From 19d79427a12f3be398b671d493b764634187ef5b Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Tue, 1 Sep 2020 10:13:27 +0900 Subject: [PATCH] Add experimental "forceNamespace" in helmfile.yaml (#1444) This is an experimental feature to support a potential use-case that you need to set namespaces in manifests rendered by `helmfile template`, WHEN the chart is unconventional hence does not have `namespace: {{ .Namespace }}`. Rather than using this, you should usually fork/maintain or update/pull-request the chart to have `namespace: {{ .Namespace }}`. Use this only when you CAN NOT do so, but still need to use `helmfile template`. --- pkg/state/helmx.go | 4 ++++ pkg/state/state.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/pkg/state/helmx.go b/pkg/state/helmx.go index d0a2b39f..4d845cd0 100644 --- a/pkg/state/helmx.go +++ b/pkg/state/helmx.go @@ -144,6 +144,10 @@ func (st *HelmState) PrepareChartify(helm helmexec.Interface, release *ReleaseSp shouldRun = true } + if release.ForceNamespace != "" { + chartify.Opts.OverrideNamespace = release.ForceNamespace + } + if shouldRun { generatedFiles, err := st.generateValuesFiles(helm, release, workerIndex) if err != nil { diff --git a/pkg/state/state.go b/pkg/state/state.go index ecaf76a9..4e8f12c2 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -253,6 +253,13 @@ type ReleaseSpec struct { // Without this, any error in url parsing result in silently falling-back to normal process of treating `chart:` as the regular // helm chart name. ForceGoGetter bool `yaml:"forceGoGetter,omitempty"` + + // ForceNamespace is an experimental feature to set metadata.namespace in every K8s resource rendered by the chart, + // regardless of the template, even when it doesn't have `namespace: {{ .Namespace | quote }}`. + // This is only needed when you can't FIX your chart to have `namespace: {{ .Namespace }}` AND you're using `helmfile template`. + // In standard use-cases, `Namespace` should be sufficient. + // Use this only when you know what you want to do! + ForceNamespace string `yaml:"forceNamespace"` } type Release struct {