diff --git a/pkg/orca/chart.go b/pkg/orca/chart.go index 64892e0..255821b 100644 --- a/pkg/orca/chart.go +++ b/pkg/orca/chart.go @@ -24,6 +24,7 @@ type chartCmd struct { repo string inject bool timeout int + validate bool out io.Writer } @@ -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) } @@ -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 } diff --git a/pkg/utils/helm.go b/pkg/utils/helm.go index 6012ff3..1ef0b9e 100644 --- a/pkg/utils/helm.go +++ b/pkg/utils/helm.go @@ -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 @@ -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 }