Add helm template --is-upgrade

Useful for toggling .Release.IsInstall / .Release.IsUpgrade which
in turn may cause templates to render differently.
pull/4105/head
Johnny Bergström 7 years ago
parent b6660cd5c9
commit 43b19dccbe

@ -72,6 +72,7 @@ type templateCmd struct {
nameTemplate string
showNotes bool
releaseName string
releaseIsUpgrade bool
renderFiles []string
kubeVersion string
outputDir string
@ -93,6 +94,7 @@ func newTemplateCmd(out io.Writer) *cobra.Command {
f := cmd.Flags()
f.BoolVar(&t.showNotes, "notes", false, "show the computed NOTES.txt file as well")
f.StringVarP(&t.releaseName, "name", "n", "RELEASE-NAME", "release name")
f.BoolVar(&t.releaseIsUpgrade, "is-upgrade", false, "set .Release.IsUpgrade instead of .Release.IsInstall")
f.StringArrayVarP(&t.renderFiles, "execute", "x", []string{}, "only execute the given templates")
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")
@ -159,6 +161,8 @@ func (t *templateCmd) run(cmd *cobra.Command, args []string) error {
}
options := chartutil.ReleaseOptions{
Name: t.releaseName,
IsInstall: !t.releaseIsUpgrade,
IsUpgrade: t.releaseIsUpgrade,
Time: timeconv.Now(),
Namespace: t.namespace,
}

@ -107,6 +107,20 @@ func TestTemplateCmd(t *testing.T) {
expectKey: "subchart1/templates/service.yaml",
expectValue: "release-name: \"test\"",
},
{
name: "check_release_is_install",
desc: "verify --is-upgrade toggles .Release.IsInstall",
args: []string{subchart1ChartPath, "--is-upgrade=false"},
expectKey: "subchart1/templates/service.yaml",
expectValue: "release-is-install: \"true\"",
},
{
name: "check_release_is_upgrade",
desc: "verify --is-upgrade toggles .Release.IsUpgrade",
args: []string{subchart1ChartPath, "--is-upgrade", "true"},
expectKey: "subchart1/templates/service.yaml",
expectValue: "release-is-upgrade: \"true\"",
},
{
name: "check_notes",
desc: "verify --notes shows notes",

@ -6,6 +6,8 @@ metadata:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
namespace: "{{ .Release.Namespace }}"
release-name: "{{ .Release.Name }}"
release-is-upgrade: "{{ .Release.IsUpgrade }}"
release-is-install: "{{ .Release.IsInstall }}"
kube-version/major: "{{ .Capabilities.KubeVersion.Major }}"
kube-version/minor: "{{ .Capabilities.KubeVersion.Minor }}"
kube-version/gitversion: "v{{ .Capabilities.KubeVersion.Major }}.{{ .Capabilities.KubeVersion.Minor }}.0"

Loading…
Cancel
Save