how do I loop over a nested map in helm charts?

6/16/2019

I want to be able to pass in env vars plain text and from secrets like this:

envVars:
  var1: 'sdfsdfsdf'
  var2: 'efwefwefwef'

envVarsSecret:
  var3:
      secretKeyRef: my-secret
      key: key

envVars works but envVarsSecret does not

env:
# This works
{{- range $key, $value := .Values.envVars }}
- name: {{ $key }}
  value: {{ $value | quote }}
{{- end }}

# This doesn't throw an error but when deployed secretKeyRef and key are blank (the secret was pre-created and exists)
{{- range $key, $value := .Values.envVarsSecret }}
- name: {{ $key }}
  valueFrom:
    secretKeyRef:
      name: {{ $.Values.envVarsSecret.secretKeyRef | quote }}
      key: {{ $.Values.envVarsSecret.key | quote }}
{{- end }
-- red888
google-kubernetes-engine
kubernetes
kubernetes-helm

1 Answer

6/16/2019

$. like that means you are trying to access a root value. You want something like {{ $value.secretKeyRef | quote }} and similar. Also that's not looping :)

-- coderanger
Source: StackOverflow