Commit 672d014c authored by Matt Butcher's avatar Matt Butcher Committed by GitHub

Merge pull request #1817 from frodenas/multiple-set-flag

feat(helm): allow specifying --set multiple times
parents fd950629 bd4fc399
...@@ -61,6 +61,13 @@ contained a key called 'Test', the value set in override.yaml would take precede ...@@ -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 $ 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, 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 the '--debug' and '--dry-run' flags can be combined. This will still require a
round-trip to the Tiller server. round-trip to the Tiller server.
...@@ -101,7 +108,7 @@ type installCmd struct { ...@@ -101,7 +108,7 @@ type installCmd struct {
keyring string keyring string
out io.Writer out io.Writer
client helm.Interface client helm.Interface
values string values []string
nameTemplate string nameTemplate string
version string version string
timeout int64 timeout int64
...@@ -156,7 +163,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command { ...@@ -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.dryRun, "dry-run", false, "simulate an install")
f.BoolVar(&inst.disableHooks, "no-hooks", false, "prevent hooks from running during 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.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.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.BoolVar(&inst.verify, "verify", false, "verify the package before installing it")
f.StringVar(&inst.keyring, "keyring", defaultKeyring(), "location of public keys used for verification") f.StringVar(&inst.keyring, "keyring", defaultKeyring(), "location of public keys used for verification")
...@@ -273,9 +280,12 @@ func (i *installCmd) vals() ([]byte, error) { ...@@ -273,9 +280,12 @@ func (i *installCmd) vals() ([]byte, error) {
base = mergeValues(base, currentMap) base = mergeValues(base, currentMap)
} }
if err := strvals.ParseInto(i.values, base); err != nil { // 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 []byte{}, fmt.Errorf("failed parsing --set data: %s", err)
} }
}
return yaml.Marshal(base) return yaml.Marshal(base)
} }
......
...@@ -52,6 +52,14 @@ func TestInstall(t *testing.T) { ...@@ -52,6 +52,14 @@ func TestInstall(t *testing.T) {
resp: releaseMock(&releaseOptions{name: "virgil"}), resp: releaseMock(&releaseOptions{name: "virgil"}),
expected: "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 // Install, values from yaml
{ {
name: "install with values", name: "install with values",
......
...@@ -45,7 +45,13 @@ You can specify the '--values'/'-f' flag multiple times. The priority will be gi ...@@ -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 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: 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 { type upgradeCmd struct {
...@@ -57,7 +63,7 @@ type upgradeCmd struct { ...@@ -57,7 +63,7 @@ type upgradeCmd struct {
recreate bool recreate bool
disableHooks bool disableHooks bool
valueFiles valueFiles valueFiles valueFiles
values string values []string
verify bool verify bool
keyring string keyring string
install bool install bool
...@@ -95,7 +101,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command { ...@@ -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.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.dryRun, "dry-run", false, "simulate an upgrade")
f.BoolVar(&upgrade.recreate, "recreate-pods", false, "performs pods restart for the resource if applicable") 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, "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.disableHooks, "no-hooks", false, "disable pre/post upgrade hooks")
f.BoolVar(&upgrade.verify, "verify", false, "verify the provenance of the chart before upgrading") f.BoolVar(&upgrade.verify, "verify", false, "verify the provenance of the chart before upgrading")
...@@ -195,9 +201,12 @@ func (u *upgradeCmd) vals() ([]byte, error) { ...@@ -195,9 +201,12 @@ func (u *upgradeCmd) vals() ([]byte, error) {
base = mergeValues(base, currentMap) base = mergeValues(base, currentMap)
} }
if err := strvals.ParseInto(u.values, base); err != nil { // 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 []byte{}, fmt.Errorf("failed parsing --set data: %s", err)
} }
}
return yaml.Marshal(base) return yaml.Marshal(base)
} }
...@@ -62,8 +62,7 @@ helm install [CHART] ...@@ -62,8 +62,7 @@ helm install [CHART]
--namespace string namespace to install the release into --namespace string namespace to install the release into
--no-hooks prevent hooks from running during install --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 --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 -f, --values string specify values in a YAML file
--verify verify the package before installing it --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 --version string specify the exact chart version to install. If this is not specified, the latest version is installed
......
...@@ -29,8 +29,7 @@ helm upgrade [RELEASE] [CHART] ...@@ -29,8 +29,7 @@ helm upgrade [RELEASE] [CHART]
-i, --install if a release by this name doesn't already exist, run an install -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") --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") --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 -f, --values string path to a values YAML file
--verify verify the provenance of the chart before upgrading --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 --version string specify the exact chart version to use. If this is not specified, the latest version is used
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment