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

@ -63,18 +63,19 @@ To render just one template in a chart, use '-x':
`
type templateCmd struct {
namespace string
valueFiles valueFiles
chartPath string
out io.Writer
values []string
stringValues []string
nameTemplate string
showNotes bool
releaseName string
renderFiles []string
kubeVersion string
outputDir string
namespace string
valueFiles valueFiles
chartPath string
out io.Writer
values []string
stringValues []string
nameTemplate string
showNotes bool
releaseName string
releaseIsUpgrade bool
renderFiles []string
kubeVersion string
outputDir string
}
func newTemplateCmd(out io.Writer) *cobra.Command {
@ -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