helmfile: Put Go Template into environmental values

203 views Asked by At

I have a particular need. I'd like to add a go template to the environment values, but have them interpreted in releases.values.

Here's a simplified example:

helmfile.yaml

releases:
  - name: cluster
    chart: ../charts/cluster
    values:
      - values/cluster/values.yaml.gotmpl

environments:
  development:
    values:
      - ./environments/development/values.yaml.gotmpl

values/cluster/values.yaml.gotmpl

registry:
  docker:
    url: '{{ .Values | get "registry.docker.url" "" }}'

service-1:
  enabled: {{ .Values | get "service-1.enabled" false }}
  chartValues:
{{ toYaml .Values.service-1.chartValues | indent 4 }}

service-2:
  enabled: {{ .Values | get "service-2.enabled" false }}
  chartValues:
{{ toYaml .Values.service-2.chartValues | indent 4 }}

environments/development/values.yaml.gotmpl

registry:
  docker:
    url: "registry.hub.docker.com"

service-1:
  enabled: true
  chartValues: 
    image:
      repository: {{ .Values | getOrNil "registry.docker.url" }}/service-1


service-2:
  enabled: true
  chartValues: 
    image:
      repository: {{ .Values | getOrNil "registry.docker.url" }}/service-2

In reality there are many services with different chartValues for each service.

The problem with this example is that it interprets registry.docker.url too early (the values are null at the environment level). I'd like them to be dynamically filled when they arrive at releases.values. I think I need to use tpl but I haven't succeeded.

thanks for your support

1

There are 1 answers

1
zzamzam On BEST ANSWER

Move releases and environments to separate files and include them in helmfile.yaml with bases keyword and yaml doc separator like this:

helmfile.yaml

bases:
  - environments.yaml
---
bases:
  - releases.yaml

That should do the work, just be assure to not use hyphens in values key names (or use index method)

I personally use such approach in my deploy repos (example)

Official doc link