Helm - Templating variables in values.yaml

给你一囗甜甜゛ 提交于 2021-02-07 13:01:11

问题


I'm trying to template variables from a map inside the values.yaml into my final Kubernetes ConfigMap YAML.

I've read through https://github.com/helm/helm/issues/2492 and https://helm.sh/docs/chart_template_guide/ but can't seem to find an answer.

For some context, this is roughly what I'm trying to do:

values.yaml

config:
  key1: value
  key2: value-{{ .Release.Name }}

configmap.yaml

kind: ConfigMap
data:
  config-file: |
    {{- range $key, $value := .Values.config }}
    {{ $key }} = {{ $value }}
    {{- end }}

Where the desired output with would be:

helm template --name v1 mychart/

kind: ConfigMap
data:
  config-file: |
    key1 = value
    key2 = value-v1

I've tried a few variations using template functions and pipelining, but to no avail:

{{ $key }} = {{ tpl $value . }}
{{ $key }} = {{ $value | tpl . }}
{{ $key }} = {{ tpl $value $ }}

回答1:


Managed to solve this using the following syntax:

configmap.yaml

kind: ConfigMap
data:
  config-file: |
    {{- range $key, $value := .Values.config }}
    {{ $key }} = {{ tpl ($value | toString) $ }}
    {{- end }}



回答2:


The above would also have worked in this way

values.yaml

config:
  key1: "value"
  key2: "value-{{ .Release.Name }}"

configmap.yaml

kind: ConfigMap
data:
  config-file: |
    {{- range $key, $value := .Values.config }}
    {{ $key }} = {{ tpl $value $ }}
    {{- end }}

What I changed was : I put value in quotes in value.yaml and used template tpl in the config map.



来源:https://stackoverflow.com/questions/55958507/helm-templating-variables-in-values-yaml

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