Icarus
Icarus

Reputation: 135

Helm Chart environment from values file

I have the following values file:

MYVAR: 12123
MYVAR2: 214123

I want to iterate over them and use them as env variables in my deployment template:

env:
    {{- range .Values.examplemap }}
    - name: {{ .name }}
      value: {{ .value }}
    {{- end }}

I tried this

Upvotes: 0

Views: 2240

Answers (2)

David Maze
David Maze

Reputation: 158908

In the core Go text/template language, the range operator can iterate over either a list or a map. There's specific syntax to assign the key-value pairs in a map to local variables:

env:
{{- $k, $v := range .Values.examplemap }}
  - name: {{ $k }}
    value: {{ $v }}
{{- end }}

Upvotes: -1

Enrique Tejeda
Enrique Tejeda

Reputation: 366

For iterate over a map in helm you can try put this in the values.yaml

 extraEnvs:
   - name: ENV_NAME_1
     value: value123
   - name: ENV_NAME_2
     value: value123

So in your template you must iterate the extraEnvs like this:

 extraEnvs:
   {{- range .Values.image.extraEnvs }}
     - name: {{ .name | quote }}
       value: {{ .value | quote }}
   {{- end }}

Upvotes: 1

Related Questions