diff --git a/ct/cmd/install.go b/ct/cmd/install.go index 4afeb8186..b514d9978 100644 --- a/ct/cmd/install.go +++ b/ct/cmd/install.go @@ -80,6 +80,9 @@ func addInstallFlags(flags *flag.FlagSet) { flags.String("helm-extra-set-args", "", heredoc.Doc(` Additional arguments for Helm. Must be passed as a single quoted string (e.g. "--set=name=value"`)) + flags.String("helm-uninstall-extra-args", "", heredoc.Doc(` + Additional arguments for Helm uninstall. Must be passed as a single quoted string + (e.g. "--no-hooks"`)) flags.Bool("skip-clean-up", false, heredoc.Doc(` Skip resources clean-up. Used if need to continue other flows or keep it around.`)) } diff --git a/doc/ct_install.md b/doc/ct_install.md index 27b5697a7..55f6340ac 100644 --- a/doc/ct_install.md +++ b/doc/ct_install.md @@ -54,7 +54,9 @@ ct install [flags] --helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string (e.g. '--timeout 500s') --helm-extra-set-args string Additional arguments for Helm. Must be passed as a single quoted string - (e.g. "--set=name=value" + (e.g. "--set=name=value") + --helm-uninstall-extra-args string Additional arguments for Helm uninstall. Must be passed as a single quoted string + (e.g. "--no-hooks --cascade background") --helm-lint-extra-args string Additional arguments for Helm lint subcommand. Must be passed as a single quoted string (e.g. '--quiet') --helm-repo-extra-args strings Additional arguments for the 'helm repo add' command to be @@ -84,5 +86,4 @@ ct install [flags] ### SEE ALSO -* [ct](ct.md) - The Helm chart testing tool - +* [ct](ct.md) - The Helm chart testing tool diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index d409e0a24..9f32ffc54 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -271,10 +271,11 @@ func NewTesting(config config.Configuration) (Testing, error) { helmExtraArgs := strings.Fields(config.HelmExtraArgs) helmExtraSetArgs := strings.Fields(config.HelmExtraSetArgs) helmLintExtraArgs := strings.Fields(config.HelmLintExtraArgs) + helmUninstallExtraArgs := strings.Fields(config.HelmUninstallExtraArgs) testing := Testing{ config: config, - helm: tool.NewHelm(procExec, helmExtraArgs, helmLintExtraArgs, helmExtraSetArgs), + helm: tool.NewHelm(procExec, helmExtraArgs, helmLintExtraArgs, helmExtraSetArgs, helmUninstallExtraArgs), git: tool.NewGit(procExec), kubectl: tool.NewKubectl(procExec, config.KubectlTimeout), linter: tool.NewLinter(procExec), diff --git a/pkg/chart/integration_test.go b/pkg/chart/integration_test.go index c6b5915a1..404bba464 100644 --- a/pkg/chart/integration_test.go +++ b/pkg/chart/integration_test.go @@ -35,6 +35,7 @@ func newTestingHelmIntegration(cfg config.Configuration, extraSetArgs string) Te procExec := exec.NewProcessExecutor(true) extraArgs := strings.Fields(cfg.HelmExtraArgs) extraLintArgs := strings.Fields(cfg.HelmLintExtraArgs) + uninstallExtraArgs := strings.Fields(cfg.HelmUninstallExtraArgs) return Testing{ config: cfg, @@ -43,7 +44,7 @@ func newTestingHelmIntegration(cfg config.Configuration, extraSetArgs string) Te utils: util.Utils{}, accountValidator: fakeAccountValidator{}, linter: fakeMockLinter, - helm: tool.NewHelm(procExec, extraArgs, extraLintArgs, strings.Fields(extraSetArgs)), + helm: tool.NewHelm(procExec, extraArgs, extraLintArgs, strings.Fields(extraSetArgs), uninstallExtraArgs), kubectl: tool.NewKubectl(procExec, 30*time.Second), } } diff --git a/pkg/config/config.go b/pkg/config/config.go index 981b2762b..27afb50a0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -61,6 +61,7 @@ type Configuration struct { ChartDirs []string `mapstructure:"chart-dirs"` ExcludedCharts []string `mapstructure:"excluded-charts"` HelmExtraArgs string `mapstructure:"helm-extra-args"` + HelmUninstallExtraArgs string `mapstructure:"helm-uninstall-extra-args"` HelmExtraSetArgs string `mapstructure:"helm-extra-set-args"` HelmLintExtraArgs string `mapstructure:"helm-lint-extra-args"` HelmRepoExtraArgs []string `mapstructure:"helm-repo-extra-args"` diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index f07d912e6..f3de9cb7a 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -54,6 +54,7 @@ func loadAndAssertConfigFromFile(t *testing.T, configFile string) { require.Equal(t, []string{"common"}, cfg.ExcludedCharts) require.Equal(t, "--timeout 300s", cfg.HelmExtraArgs) require.Equal(t, "--quiet", cfg.HelmLintExtraArgs) + require.Equal(t, "--no-hooks --cascade background", cfg.HelmUninstallExtraArgs) require.Equal(t, true, cfg.Upgrade) require.Equal(t, true, cfg.SkipMissingValues) require.Equal(t, "default", cfg.Namespace) diff --git a/pkg/config/test_config.json b/pkg/config/test_config.json index 73cd45742..22f166e59 100644 --- a/pkg/config/test_config.json +++ b/pkg/config/test_config.json @@ -26,6 +26,7 @@ ], "helm-extra-args": "--timeout 300s", "helm-lint-extra-args": "--quiet", + "helm-uninstall-extra-args": "--no-hooks --cascade background", "upgrade": true, "skip-missing-values": true, "namespace": "default", diff --git a/pkg/config/test_config.yaml b/pkg/config/test_config.yaml index 0d1c7c02b..6a8234439 100644 --- a/pkg/config/test_config.yaml +++ b/pkg/config/test_config.yaml @@ -21,6 +21,7 @@ excluded-charts: - common helm-extra-args: --timeout 300s helm-lint-extra-args: --quiet +helm-uninstall-extra-args: --no-hooks --cascade background upgrade: true skip-missing-values: true namespace: default diff --git a/pkg/tool/helm.go b/pkg/tool/helm.go index 339a70e5e..0deb988e9 100644 --- a/pkg/tool/helm.go +++ b/pkg/tool/helm.go @@ -22,18 +22,20 @@ import ( ) type Helm struct { - exec exec.ProcessExecutor - extraArgs []string - lintExtraArgs []string - extraSetArgs []string + exec exec.ProcessExecutor + extraArgs []string + lintExtraArgs []string + extraSetArgs []string + uninstallExtraArgs []string } -func NewHelm(exec exec.ProcessExecutor, extraArgs, lintExtraArgs, extraSetArgs []string) Helm { +func NewHelm(exec exec.ProcessExecutor, extraArgs, lintExtraArgs, extraSetArgs, uninstallExtraArgs []string) Helm { return Helm{ - exec: exec, - extraArgs: extraArgs, - lintExtraArgs: lintExtraArgs, - extraSetArgs: extraSetArgs, + exec: exec, + extraArgs: extraArgs, + lintExtraArgs: lintExtraArgs, + extraSetArgs: extraSetArgs, + uninstallExtraArgs: uninstallExtraArgs, } } @@ -91,7 +93,7 @@ func (h Helm) Test(namespace string, release string) error { func (h Helm) DeleteRelease(namespace string, release string) { fmt.Printf("Deleting release %q...\n", release) - if err := h.exec.RunProcess("helm", "uninstall", release, "--namespace", namespace, "--wait", h.extraArgs); err != nil { + if err := h.exec.RunProcess("helm", "uninstall", release, "--namespace", namespace, "--wait", h.extraArgs, h.uninstallExtraArgs); err != nil { fmt.Println("Error deleting Helm release:", err) } }