Skip to content

Commit

Permalink
[deploy/chart] add validation flag
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Nov 27, 2018
1 parent 97438f2 commit 0dfe2c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/orca/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type chartCmd struct {
repo string
inject bool
timeout int
validate bool

out io.Writer
}
Expand Down Expand Up @@ -69,6 +70,7 @@ func NewDeployChartCmd(out io.Writer) *cobra.Command {
IsIsolated: true,
Inject: c.inject,
Timeout: c.timeout,
Validate: c.validate,
}); err != nil {
log.Fatal(err)
}
Expand All @@ -89,6 +91,7 @@ func NewDeployChartCmd(out io.Writer) *cobra.Command {
f.StringVar(&c.helmTLSStore, "helm-tls-store", os.Getenv("HELM_TLS_STORE"), "path to TLS certs and keys. Overrides $HELM_TLS_STORE")
f.BoolVar(&c.inject, "inject", utils.GetBoolEnvVar("ORCA_INJECT", false), "enable injection during helm upgrade. Overrides $ORCA_INJECT (requires helm inject plugin: https://github.com/maorfr/helm-inject)")
f.IntVar(&c.timeout, "timeout", utils.GetIntEnvVar("ORCA_TIMEOUT", 300), "time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks). Overrides $ORCA_TIMEOUT")
f.BoolVar(&c.validate, "validate", utils.GetBoolEnvVar("ORCA_VALIDATE", false), "perform environment validation after deployment. Overrides $ORCA_VALIDATE")

return cmd
}
Expand Down
16 changes: 15 additions & 1 deletion pkg/utils/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,13 @@ type DeployChartFromRepositoryOptions struct {
IsIsolated bool
Inject bool
Timeout int
Validate bool
}

// DeployChartFromRepository deploys a Helm chart from a chart repository
func DeployChartFromRepository(o DeployChartFromRepositoryOptions) error {
tempDir := MkRandomDir()
defer os.RemoveAll(tempDir)

if o.ReleaseName == "" {
o.ReleaseName = o.Name
Expand Down Expand Up @@ -258,7 +260,19 @@ func DeployChartFromRepository(o DeployChartFromRepositoryOptions) error {
return err
}

os.RemoveAll(tempDir)
if !o.Validate {
return nil
}
envValid, err := IsEnvValidWithLoopBackOff(o.Namespace, o.KubeContext)
if err != nil {
return err
}
if !envValid {
return fmt.Errorf("environment \"%s\" validation failed", o.Namespace)
}
// If we have made it so far, the environment is validated
log.Printf("environment \"%s\" validated!", o.Namespace)

return nil
}

Expand Down

0 comments on commit 0dfe2c6

Please sign in to comment.