0

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!

Bart Versluijs
  • 186
  • 1
  • 8
  • 1
    `values.yaml` files (and its `--set` friend) are not subject to interpolation, as I'm sure that would be a security risk. If you want `.Values.config.config-proxy` to be interpolated, you can use helm's [`tpl` function](https://helm.sh/docs/howto/charts_tips_and_tricks/#using-the-tpl-function) – mdaniel Apr 20 '21 at 16:13
  • Thanks! Only thing is, when using the `tpl` function, it has to be done in the template yaml files and not in the `values.yaml` right? So only option is to change the behaviour in the Chart templates how it's parsed? – Bart Versluijs Apr 21 '21 at 10:56
  • @mdaniel would mind converting your comment into the answer since it addresses the OP question? – acid_fuji Apr 21 '21 at 14:02
  • 1
    @BartVersluijs yes, that's correct; the `values.yaml` does not execute any dynamic content (that's the original problem you were facing). If you are merely trying to replace the namespace, then using `tpl` may be more trouble than it's worth. If you have a lot of those gotmpl expressions, then patching the chart is the only way – mdaniel Apr 21 '21 at 15:48

2 Answers2

1

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.

René Jahn
  • 1,155
  • 1
  • 10
  • 27
  • Thanks for your answer! However, can I use that in the `values.yaml`, or do I have to do that in the Chart templates? Because I'm trying to set a config of a dependency chart. When I try this in the `values.yaml`, I get the following error: `Error: cannot load values.yaml: error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{"tpl (.Files.Glob (\"files/haproxy.config.yaml\")).AsConfig . | nindent 6":interface {}(nil)}` – Bart Versluijs Apr 23 '21 at 08:02
  • I didn't know it was an excerpt of your values.yml. You cannot use templating in the there, sorry. I myself have used this in config-maps, but it yhould work in all yamls in the templates folder – René Jahn Apr 23 '21 at 08:05
  • Ah okay, thanks! I'll try another solution for my problem then. Weird thing is that the `{{ .Release.Namespace }}` in another config in my `values.yaml` is being parsed, so I don't know why this isn't parsed... – Bart Versluijs Apr 23 '21 at 08:20
0

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!

Bart Versluijs
  • 186
  • 1
  • 8