Get array of strings from helm config

纵然是瞬间 提交于 2019-12-06 09:50:41
Ryan Dawson

One way to get the output you're looking for is to change:

...
organizations:
  - 'foo'
  - 'bar'
...

To:

organizations: |
  [ 'foo', 'bar']

So helm treats it as a single string. We happen to know that it contains array content but helm just thinks it's a string. Then we can set that string directly in the configmap:

organizations: {{ .Values.organizations | indent 4 }}

What this does is what the grafana chart does in that it forces the user to specify the list in the desired format in the first place. Perhaps you'd prefer to take an array from the helm values and convert it to your desired format, which appears to me to be json format. To do that you could follow the example of the vault chart. So the configmap line becomes:

organizations: {{ .Values.organizations | toJson | indent 4 }}

Then the yaml that the user puts in can be as you originally had it i.e. a true yaml array. I tried this and it works but I notice that it gives double-quoted content like ["foo","bar"]

The other way you can do it is with:

organizations:
  {{- range .Values.organizations }}
    - {{ . }}
  {{- end }}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!