Assign list to a key within a chart
The current Go template expansion will give output which is not YAML:
env: {{ .Values.env}}
becomes:
env: env: [Some Go type stuff that isn't YAML]...
The Helm Go template needs to loop over the keys of the source YAML dictionary.This is described in the Helm docs.
The correct Deployment.yaml is:
...env:{{- range .Values.env }} - name: {{ .name | quote }} value: {{ .value | quote }}{{- end }}...
Helm includes undocumented toYaml
and toJson
template functions; either will work here (because valid JSON is valid YAML). A shorter path could be
env: {{- .Values.env | toYaml | nindent 2 }}
Note that you need to be a little careful with the indentation, particularly if you're setting any additional environment variables that aren't in that list. In this example I've asked Helm to indent the YAML list two steps more, so additional environment values need to follow that too
env: {{- .Values.env | toYaml | nindent 2 }} - name: OTHER_SERVICE_URL value: "http://other-service.default.svc.cluster.local"