Skip to content

Commit 2a418b6

Browse files
committed
feat: add --helm-uninstall-extra-args flag
Signed-off-by: Patryk Małek <malekpatryk+github@gmail.com>
1 parent b4897a4 commit 2a418b6

File tree

9 files changed

+27
-15
lines changed

9 files changed

+27
-15
lines changed

ct/cmd/install.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ func addInstallFlags(flags *flag.FlagSet) {
8080
flags.String("helm-extra-set-args", "", heredoc.Doc(`
8181
Additional arguments for Helm. Must be passed as a single quoted string
8282
(e.g. "--set=name=value"`))
83+
flags.String("helm-uninstall-extra-args", "", heredoc.Doc(`
84+
Additional arguments for Helm uninstall. Must be passed as a single quoted string
85+
(e.g. "--no-hooks"`))
8386
flags.Bool("skip-clean-up", false, heredoc.Doc(`
8487
Skip resources clean-up. Used if need to continue other flows or keep it around.`))
8588
}

doc/ct_install.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ ct install [flags]
5454
--helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string
5555
(e.g. '--timeout 500s')
5656
--helm-extra-set-args string Additional arguments for Helm. Must be passed as a single quoted string
57-
(e.g. "--set=name=value"
57+
(e.g. "--set=name=value")
58+
--helm-uninstall-extra-args string Additional arguments for Helm uninstall. Must be passed as a single quoted string
59+
(e.g. "--no-hooks --cascade background")
5860
--helm-lint-extra-args string Additional arguments for Helm lint subcommand. Must be passed as a single quoted string
5961
(e.g. '--quiet')
6062
--helm-repo-extra-args strings Additional arguments for the 'helm repo add' command to be
@@ -84,5 +86,4 @@ ct install [flags]
8486

8587
### SEE ALSO
8688

87-
* [ct](ct.md) - The Helm chart testing tool
88-
89+
* [ct](ct.md) - The Helm chart testing tool

pkg/chart/chart.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,11 @@ func NewTesting(config config.Configuration) (Testing, error) {
271271
helmExtraArgs := strings.Fields(config.HelmExtraArgs)
272272
helmExtraSetArgs := strings.Fields(config.HelmExtraSetArgs)
273273
helmLintExtraArgs := strings.Fields(config.HelmLintExtraArgs)
274+
helmUninstallExtraArgs := strings.Fields(config.HelmUninstallExtraArgs)
274275

275276
testing := Testing{
276277
config: config,
277-
helm: tool.NewHelm(procExec, helmExtraArgs, helmLintExtraArgs, helmExtraSetArgs),
278+
helm: tool.NewHelm(procExec, helmExtraArgs, helmLintExtraArgs, helmExtraSetArgs, helmUninstallExtraArgs),
278279
git: tool.NewGit(procExec),
279280
kubectl: tool.NewKubectl(procExec, config.KubectlTimeout),
280281
linter: tool.NewLinter(procExec),

pkg/chart/integration_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func newTestingHelmIntegration(cfg config.Configuration, extraSetArgs string) Te
3535
procExec := exec.NewProcessExecutor(true)
3636
extraArgs := strings.Fields(cfg.HelmExtraArgs)
3737
extraLintArgs := strings.Fields(cfg.HelmLintExtraArgs)
38+
uninstallExtraArgs := strings.Fields(cfg.HelmUninstallExtraArgs)
3839

3940
return Testing{
4041
config: cfg,
@@ -43,7 +44,7 @@ func newTestingHelmIntegration(cfg config.Configuration, extraSetArgs string) Te
4344
utils: util.Utils{},
4445
accountValidator: fakeAccountValidator{},
4546
linter: fakeMockLinter,
46-
helm: tool.NewHelm(procExec, extraArgs, extraLintArgs, strings.Fields(extraSetArgs)),
47+
helm: tool.NewHelm(procExec, extraArgs, extraLintArgs, strings.Fields(extraSetArgs), uninstallExtraArgs),
4748
kubectl: tool.NewKubectl(procExec, 30*time.Second),
4849
}
4950
}

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type Configuration struct {
6161
ChartDirs []string `mapstructure:"chart-dirs"`
6262
ExcludedCharts []string `mapstructure:"excluded-charts"`
6363
HelmExtraArgs string `mapstructure:"helm-extra-args"`
64+
HelmUninstallExtraArgs string `mapstructure:"helm-uninstall-extra-args"`
6465
HelmExtraSetArgs string `mapstructure:"helm-extra-set-args"`
6566
HelmLintExtraArgs string `mapstructure:"helm-lint-extra-args"`
6667
HelmRepoExtraArgs []string `mapstructure:"helm-repo-extra-args"`

pkg/config/config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func loadAndAssertConfigFromFile(t *testing.T, configFile string) {
5454
require.Equal(t, []string{"common"}, cfg.ExcludedCharts)
5555
require.Equal(t, "--timeout 300s", cfg.HelmExtraArgs)
5656
require.Equal(t, "--quiet", cfg.HelmLintExtraArgs)
57+
require.Equal(t, "--no-hooks --cascade background", cfg.HelmUninstallExtraArgs)
5758
require.Equal(t, true, cfg.Upgrade)
5859
require.Equal(t, true, cfg.SkipMissingValues)
5960
require.Equal(t, "default", cfg.Namespace)

pkg/config/test_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
],
2727
"helm-extra-args": "--timeout 300s",
2828
"helm-lint-extra-args": "--quiet",
29+
"helm-uninstall-extra-args": "--no-hooks --cascade background",
2930
"upgrade": true,
3031
"skip-missing-values": true,
3132
"namespace": "default",

pkg/config/test_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ excluded-charts:
2121
- common
2222
helm-extra-args: --timeout 300s
2323
helm-lint-extra-args: --quiet
24+
helm-uninstall-extra-args: --no-hooks --cascade background
2425
upgrade: true
2526
skip-missing-values: true
2627
namespace: default

pkg/tool/helm.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,20 @@ import (
2222
)
2323

2424
type Helm struct {
25-
exec exec.ProcessExecutor
26-
extraArgs []string
27-
lintExtraArgs []string
28-
extraSetArgs []string
25+
exec exec.ProcessExecutor
26+
extraArgs []string
27+
lintExtraArgs []string
28+
extraSetArgs []string
29+
uninstallExtraArgs []string
2930
}
3031

31-
func NewHelm(exec exec.ProcessExecutor, extraArgs, lintExtraArgs, extraSetArgs []string) Helm {
32+
func NewHelm(exec exec.ProcessExecutor, extraArgs, lintExtraArgs, extraSetArgs, uninstallExtraArgs []string) Helm {
3233
return Helm{
33-
exec: exec,
34-
extraArgs: extraArgs,
35-
lintExtraArgs: lintExtraArgs,
36-
extraSetArgs: extraSetArgs,
34+
exec: exec,
35+
extraArgs: extraArgs,
36+
lintExtraArgs: lintExtraArgs,
37+
extraSetArgs: extraSetArgs,
38+
uninstallExtraArgs: uninstallExtraArgs,
3739
}
3840
}
3941

@@ -91,7 +93,7 @@ func (h Helm) Test(namespace string, release string) error {
9193

9294
func (h Helm) DeleteRelease(namespace string, release string) {
9395
fmt.Printf("Deleting release %q...\n", release)
94-
if err := h.exec.RunProcess("helm", "uninstall", release, "--namespace", namespace, "--wait", h.extraArgs); err != nil {
96+
if err := h.exec.RunProcess("helm", "uninstall", release, "--namespace", namespace, "--wait", h.extraArgs, h.uninstallExtraArgs); err != nil {
9597
fmt.Println("Error deleting Helm release:", err)
9698
}
9799
}

0 commit comments

Comments
 (0)