helmfile
helmfile copied to clipboard
Namespace template doesn't render any value
When I try to use {{ .Namespace }}
in a values.yaml.gotmpl
template, it just renders as an empty string. It doesn't throw an error. This happens if I let helmfile
use the default namespace or specify a namespace override with --namespace
on the CLI.
Maybe I'm missing something?
@dtshepherd Hey! Thanks for the report. Yeah {{.Namespace}}
is available only in helmfile.yaml
right now. For which purpose you want to use it from within values.yaml.gotmpl
s?
I wanted to use it to build a URL that includes the namespace. That value is used in my chart templates.
@dtshepherd Makes sense! Meanwhile you can use something like below as a work-around:
releases:
- name: myapp
# ...
set:
- name: foo.bar.ns
value: {{.Namespace}}
Yeah once you said I could use in the helmfile, that pointed to a workaround. Thanks!
Nice! Glad it worked for you.
One gotcha is that {{.Namespace}}
results in the value passed via --namespace
. That is, you can't refer to what was set in namespace:
key in your helmfile.yaml
.
So, do you expect {{.Namespace}}
to result in foo
in the below example?
releases:
- name: myapp
# ...
namespace: foo
Yeah, that's a good point. Ideally, it would work that way. I'm not quite clear on the --namespace
flag and how it interacts with namespace:
being specified on a release given that there can be multiple namespaces specified if there are multiple. Does the --namespace
flag override all specified namespace:
fields in the releases
?
I'm after this functionality too - My use case is related to two different environments:
environments:
default:
values:
- helm_vars/minikube.yaml
test1:
values:
- helm_vars/test1.yaml
default
- minikube - Everything is in the default
namespace to ease developer use
test1
- test cluster - Everything is in a namespace per app, i.e. fluentd
So for example helm_vars/minikube.yaml
has:
releaseNamespace: {{ env "RELEASE_NAMESPACE" | default "default" }}
so it can be overriden with env vars if necessary, and then I refer to it like so:
releases:
- name: fluentd
namespace: {{ .Environment.Values | getOrNil "releaseNamespace" | default "fluentd" }}
chart: stable/fluentd-elasticsearch
values:
- helm_vars/apps/fluentd.yaml.gotmpl
Finally, this is how i'm trying to use {{ .Namespace }}
in ./helm_vars/apps/fluentd.yaml.gotmpl
without having to duplicate the previous value again:
elasticsearch:
host: 'elasticsearch-client.{{ .Namespace }}'
Is there a different workaround? I'm looking for a similar setup as @acaire and since it's quite a few settings with a substring of namespace (also release name) it's a bit heavy handed to set all of those specifically in the helmfile.
Is there a way to get access to the namespace in values.gotmpl
?:
...
releases:
...
namespace: bla
values:
- namespace: bla
- values.gotmpl
In the context of values.gotmpl
both .Environment.Values.namespace
and .Namespace
are empty...what am I missing?
@Morriz I think you're confusing the context of values.gotmpl
and helmfile.yaml
. They're different and you have no way to alter the values.gotmpl
context from within each release under releases
.
We'll need what we're discussing in #745 in order to elegantly write it.
Until then, https://github.com/roboll/helmfile/issues/756#issuecomment-514013382 is the only known work-around.
Even in helmfile.yaml I got the issue, except if I specify a --namespace
arg in the helmfile command.
The context I use got a namespace
Yep, I could not find a way to pick the targeting namespace and use it on the values section.
My use case is to specify the value for default-ssl-certificate
for the nginx-ingress, which is on the form of namespace/secretName
.
@daper Here's what works for me.
values.351.yaml.gotmpl
:
myns2: {{ .Release.Namespace }}
myns3: {{ .Namespace }}
helmfile.351.yaml
:
releases:
- name: foo
chart: stable/nginx
namespace: bar
values:
- myns1: {{ .Namespace }}
- values.351.yaml.gotmpl
$ helmfile -f helmfile.351.yaml --namespace foo build --embed-values
---
# Source: helmfile.351.yaml
filepath: helmfile.351.yaml
helmBinary: helm
namespace: foo
releases:
- chart: stable/nginx
name: foo
namespace: bar
values:
- myns1: foo
- myns2: bar
myns3: foo
templates: {}
renderedvalues: {}
@mumoshu, as @Tlzps commented, it works when you specify the --namespace
option. But it comes as an empty value if not.