Skip to content

Commit

Permalink
Adding --set-string flag to force string values.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arturo Contreras committed Mar 20, 2018
1 parent b6335b7 commit a615f80
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 92 deletions.
22 changes: 18 additions & 4 deletions cmd/helm/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,19 @@ The install argument must be a chart reference, a path to a packaged chart,
a path to an unpacked chart directory or a URL.
To override values in a chart, use either the '--values' flag and pass in a file
or use the '--set' flag and pass configuration from the command line.
or use the '--set' flag and pass configuration from the command line, to force
a string value use '--set-string'.
$ helm install -f myvalues.yaml ./redis
or
$ helm install --set name=prod ./redis
or
$ helm install --set-string long_int=1234567890 ./redis
You can specify the '--values'/'-f' flag multiple times. The priority will be given to the
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:
Expand Down Expand Up @@ -113,6 +118,7 @@ type installCmd struct {
out io.Writer
client helm.Interface
values []string
stringValues []string
nameTemplate string
version string
timeout int64
Expand Down Expand Up @@ -186,6 +192,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command {
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.StringArrayVar(&inst.values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
f.StringArrayVar(&inst.stringValues, "set-string", []string{}, "set STRING 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")
Expand All @@ -211,7 +218,7 @@ func (i *installCmd) run() error {
i.namespace = defaultNamespace()
}

rawVals, err := vals(i.valueFiles, i.values)
rawVals, err := vals(i.valueFiles, i.values, i.stringValues)
if err != nil {
return err
}
Expand Down Expand Up @@ -325,8 +332,8 @@ func mergeValues(dest map[string]interface{}, src map[string]interface{}) map[st
}

// vals merges values from files specified via -f/--values and
// directly via --set, marshaling them to YAML
func vals(valueFiles valueFiles, values []string) ([]byte, error) {
// directly via --set or --set-string, marshaling them to YAML
func vals(valueFiles valueFiles, values []string, stringValues []string) ([]byte, error) {
base := map[string]interface{}{}

// User specified a values files via -f/--values
Expand Down Expand Up @@ -359,6 +366,13 @@ func vals(valueFiles valueFiles, values []string) ([]byte, error) {
}
}

// User specified a value via --set-string
for _, value := range stringValues {
if err := strvals.ParseIntoString(value, base); err != nil {
return []byte{}, fmt.Errorf("failed parsing --set-string data: %s", err)
}
}

return yaml.Marshal(base)
}

Expand Down
9 changes: 9 additions & 0 deletions cmd/helm/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ or recommendation, it will emit [WARNING] messages.
type lintCmd struct {
valueFiles valueFiles
values []string
sValues []string
namespace string
strict bool
paths []string
Expand All @@ -71,6 +72,7 @@ func newLintCmd(out io.Writer) *cobra.Command {

cmd.Flags().VarP(&l.valueFiles, "values", "f", "specify values in a YAML file (can specify multiple)")
cmd.Flags().StringArrayVar(&l.values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
cmd.Flags().StringArrayVar(&l.sValues, "set-string", []string{}, "set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
cmd.Flags().StringVar(&l.namespace, "namespace", "default", "namespace to install the release into (only used if --install is set)")
cmd.Flags().BoolVar(&l.strict, "strict", false, "fail on lint warnings")

Expand Down Expand Up @@ -192,5 +194,12 @@ func (l *lintCmd) vals() ([]byte, error) {
}
}

// User specified a value via --set-string
for _, value := range l.sValues {
if err := strvals.ParseIntoString(value, base); err != nil {
return []byte{}, fmt.Errorf("failed parsing --set-string data: %s", err)
}
}

return yaml.Marshal(base)
}
4 changes: 3 additions & 1 deletion cmd/helm/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type templateCmd struct {
chartPath string
out io.Writer
values []string
stringValues []string
nameTemplate string
showNotes bool
releaseName string
Expand Down Expand Up @@ -96,6 +97,7 @@ func newTemplateCmd(out io.Writer) *cobra.Command {
f.VarP(&t.valueFiles, "values", "f", "specify values in a YAML file (can specify multiple)")
f.StringVar(&t.namespace, "namespace", "", "namespace to install the release into")
f.StringArrayVar(&t.values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
f.StringArrayVar(&t.stringValues, "set-string", []string{}, "set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
f.StringVar(&t.nameTemplate, "name-template", "", "specify template used to name the release")
f.StringVar(&t.kubeVersion, "kube-version", defaultKubeVersion, "kubernetes version used as Capabilities.KubeVersion.Major/Minor")
f.StringVar(&t.outputDir, "output-dir", "", "writes the executed templates to files in output-dir instead of stdout")
Expand Down Expand Up @@ -149,7 +151,7 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
t.namespace = defaultNamespace()
}
// get combined values and create config
rawVals, err := vals(t.valueFiles, t.values)
rawVals, err := vals(t.valueFiles, t.values, t.stringValues)
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/helm/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ a packaged chart, or a fully qualified URL. For chart references, the latest
version will be specified unless the '--version' flag is set.
To override values in a chart, use either the '--values' flag and pass in a file
or use the '--set' flag and pass configuration from the command line.
or use the '--set' flag and pass configuration from the command line, to force string
values, use '--set-string'.
You can specify the '--values'/'-f' flag multiple times. The priority will be given to the
last (right-most) file specified. For example, if both myvalues.yaml and override.yaml
Expand All @@ -63,6 +64,7 @@ type upgradeCmd struct {
disableHooks bool
valueFiles valueFiles
values []string
stringValues []string
verify bool
keyring string
install bool
Expand Down Expand Up @@ -118,6 +120,7 @@ func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command {
f.BoolVar(&upgrade.recreate, "recreate-pods", false, "performs pods restart for the resource if applicable")
f.BoolVar(&upgrade.force, "force", false, "force resource update through delete/recreate if needed")
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.StringArrayVar(&upgrade.stringValues, "set-string", []string{}, "set STRING 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")
Expand Down Expand Up @@ -183,6 +186,7 @@ func (u *upgradeCmd) run() error {
disableHooks: u.disableHooks,
keyring: u.keyring,
values: u.values,
stringValues: u.stringValues,
namespace: u.namespace,
timeout: u.timeout,
wait: u.wait,
Expand All @@ -191,7 +195,7 @@ func (u *upgradeCmd) run() error {
}
}

rawVals, err := vals(u.valueFiles, u.values)
rawVals, err := vals(u.valueFiles, u.values, u.stringValues)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion docs/chart_best_practices/values.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ There are three potential sources of values:
- A chart's `values.yaml` file
- A values file supplied by `helm install -f` or `helm upgrade -f`
- The values passed to a `--set` flag on `helm install` or `helm upgrade`
- The values passed to a `--set` or `--set-string` flag on `helm install` or `helm upgrade`
When designing the structure of your values, keep in mind that users of your
chart may want to override them via either the `-f` flag or with the `--set`
Expand Down
62 changes: 34 additions & 28 deletions docs/helm/helm_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ The install argument must be a chart reference, a path to a packaged chart,
a path to an unpacked chart directory or a URL.

To override values in a chart, use either the '--values' flag and pass in a file
or use the '--set' flag and pass configuration from the command line.
or use the '--set' flag and pass configuration from the command line, to force
a string value use '--set-string'.

$ helm install -f myvalues.yaml ./redis

or

$ helm install --set name=prod ./redis

or

$ helm install --set-string long_int=1234567890 ./redis

You can specify the '--values'/'-f' flag multiple times. The priority will be given to the
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:
Expand Down Expand Up @@ -69,32 +74,33 @@ helm install [CHART]
### Options

```
--ca-file string verify certificates of HTTPS-enabled servers using this CA bundle
--cert-file string identify HTTPS client using this SSL certificate file
--dep-up run helm dependency update before installing the chart
--devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.
--dry-run simulate an install
--key-file string identify HTTPS client using this SSL key file
--keyring string location of public keys used for verification (default "~/.gnupg/pubring.gpg")
-n, --name string release name. If unspecified, it will autogenerate one for you
--name-template string specify template used to name the release
--namespace string namespace to install the release into. Defaults to the current kube config namespace.
--no-hooks prevent hooks from running during install
--password string chart repository password where to locate the requested chart
--replace re-use the given name, even if that name is already used. This is unsafe in production
--repo string chart repository url where to locate the requested chart
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--timeout int time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks) (default 300)
--tls enable TLS for request
--tls-ca-cert string path to TLS CA certificate file (default "$HELM_HOME/ca.pem")
--tls-cert string path to TLS certificate file (default "$HELM_HOME/cert.pem")
--tls-key string path to TLS key file (default "$HELM_HOME/key.pem")
--tls-verify enable TLS for request and verify remote
--username string chart repository username where to locate the requested chart
-f, --values valueFiles specify values in a YAML file or a URL(can specify multiple) (default [])
--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
--wait if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment are in a ready state before marking the release as successful. It will wait for as long as --timeout
--ca-file string verify certificates of HTTPS-enabled servers using this CA bundle
--cert-file string identify HTTPS client using this SSL certificate file
--dep-up run helm dependency update before installing the chart
--devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.
--dry-run simulate an install
--key-file string identify HTTPS client using this SSL key file
--keyring string location of public keys used for verification (default "~/.gnupg/pubring.gpg")
-n, --name string release name. If unspecified, it will autogenerate one for you
--name-template string specify template used to name the release
--namespace string namespace to install the release into. Defaults to the current kube config namespace.
--no-hooks prevent hooks from running during install
--password string chart repository password where to locate the requested chart
--replace re-use the given name, even if that name is already used. This is unsafe in production
--repo string chart repository url where to locate the requested chart
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--set-string stringArray set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--timeout int time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks) (default 300)
--tls enable TLS for request
--tls-ca-cert string path to TLS CA certificate file (default "$HELM_HOME/ca.pem")
--tls-cert string path to TLS certificate file (default "$HELM_HOME/cert.pem")
--tls-key string path to TLS key file (default "$HELM_HOME/key.pem")
--tls-verify enable TLS for request and verify remote
--username string chart repository username where to locate the requested chart
-f, --values valueFiles specify values in a YAML file or a URL(can specify multiple) (default [])
--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
--wait if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment are in a ready state before marking the release as successful. It will wait for as long as --timeout
```

### Options inherited from parent commands
Expand All @@ -111,4 +117,4 @@ helm install [CHART]
### SEE ALSO
* [helm](helm.md) - The Helm package manager for Kubernetes.

###### Auto generated by spf13/cobra on 8-Mar-2018
###### Auto generated by spf13/cobra on 20-Mar-2018
11 changes: 6 additions & 5 deletions docs/helm/helm_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ helm lint [flags] PATH
### Options

```
--namespace string namespace to install the release into (only used if --install is set) (default "default")
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--strict fail on lint warnings
-f, --values valueFiles specify values in a YAML file (can specify multiple) (default [])
--namespace string namespace to install the release into (only used if --install is set) (default "default")
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--set-string stringArray set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--strict fail on lint warnings
-f, --values valueFiles specify values in a YAML file (can specify multiple) (default [])
```

### Options inherited from parent commands
Expand All @@ -41,4 +42,4 @@ helm lint [flags] PATH
### SEE ALSO
* [helm](helm.md) - The Helm package manager for Kubernetes.

###### Auto generated by spf13/cobra on 8-Mar-2018
###### Auto generated by spf13/cobra on 9-Mar-2018
21 changes: 11 additions & 10 deletions docs/helm/helm_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ helm template [flags] CHART
### Options

```
-x, --execute stringArray only execute the given templates
--kube-version string kubernetes version used as Capabilities.KubeVersion.Major/Minor (default "1.9")
-n, --name string release name (default "RELEASE-NAME")
--name-template string specify template used to name the release
--namespace string namespace to install the release into
--notes show the computed NOTES.txt file as well
--output-dir string writes the executed templates to files in output-dir instead of stdout
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
-f, --values valueFiles specify values in a YAML file (can specify multiple) (default [])
-x, --execute stringArray only execute the given templates
--kube-version string kubernetes version used as Capabilities.KubeVersion.Major/Minor (default "1.9")
-n, --name string release name (default "RELEASE-NAME")
--name-template string specify template used to name the release
--namespace string namespace to install the release into
--notes show the computed NOTES.txt file as well
--output-dir string writes the executed templates to files in output-dir instead of stdout
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--set-string stringArray set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
-f, --values valueFiles specify values in a YAML file (can specify multiple) (default [])
```

### Options inherited from parent commands
Expand All @@ -50,4 +51,4 @@ helm template [flags] CHART
### SEE ALSO
* [helm](helm.md) - The Helm package manager for Kubernetes.

###### Auto generated by spf13/cobra on 8-Mar-2018
###### Auto generated by spf13/cobra on 9-Mar-2018
Loading

0 comments on commit a615f80

Please sign in to comment.