Parse namespace to values file

1.5k views Asked by At

I'm trying to add the {{ .Release.Namespace }} to a string, but it's parsed literally as just {{ .Release.Namespace }} and not as the namespace itself. I've tried using quotes (") and using tpl, but nothing did the job. I'm using Helm v3.5.4.

In context:

config:
  config-proxy: |-
    _front__tls
      # BEGIN::Redirect to openBalena VPN
      acl is_ssl req.ssl_ver 2:3.4
      use_backend {{ .Release.Namespace }}_openbalena-vpn_443 if !is_ssl
      # END::Redirect to openBalena VPN

Whole values.yaml is found here, and the above snippet is located here.
I'm using the HAProxy Ingress Helm Chart.

In some parts, as you can see in the values.yaml, are also using {{ .Release.Namespace }}, but those are parsed fine (like the TCP options for example).

Thanks in advance!

2

There are 2 answers

3
René Jahn On

It should work if you have config-proxy place in <chart_root_dir>/files/config-proxy and use tpl function to load it in your template like this:

config:
{{ tpl (.Files.Glob "files/config-proxy").AsConfig .  | indent 2 }}

Not sure about how nested your config key is i your template, so you might adjust the indent level from the example.

0
Bart Versluijs On

After investigating it some more and with the help of @Minato and @mdaniel (thanks for that), I came to the conclusion that it simply isn't possible using the values.yaml alone. I've created a PR in the Chart.

Before the PR, the values were parsed like this:

{{- toYaml .Values.controller.config | nindent 2 }}

I've changed that to:

{{- tpl (toYaml .Values.controller.config) . | nindent 2 }}

And now it parses the {{ .Release.Namespace }} fine!