From bd4fc399503fd9a80b713d4dd6e60c5ae6ba4391 Mon Sep 17 00:00:00 2001 From: Ferran Rodenas Date: Thu, 12 Jan 2017 00:51:06 +0100 Subject: [PATCH] Allow specifying --set multiple times --- cmd/helm/install.go | 18 ++++++++++++++---- cmd/helm/install_test.go | 8 ++++++++ cmd/helm/upgrade.go | 19 ++++++++++++++----- docs/helm/helm_install.md | 3 +-- docs/helm/helm_upgrade.md | 3 +-- 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index be9b61b75..f2fc67fe7 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -61,6 +61,13 @@ contained a key called 'Test', the value set in override.yaml would take precede $ helm install -f myvalues.yaml -f override.yaml ./redis +You can specify the '--set' flag multiple times. The priority will be given to the +last (right-most) set specified. For example, if both 'bar' and 'newbar' values are +set for a key called 'foo', the 'newbar' value would take precedence: + + $ helm install --set foo=bar --set foo=newbar ./redis + + To check the generated manifests of a release without installing the chart, the '--debug' and '--dry-run' flags can be combined. This will still require a round-trip to the Tiller server. @@ -101,7 +108,7 @@ type installCmd struct { keyring string out io.Writer client helm.Interface - values string + values []string nameTemplate string version string timeout int64 @@ -156,7 +163,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command { f.BoolVar(&inst.dryRun, "dry-run", false, "simulate an install") f.BoolVar(&inst.disableHooks, "no-hooks", false, "prevent hooks from running during install") f.BoolVar(&inst.replace, "replace", false, "re-use the given name, even if that name is already used. This is unsafe in production") - f.StringVar(&inst.values, "set", "", "set values on the command line. Separate values with commas: key1=val1,key2=val2") + f.StringArrayVar(&inst.values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)") f.StringVar(&inst.nameTemplate, "name-template", "", "specify template used to name the release") f.BoolVar(&inst.verify, "verify", false, "verify the package before installing it") f.StringVar(&inst.keyring, "keyring", defaultKeyring(), "location of public keys used for verification") @@ -273,8 +280,11 @@ func (i *installCmd) vals() ([]byte, error) { base = mergeValues(base, currentMap) } - if err := strvals.ParseInto(i.values, base); err != nil { - return []byte{}, fmt.Errorf("failed parsing --set data: %s", err) + // User specified a value via --set + for _, value := range i.values { + if err := strvals.ParseInto(value, base); err != nil { + return []byte{}, fmt.Errorf("failed parsing --set data: %s", err) + } } return yaml.Marshal(base) diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index 560ca531b..e8708789d 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -52,6 +52,14 @@ func TestInstall(t *testing.T) { resp: releaseMock(&releaseOptions{name: "virgil"}), expected: "virgil", }, + // Install, values from cli via multiple --set + { + name: "install with multiple values", + args: []string{"testdata/testcharts/alpine"}, + flags: strings.Split("--set foo=bar", "--set bar=foo"), + resp: releaseMock(&releaseOptions{name: "virgil"}), + expected: "virgil", + }, // Install, values from yaml { name: "install with values", diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 6d9ac1faa..1aef1e27c 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -45,7 +45,13 @@ You can specify the '--values'/'-f' flag multiple times. The priority will be gi last (right-most) file specified. For example, if both myvalues.yaml and override.yaml contained a key called 'Test', the value set in override.yaml would take precedence: - $ helm install -f myvalues.yaml -f override.yaml ./redis + $ helm upgrade -f myvalues.yaml -f override.yaml redis ./redis + +You can specify the '--set' flag multiple times. The priority will be given to the +last (right-most) set specified. For example, if both 'bar' and 'newbar' values are +set for a key called 'foo', the 'newbar' value would take precedence: + + $ helm upgrade --set foo=bar --set foo=newbar redis ./redis ` type upgradeCmd struct { @@ -57,7 +63,7 @@ type upgradeCmd struct { recreate bool disableHooks bool valueFiles valueFiles - values string + values []string verify bool keyring string install bool @@ -95,7 +101,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command { f.VarP(&upgrade.valueFiles, "values", "f", "specify values in a YAML file (can specify multiple)") f.BoolVar(&upgrade.dryRun, "dry-run", false, "simulate an upgrade") f.BoolVar(&upgrade.recreate, "recreate-pods", false, "performs pods restart for the resource if applicable") - f.StringVar(&upgrade.values, "set", "", "set values on the command line. Separate values with commas: key1=val1,key2=val2") + f.StringArrayVar(&upgrade.values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)") f.BoolVar(&upgrade.disableHooks, "disable-hooks", false, "disable pre/post upgrade hooks. DEPRECATED. Use no-hooks") f.BoolVar(&upgrade.disableHooks, "no-hooks", false, "disable pre/post upgrade hooks") f.BoolVar(&upgrade.verify, "verify", false, "verify the provenance of the chart before upgrading") @@ -195,8 +201,11 @@ func (u *upgradeCmd) vals() ([]byte, error) { base = mergeValues(base, currentMap) } - if err := strvals.ParseInto(u.values, base); err != nil { - return []byte{}, fmt.Errorf("failed parsing --set data: %s", err) + // User specified a value via --set + for _, value := range u.values { + if err := strvals.ParseInto(value, base); err != nil { + return []byte{}, fmt.Errorf("failed parsing --set data: %s", err) + } } return yaml.Marshal(base) diff --git a/docs/helm/helm_install.md b/docs/helm/helm_install.md index 3b8e56ed2..5d66807ea 100644 --- a/docs/helm/helm_install.md +++ b/docs/helm/helm_install.md @@ -62,8 +62,7 @@ helm install [CHART] --namespace string namespace to install the release into --no-hooks prevent hooks from running during install --replace re-use the given name, even if that name is already used. This is unsafe in production - --set value set values on the command line. Separate values with commas: key1=val1,key2=val2 (default null -) + --set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2) -f, --values string specify values in a YAML file --verify verify the package before installing it --version string specify the exact chart version to install. If this is not specified, the latest version is installed diff --git a/docs/helm/helm_upgrade.md b/docs/helm/helm_upgrade.md index 174855724..ba5f61051 100644 --- a/docs/helm/helm_upgrade.md +++ b/docs/helm/helm_upgrade.md @@ -29,8 +29,7 @@ helm upgrade [RELEASE] [CHART] -i, --install if a release by this name doesn't already exist, run an install --keyring string path to the keyring that contains public singing keys (default "/Users/mattbutcher/.gnupg/pubring.gpg") --namespace string namespace to install the release into (only used if --install is set) (default "default") - --set value set values on the command line. Separate values with commas: key1=val1,key2=val2 (default null -) + --set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2) -f, --values string path to a values YAML file --verify verify the provenance of the chart before upgrading --version string specify the exact chart version to use. If this is not specified, the latest version is used