Define values for each namespace

家住魔仙堡 提交于 2020-01-30 08:07:46

问题


values.yaml

replicas: {
  test: 1,
  stage: 2,
  prod: 3
}

Here I am trying to use Helm templates to define number of replicas per namespace but am unsure of the proper syntax and pattern:

deployment.yaml

replicas: {{ .Values.replicas.{{ .Release.Namespace }} }}

So if this were deployed to --namespace=prod, I would expect the template to return:

# .Values.replicas.prod
replicas: 3

回答1:


All of the template functions provided by the standard Go text/template library are available. In particular, that includes an index function which can do dynamic lookup in an array or map object.

replicas: {{ index .Values.replicas .Release.Namespace }}



回答2:


I don't think that Helm supports evaluating variable in the variable. For this, you're expression would need to be evaluated twice.

What you could do is to write the following code:

{{ if eq .Release.Namespace "test" }}{{ .Values.replicas.test }}{{ end }}

You can then also extract that code to your _helpers.tpl. Then the usage should be clear and pretty.



来源:https://stackoverflow.com/questions/56348814/define-values-for-each-namespace

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