diff --git a/ct/cmd/install.go b/ct/cmd/install.go index be16d8d6..12e76b55 100644 --- a/ct/cmd/install.go +++ b/ct/cmd/install.go @@ -77,6 +77,9 @@ func addInstallFlags(flags *flag.FlagSet) { flags.String("release-label", "app.kubernetes.io/instance", heredoc.Doc(` The label to be used as a selector when inspecting resources created by charts. This is only used if namespace is specified`)) + 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"`)) } func install(cmd *cobra.Command, args []string) error { @@ -91,7 +94,11 @@ func install(cmd *cobra.Command, args []string) error { return fmt.Errorf("Error loading configuration: %s", err) } - testing, err := chart.NewTesting(*configuration) + extraSetArgs, err := cmd.Flags().GetString("helm-extra-set-args") + if err != nil { + return err + } + testing, err := chart.NewTesting(*configuration, extraSetArgs) if err != nil { fmt.Println(err) } diff --git a/ct/cmd/lint.go b/ct/cmd/lint.go index 5783567f..2656a4ab 100644 --- a/ct/cmd/lint.go +++ b/ct/cmd/lint.go @@ -88,7 +88,8 @@ func lint(cmd *cobra.Command, args []string) error { return fmt.Errorf("Error loading configuration: %s", err) } - testing, err := chart.NewTesting(*configuration) + emptyExtraSetArgs := "" + testing, err := chart.NewTesting(*configuration, emptyExtraSetArgs) if err != nil { return err } diff --git a/ct/cmd/lintAndInstall.go b/ct/cmd/lintAndInstall.go index 10c48cab..0ec6238c 100644 --- a/ct/cmd/lintAndInstall.go +++ b/ct/cmd/lintAndInstall.go @@ -51,7 +51,11 @@ func lintAndInstall(cmd *cobra.Command, args []string) error { return fmt.Errorf("Error loading configuration: %s", err) } - testing, err := chart.NewTesting(*configuration) + extraSetArgs, err := cmd.Flags().GetString("helm-extra-set-args") + if err != nil { + return err + } + testing, err := chart.NewTesting(*configuration, extraSetArgs) if err != nil { return err } diff --git a/ct/cmd/listChanged.go b/ct/cmd/listChanged.go index 134203a3..4c286e37 100644 --- a/ct/cmd/listChanged.go +++ b/ct/cmd/listChanged.go @@ -50,7 +50,8 @@ func listChanged(cmd *cobra.Command, args []string) error { return fmt.Errorf("Error loading configuration: %s", err) } - testing, err := chart.NewTesting(*configuration) + emptyExtraSetArgs := "" + testing, err := chart.NewTesting(*configuration, emptyExtraSetArgs) if err != nil { return err } diff --git a/doc/ct.md b/doc/ct.md index 9fbd0938..b510691c 100644 --- a/doc/ct.md +++ b/doc/ct.md @@ -26,4 +26,4 @@ in given chart directories. * [ct list-changed](ct_list-changed.md) - List changed charts * [ct version](ct_version.md) - Print version information -###### Auto generated by spf13/cobra on 21-Apr-2020 +###### Auto generated by spf13/cobra on 16-Mar-2022 diff --git a/doc/ct_install.md b/doc/ct_install.md index 271a9e8e..c1fc741b 100644 --- a/doc/ct_install.md +++ b/doc/ct_install.md @@ -50,6 +50,8 @@ ct install [flags] or separate values with commas --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" --helm-repo-extra-args strings Additional arguments for the 'helm repo add' command to be specified on a per-repo basis with an equals sign as delimiter (e.g. 'myrepo=--username test --password secret'). May be specified @@ -75,4 +77,4 @@ ct install [flags] * [ct](ct.md) - The Helm chart testing tool -###### Auto generated by spf13/cobra on 28-Oct-2020 +###### Auto generated by spf13/cobra on 16-Mar-2022 diff --git a/doc/ct_lint-and-install.md b/doc/ct_lint-and-install.md index 2216a9fb..041bbef1 100644 --- a/doc/ct_lint-and-install.md +++ b/doc/ct_lint-and-install.md @@ -42,6 +42,8 @@ ct lint-and-install [flags] or separate values with commas --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" --helm-repo-extra-args strings Additional arguments for the 'helm repo add' command to be specified on a per-repo basis with an equals sign as delimiter (e.g. 'myrepo=--username test --password secret'). May be specified @@ -74,4 +76,4 @@ ct lint-and-install [flags] * [ct](ct.md) - The Helm chart testing tool -###### Auto generated by spf13/cobra on 28-Oct-2020 +###### Auto generated by spf13/cobra on 16-Mar-2022 diff --git a/doc/ct_lint.md b/doc/ct_lint.md index 1c1b11be..9c48ac4d 100644 --- a/doc/ct_lint.md +++ b/doc/ct_lint.md @@ -73,4 +73,4 @@ ct lint [flags] * [ct](ct.md) - The Helm chart testing tool -###### Auto generated by spf13/cobra on 28-Oct-2020 +###### Auto generated by spf13/cobra on 16-Mar-2022 diff --git a/doc/ct_list-changed.md b/doc/ct_list-changed.md index b46ec16d..e3f89e72 100644 --- a/doc/ct_list-changed.md +++ b/doc/ct_list-changed.md @@ -32,4 +32,4 @@ ct list-changed [flags] * [ct](ct.md) - The Helm chart testing tool -###### Auto generated by spf13/cobra on 28-Oct-2020 +###### Auto generated by spf13/cobra on 16-Mar-2022 diff --git a/doc/ct_version.md b/doc/ct_version.md index 12e25f1a..5090b354 100644 --- a/doc/ct_version.md +++ b/doc/ct_version.md @@ -2,10 +2,6 @@ Print version information -### Synopsis - -Print version information - ``` ct version [flags] ``` @@ -20,4 +16,4 @@ ct version [flags] * [ct](ct.md) - The Helm chart testing tool -###### Auto generated by spf13/cobra on 21-Apr-2020 +###### Auto generated by spf13/cobra on 16-Mar-2022 diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index 96b1b7da..3d92647f 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -252,13 +252,13 @@ type TestResult struct { } // NewTesting creates a new Testing struct with the given config. -func NewTesting(config config.Configuration) (Testing, error) { +func NewTesting(config config.Configuration, extraSetArgs string) (Testing, error) { procExec := exec.NewProcessExecutor(config.Debug) extraArgs := strings.Fields(config.HelmExtraArgs) testing := Testing{ config: config, - helm: tool.NewHelm(procExec, extraArgs), + helm: tool.NewHelm(procExec, extraArgs, strings.Fields(extraSetArgs)), git: tool.NewGit(procExec), kubectl: tool.NewKubectl(procExec), linter: tool.NewLinter(procExec), diff --git a/pkg/chart/integration_test.go b/pkg/chart/integration_test.go index 0132963e..c3b24221 100644 --- a/pkg/chart/integration_test.go +++ b/pkg/chart/integration_test.go @@ -29,7 +29,7 @@ import ( "github.com/stretchr/testify/assert" ) -func newTestingHelmIntegration(cfg config.Configuration) Testing { +func newTestingHelmIntegration(cfg config.Configuration, extraSetArgs string) Testing { fakeMockLinter := new(fakeLinter) procExec := exec.NewProcessExecutor(true) extraArgs := strings.Fields(cfg.HelmExtraArgs) @@ -40,7 +40,7 @@ func newTestingHelmIntegration(cfg config.Configuration) Testing { chartUtils: util.ChartUtils{}, accountValidator: fakeAccountValidator{}, linter: fakeMockLinter, - helm: tool.NewHelm(procExec, extraArgs), + helm: tool.NewHelm(procExec, extraArgs, strings.Fields(extraSetArgs)), kubectl: tool.NewKubectl(procExec), } } @@ -51,6 +51,7 @@ func TestInstallChart(t *testing.T) { cfg config.Configuration chartDir string output TestResult + extraSet string } cases := []testCase{ @@ -63,6 +64,7 @@ func TestInstallChart(t *testing.T) { }, "test_charts/must-pass-upgrade-install", TestResult{mustNewChart("test_charts/must-pass-upgrade-install"), nil}, + "", }, { "install only in random namespace", @@ -71,12 +73,22 @@ func TestInstallChart(t *testing.T) { }, "test_charts/must-pass-upgrade-install", TestResult{mustNewChart("test_charts/must-pass-upgrade-install"), nil}, + "", + }, + { + "install with override set", + config.Configuration{ + Debug: true, + }, + "test_charts/must-pass-upgrade-install", + TestResult{mustNewChart("test_charts/must-pass-upgrade-install"), nil}, + "--set=image.tag=latest", }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { - ct := newTestingHelmIntegration(tc.cfg) + ct := newTestingHelmIntegration(tc.cfg, tc.extraSet) namespace := tc.cfg.Namespace if namespace != "" { ct.kubectl.CreateNamespace(namespace) @@ -107,7 +119,7 @@ func TestUpgradeChart(t *testing.T) { Debug: true, Upgrade: true, } - ct := newTestingHelmIntegration(cfg) + ct := newTestingHelmIntegration(cfg, "") processError := fmt.Errorf("Error waiting for process: exit status 1") cases := []testCase{ diff --git a/pkg/tool/helm.go b/pkg/tool/helm.go index ffea48ab..bef2454f 100644 --- a/pkg/tool/helm.go +++ b/pkg/tool/helm.go @@ -21,14 +21,16 @@ import ( ) type Helm struct { - exec exec.ProcessExecutor - extraArgs []string + exec exec.ProcessExecutor + extraArgs []string + extraSetArgs []string } -func NewHelm(exec exec.ProcessExecutor, extraArgs []string) Helm { +func NewHelm(exec exec.ProcessExecutor, extraArgs []string, extraSetArgs []string) Helm { return Helm{ - exec: exec, - extraArgs: extraArgs, + exec: exec, + extraArgs: extraArgs, + extraSetArgs: extraSetArgs, } } @@ -56,7 +58,7 @@ func (h Helm) InstallWithValues(chart string, valuesFile string, namespace strin } if err := h.exec.RunProcess("helm", "install", release, chart, "--namespace", namespace, - "--wait", values, h.extraArgs); err != nil { + "--wait", values, h.extraArgs, h.extraSetArgs); err != nil { return err } @@ -65,7 +67,7 @@ func (h Helm) InstallWithValues(chart string, valuesFile string, namespace strin func (h Helm) Upgrade(chart string, namespace string, release string) error { if err := h.exec.RunProcess("helm", "upgrade", release, chart, "--namespace", namespace, - "--reuse-values", "--wait", h.extraArgs); err != nil { + "--reuse-values", "--wait", h.extraArgs, h.extraSetArgs); err != nil { return err }