Skip to content

Commit

Permalink
Introduce helm-extra-set-args
Browse files Browse the repository at this point in the history
Signed-off-by: ilmax <[email protected]>
  • Loading branch information
Massimiliano Donini committed Mar 4, 2022
1 parent 0a093e4 commit 431c57f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 15 deletions.
9 changes: 8 additions & 1 deletion ct/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion ct/cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion ct/cmd/lintAndInstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion ct/cmd/listChanged.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion doc/ct_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion doc/ct_lint-and-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
16 changes: 9 additions & 7 deletions pkg/tool/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 431c57f

Please sign in to comment.