diff --git a/cmd/helm/template.go b/cmd/helm/template.go index e3c1d421f..128855269 100644 --- a/cmd/helm/template.go +++ b/cmd/helm/template.go @@ -182,6 +182,7 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f.BoolVar(&client.IsUpgrade, "is-upgrade", false, "set .Release.IsUpgrade instead of .Release.IsInstall") f.StringVar(&kubeVersion, "kube-version", "", "Kubernetes version used for Capabilities.KubeVersion") f.StringArrayVarP(&extraAPIs, "api-versions", "a", []string{}, "Kubernetes api versions used for Capabilities.APIVersions") + f.BoolVar(&client.StrictAPIVersions, "strict-api-versions", false, "set api versions to strict mode") f.BoolVar(&client.UseReleaseName, "release-name", false, "use release name in the output-dir path.") bindPostRenderFlag(cmd, &client.PostRenderer) diff --git a/pkg/action/install.go b/pkg/action/install.go index b84a57271..b0fd2d0df 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -101,6 +101,8 @@ type Install struct { // (for things like templating). These are ignored if ClientOnly is false KubeVersion *chartutil.KubeVersion APIVersions chartutil.VersionSet + // Used by helm template to limit API versions to the one specified in the --api-versions tag + StrictAPIVersions bool // Used by helm template to render charts with .Release.IsUpgrade. Ignored if Dry-Run is false IsUpgrade bool // Used by helm template to add the release as part of OutputDir path @@ -216,7 +218,11 @@ func (i *Install) RunWithContext(ctx context.Context, chrt *chart.Chart, vals ma if i.KubeVersion != nil { i.cfg.Capabilities.KubeVersion = *i.KubeVersion } - i.cfg.Capabilities.APIVersions = append(i.cfg.Capabilities.APIVersions, i.APIVersions...) + if i.StrictAPIVersions && len(i.APIVersions) > 0 { + i.cfg.Capabilities.APIVersions = i.APIVersions + } else { + i.cfg.Capabilities.APIVersions = append(i.cfg.Capabilities.APIVersions, i.APIVersions...) + } i.cfg.KubeClient = &kubefake.PrintingKubeClient{Out: ioutil.Discard} mem := driver.NewMemory()