Converting a yaml sequence to a yaml map in a helm chart (Kubernetes)

1/23/2019

I have a helm values file (yaml) containing the following block:

env:
- name: <key>
  value: <value>
- name: <key1>
  value: <value1>

I would like to inject the above block into a kubernetes configmap definition. The result should look the following:

data: 
  key: value
  key1: value1

I tried the following, however the resulting file would contain a yaml sequence instead of a yaml map:

{{ toYaml .Values.env }}

Any advise helping me to solve the problem is appreciated.

-- user2074945
kubernetes
kubernetes-helm
yaml

1 Answer

1/23/2019

You should be able to use:

{{- range .Values.env }}
  {{ .name }}:{{ .value}}
{{- end }}
-- Ryan Dawson
Source: StackOverflow