Modify specific helm toYaml output template

10/31/2019

I have the following in my dep.yml {{ toYaml .Values.volumes | indent 8 }} which takes an array from values.yml of volumes and then loads it on the dep.yml file.

I want the following result on my dep.yml from the initial array

 volumes:
    - name: volume
      persistentVolumeClaim:
        claimName: {{ Release.Name }}-volume-claim
    - name: volume-a
      persistentVolumeClaim:
        claimName: {{ Release.Name }}-volume-a-claim
    - name: volume-b
      persistentVolumeClaim:
        claimName: {{ Release.Name }}-volume-b-claim

Adding the {{ Release.Name }} dynamically to the volume claim name for each element of the array.

Is there any way to achieve this modifying the {{ toYaml .Values.volumes | indent 8 }} directive?

-- gusgleuy
kubernetes
kubernetes-helm

1 Answer

11/1/2019

Helm includes a tpl function that expands template content in a string. I would fit this into the pipeline after rendering the value to a string, but before indenting it; its parameters don't quite fit into the standard pipeline setup.

{{ tpl (toYaml .Values.volumes) . | indent 8 }}
-- David Maze
Source: StackOverflow