使用Golang模板动态获取变量

I'm using Golang templates to manage deployments with Helm.

I have the values.yaml file like this:

env: dev
config:
   dev:
       myname: Hi
   live:
       myname: Bye

Now I'd like to get the values depending on the environment (dev, live). Like:

{{ .Values.config. {{.Values.env}} }}

Unfortunately, this way doesn't work because it says:

bad character U+007B '{'

Is there any way to get the value using others values?

The following may work. I didn't test it...

{{ .Values.config.(.Values.env) }}

The full template syntax is found in the text/template documentation.

The problem comes from the nested template, this is not how golang templates work.

The solution depends on the internal representation of the data. If it is represented as nested maps, a solution is to use the pipeline global function index.

{{ index .Values.config .Values.env `myname` }}

More info on pipelines.

More info on global template functions.