Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce helm-extra-set-args command line parameter #402

Merged
merged 3 commits into from
Mar 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ct/cmd/install.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 2 additions & 1 deletion ct/cmd/lint.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 5 additions & 1 deletion ct/cmd/lintAndInstall.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 2 additions & 1 deletion ct/cmd/listChanged.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion doc/ct.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion doc/ct_install.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion doc/ct_lint-and-install.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion doc/ct_lint.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion doc/ct_list-changed.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 1 addition & 5 deletions doc/ct_version.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions pkg/chart/chart.go
Original file line number Diff line number Diff line change
@@ -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),
20 changes: 16 additions & 4 deletions pkg/chart/integration_test.go
Original file line number Diff line number Diff line change
@@ -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{
16 changes: 9 additions & 7 deletions pkg/tool/helm.go
Original file line number Diff line number Diff line change
@@ -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
}