mirror of
https://github.com/helm/chart-testing.git
synced 2026-02-05 09:45:14 +01:00
Introduce helm-extra-set-args command line parameter (#402)
* Introduce helm-extra-set-args Signed-off-by: ilmax <massimiliano.donini@gmail.com> Signed-off-by: Massimiliano Donini <massimiliano.donini@lobsterink.com> * Fix and add integration test - Fixed error when no values are passed in - Added integration test Signed-off-by: Massimiliano Donini <massimiliano.donini@lobsterink.com> * Generate docs Signed-off-by: Massimiliano Donini <massimiliano.donini@lobsterink.com>
This commit is contained in:
committed by
GitHub
parent
e14c2b21b6
commit
aabb51e7dd
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user