如何遍历头盔图中的嵌套地图?

时间:2019-06-16 08:27:29

标签: kubernetes google-kubernetes-engine kubernetes-helm

我希望能够传递env vars纯文本和类似这样的秘密:

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

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

envVars有效,但是envVarsSecret不起作用

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 }

1 个答案:

答案 0 :(得分:4)

$.表示您正在尝试访问根值。您想要类似{{ $value.secretKeyRef | quote }}之类的东西。而且这不是循环的:)