helm template: display the default value of --kube-version in help message

This commit improves to display the default value of --kube-version in
help message of `helm template` command.

```
--kube-version string    kubernetes version used as Capabilities.KubeVersion.Major/Minor (default "1.9")
```
pull/3297/head
Kazuki Suda 7 years ago
parent 512a887421
commit 7b5a837b04

@ -42,7 +42,12 @@ import (
const defaultDirectoryPermission = 0755 const defaultDirectoryPermission = 0755
var whitespaceRegex = regexp.MustCompile(`^\s*$`) var (
whitespaceRegex = regexp.MustCompile(`^\s*$`)
// defaultKubeVersion is the default value of --kube-version flag
defaultKubeVersion = fmt.Sprintf("%s.%s", chartutil.DefaultKubeVersion.Major, chartutil.DefaultKubeVersion.Minor)
)
const templateDesc = ` const templateDesc = `
Render chart templates locally and display the output. Render chart templates locally and display the output.
@ -92,7 +97,7 @@ func newTemplateCmd(out io.Writer) *cobra.Command {
f.StringVar(&t.namespace, "namespace", "", "namespace to install the release into") 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.values, "set", []string{}, "set 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.nameTemplate, "name-template", "", "specify template used to name the release")
f.StringVar(&t.kubeVersion, "kube-version", "", "override the Kubernetes version used as Capabilities.KubeVersion.Major/Minor (e.g. 1.7)") 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") f.StringVar(&t.outputDir, "output-dir", "", "writes the executed templates to files in output-dir instead of stdout")
return cmd return cmd
@ -194,17 +199,16 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
KubeVersion: chartutil.DefaultKubeVersion, KubeVersion: chartutil.DefaultKubeVersion,
TillerVersion: tversion.GetVersionProto(), TillerVersion: tversion.GetVersionProto(),
} }
// If --kube-versionis set, try to parse it as SemVer, and override the
// kubernetes version // kubernetes version
if t.kubeVersion != "" { kv, err := semver.NewVersion(t.kubeVersion)
kv, err := semver.NewVersion(t.kubeVersion) if err != nil {
if err != nil { return fmt.Errorf("could not parse a kubernetes version: %v", err)
return fmt.Errorf("could not parse a kubernetes version: %v", err)
}
caps.KubeVersion.Major = fmt.Sprint(kv.Major())
caps.KubeVersion.Minor = fmt.Sprint(kv.Minor())
caps.KubeVersion.GitVersion = fmt.Sprintf("v%d.%d.0", kv.Major(), kv.Minor())
} }
caps.KubeVersion.Major = fmt.Sprint(kv.Major())
caps.KubeVersion.Minor = fmt.Sprint(kv.Minor())
caps.KubeVersion.GitVersion = fmt.Sprintf("v%d.%d.0", kv.Major(), kv.Minor())
vals, err := chartutil.ToRenderValuesCaps(c, config, options, caps) vals, err := chartutil.ToRenderValuesCaps(c, config, options, caps)
if err != nil { if err != nil {
return err return err

@ -26,7 +26,7 @@ helm template [flags] CHART
``` ```
-x, --execute stringArray only execute the given templates -x, --execute stringArray only execute the given templates
--kube-version string override the Kubernetes version used as Capabilities.KubeVersion.Major/Minor (e.g. 1.7) --kube-version string kubernetes version used as Capabilities.KubeVersion.Major/Minor (default "1.9")
-n, --name string release name (default "RELEASE-NAME") -n, --name string release name (default "RELEASE-NAME")
--name-template string specify template used to name the release --name-template string specify template used to name the release
--namespace string namespace to install the release into --namespace string namespace to install the release into
@ -50,4 +50,4 @@ helm template [flags] CHART
### SEE ALSO ### SEE ALSO
* [helm](helm.md) - The Helm package manager for Kubernetes. * [helm](helm.md) - The Helm package manager for Kubernetes.
###### Auto generated by spf13/cobra on 15-Nov-2017 ###### Auto generated by spf13/cobra on 17-Jan-2018

Loading…
Cancel
Save