Use case: I want to interpolate the namespace specified on the Helmfile command-line via --namespace into the release name in a helmfile.yaml. My motivation is that I'm trying to prefix all Helm release names with the name of the namespace that they correspond to, because I've got a global cluster-wide Helm Tiller and helm list is kind of useless if I can't tell at a glance which namespace a particular release belongs to. And perhaps more importantly, I want to avoid Helm release name collisions if the same thing is deployed to multiple different namespaces in a cluster.
Here's the sort of syntax I'm imagining:
releases:
- name: {{ .Namespace }}-my-chart
Please let me know if this isn't possible for some reason, e.g. the namespace isn't known at release name templating time.
I know that I could use the environment variable feature for this, but that would be duplicative with --namespace.
@witten Hey! It sounds great. Would you mind contributing a PR?
I don't know Go, but I can maybe give it a shot anyway. How would you prefer the namespace value to appear in the template? {{ .Namespace }}? {{ .Namespace.Name }}? {{ env "namespace" }}?
Thanks. {{ .Namespace }} sounds good 馃憤
I have not tested it myself, but basically you need to somehow propagate the namespace specified via --namespace from top to bottom. Perhaps the important steps would be look like the below:
Namespace string field to:https://github.com/roboll/helmfile/blob/7bfb58c0e40a36030d2282693d9761500861b916/tmpl/file.go#L16-L19
Populated its value here:
https://github.com/roboll/helmfile/blob/7bfb58c0e40a36030d2282693d9761500861b916/tmpl/file.go#L32-L34
Pass the namespace:
https://github.com/roboll/helmfile/blob/b3da9a9a07f44655d34081f5410a851b1e8ddebe/main.go#L638
Thanks, that's exactly the sort of guidance I needed. I've got an initial stab working now.. I'll do some additional testing and then submit it for review.
Why is the namespace not populated when it is specified in a release?
@Morriz its helm problem where helm install and helm template have different output. However maintainers of helm decided to close the issue as won't fix https://github.com/helm/helm/issues/3553
Yeah it's a helm/helm chart problem.
However, Helmfile has a secret feature called forceNamespace to, uh, set metadata.namespace forcefully, as a workaround to the problem. It works by Helmfile running helm template to render the manifests and setting metadata.namespace, and compiling it as a temporary chart(again). So you can use it when you know what you're doing.
releases:
- name: "aws-load-balancer-controller"
namespace: "kube-system"
forceNamespace: "kube-system"
I have created issue #1718 related to a bug I have found (in latest 0.138.7 release) when using this --namespace CLI option.