Variable value as yaml key in helm chart

六月ゝ 毕业季﹏ 提交于 2019-12-04 01:51:17

问题


I want to choose config section from values.yaml by setting a variable in helm command line.

example part of values.yaml:

aaa:
  x1: "az1"
  x2: "az2"
bbb:
  x1: "bz1" 
  x2: "bz2"

example part of configmap.yaml

data: 
  {{ .Values.outsideVal.x1 }}

Expected result should looks like this

   data:
     az1

Test helm output

helm template --set outsideVal=aaa mychart

And got this error

Error: render error in "./templates/configmap.yaml": template: ./templates/configmap.yaml:21:12: executing "./templates/configmap.yaml" at <.Values.outsideVal.x...>: can't evaluate field x1 in type interface {}

So the question is how get the result as expected?


回答1:


I suspect you're looking for the text/template index function, which can look up a value in a map by a variable key.

{{ (index .Values .Values.outsideVal).x1 }}


来源:https://stackoverflow.com/questions/52407940/variable-value-as-yaml-key-in-helm-chart

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