Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace template doesn't render any value #351

Open
dtshepherd opened this issue Sep 19, 2018 · 14 comments
Open

Namespace template doesn't render any value #351

dtshepherd opened this issue Sep 19, 2018 · 14 comments

Comments

@dtshepherd
Copy link

dtshepherd commented Sep 19, 2018

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?

@mumoshu
Copy link
Collaborator

mumoshu commented Sep 19, 2018

@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.gotmpls?

@dtshepherd
Copy link
Author

I wanted to use it to build a URL that includes the namespace. That value is used in my chart templates.

@mumoshu
Copy link
Collaborator

mumoshu commented Sep 20, 2018

@dtshepherd Makes sense! Meanwhile you can use something like below as a work-around:

releases:
- name: myapp
   # ...
   set:
   - name: foo.bar.ns
      value: {{.Namespace}}

@dtshepherd
Copy link
Author

Yeah once you said I could use in the helmfile, that pointed to a workaround. Thanks!

@mumoshu
Copy link
Collaborator

mumoshu commented Sep 20, 2018

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

@dtshepherd
Copy link
Author

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?

@acaire
Copy link
Contributor

acaire commented Oct 4, 2018

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 }}'

@naphta
Copy link
Contributor

naphta commented Apr 12, 2019

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.

@Morriz
Copy link

Morriz commented Jul 28, 2019

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?

@mumoshu
Copy link
Collaborator

mumoshu commented Jul 29, 2019

@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, #756 (comment) is the only known work-around.

@ghost
Copy link

ghost commented Nov 18, 2021

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

@daper
Copy link

daper commented Apr 1, 2022

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.

@mumoshu
Copy link
Collaborator

mumoshu commented Apr 3, 2022

@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: {}

@daper
Copy link

daper commented Apr 4, 2022

@mumoshu, as @Tlzps commented, it works when you specify the --namespace option. But it comes as an empty value if not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants