From 431c57f2099355123351ecb05bc07ad4b3371092 Mon Sep 17 00:00:00 2001 From: Massimiliano Donini Date: Fri, 4 Mar 2022 12:54:30 +0100 Subject: [PATCH] Introduce helm-extra-set-args Signed-off-by: ilmax --- ct/cmd/install.go | 9 ++++++++- ct/cmd/lint.go | 3 ++- ct/cmd/lintAndInstall.go | 6 +++++- ct/cmd/listChanged.go | 3 ++- doc/ct_install.md | 4 +++- doc/ct_lint-and-install.md | 4 +++- pkg/chart/chart.go | 4 ++-- pkg/tool/helm.go | 16 +++++++++------- 8 files changed, 34 insertions(+), 15 deletions(-) diff --git a/ct/cmd/install.go b/ct/cmd/install.go index 23968781..10c9885f 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_install.md b/doc/ct_install.md index 55c9c019..757c2f17 100644 --- a/doc/ct_install.md +++ b/doc/ct_install.md @@ -49,7 +49,9 @@ ct install [flags] --excluded-charts strings Charts that should be skipped. May be specified multiple times or separate values with commas --helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string - (e.g. "--timeout 500" + (e.g. "--timeout 500") + --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 diff --git a/doc/ct_lint-and-install.md b/doc/ct_lint-and-install.md index 4e67e46d..653bd79c 100644 --- a/doc/ct_lint-and-install.md +++ b/doc/ct_lint-and-install.md @@ -41,7 +41,9 @@ ct lint-and-install [flags] --excluded-charts strings Charts that should be skipped. May be specified multiple times or separate values with commas --helm-extra-args string Additional arguments for Helm. Must be passed as a single quoted string - (e.g. "--timeout 500" + (e.g. "--timeout 500") + --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 diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index 96b1b7da..123d934d 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, extraSetArgs), git: tool.NewGit(procExec), kubectl: tool.NewKubectl(procExec), linter: tool.NewLinter(procExec), diff --git a/pkg/tool/helm.go b/pkg/tool/helm.go index ffea48ab..9e891760 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 }