kubernetes-helmhelmfile

Templating value file using Helmfile and got "error during tpl function execution"


I'm using helmfile to install my Helm chart and other dependencies charts. I want to use templated values in the value files.
From this resolved issue, it looks like templating in value files is supported. However, I tested with the following files: helmfile.yaml:

environments:
  default:
    values:
    - my:
        port: 8080
---
repositories:
  - name: incubator
    url: https://kubernetes-charts-incubator.storage.googleapis.com
releases:
- name: haproxy-ingress
  namespace: haproxy-ingress
  chart: incubator/haproxy-ingress
  version: 0.0.27
  values:
  - values.yaml

values.yaml:

controller:
  tcp:
    1936: "my_namespace/my-service:{{ .Values.my.port }}"

And if I run helmfile template, I would get

COMBINED OUTPUT:
  Error: template: haproxy-ingress/templates/tcp-configmap.yaml:16:31: executing "haproxy-ingress/templates/tcp-configmap.yaml" at <tpl $value $>: error calling tpl: error during tpl function execution for "my_namespace/my-service:{{ .Values.my.port }}": template: haproxy-ingress/templates/tcp-configmap.yaml:1:34: executing "haproxy-ingress/templates/tcp-configmap.yaml" at <.Values.my.port>: nil pointer evaluating interface {}.port
  Use --debug flag to render out invalid YAML

If I inline the values, it works

environments:
  default:
    values:
    - my:
        port: 8080
---
repositories:
  - name: incubator
    url: https://kubernetes-charts-incubator.storage.googleapis.com
releases:
- name: haproxy-ingress
  namespace: haproxy-ingress
  chart: incubator/haproxy-ingress
  version: 0.0.27
  values:
  - controller:
      tcp:
        1936: "my_namespace/my-service:{{ .Values.my.port }}"

Solution

  • I got the answer. From the document of helmfile,

    You can use go's text/template expressions in helmfile.yaml and values.yaml.gotmpl (templated helm values files). values.yaml references will be used verbatim. In other words: for value files ending with .gotmpl, template expressions will be rendered for plain value files (ending in .yaml), content will be used as-is

    Therefore, for this case, values.yaml should be renamed to values.yaml.gotmpl so that helmfile will interpret the file as go template.