[英]helm chart: Include multiple lines from values.yaml into configmap
I want to create a helm chart that results in a config map that looks like this:我想创建一个掌舵图,其结果是配置 map,如下所示:
apiVersion: v1
kind: ConfigMap
metadata:
name: myconfigmap
data:
myconfigfile1.properties: |
property11 = value11
property12 = value12
myconfigfile1.properties: |
property21 = value21
property22 = value22
whereas this part shall be configurable in the values.yaml
:而这部分应可在
values.yaml
中配置:
myconfig:
myconfigfile1.properties: |
property11 = value11
property12 = value12
myconfigfile1.properties: |
property21 = value21
property22 = value22
Now I want to iterate over all the children of myconfig
in the values.yaml
and add them to my helm template.现在我想遍历
values.yaml
中myconfig
的所有子项并将它们添加到我的 helm 模板中。 My attempts so far with this template:到目前为止,我对这个模板的尝试:
apiVersion: v1
kind: ConfigMap
metadata:
name: myconfigmap
data:
# {{- range $key, $val := .Values.myconfig}}
# {{ $key }}: |
# {{ $val }}
# {{- end }}
resulted in this error message:导致此错误消息:
$ helm install --dry-run --debug ./mychart/ --generate-name
install.go:159: [debug] Original chart version: ""
install.go:176: [debug] CHART PATH: /home/my/helmcharts/mychart
Error: YAML parse error on mychart/templates/myconfig.yaml: error converting YAML to JSON: yaml: line 11: could not find expected ':'
helm.go:84: [debug] error converting YAML to JSON: yaml: line 11: could not find expected ':'
YAML parse error on mychart/templates/myconfig.yaml
I can avoid the error by removing the |
我可以通过删除
|
来避免错误after myconfigfile1.properties:
in my values.yaml
, however then I lose the line breaks and the result is not what I want.在
myconfigfile1.properties:
在我的values.yaml
,然后我失去了换行符,结果不是我想要的。
Many thanks for your help in advance.非常感谢您提前提供的帮助。
Kind regards, Martin亲切的问候,马丁
A few minutes after writing this question I stubled upon Question #62432632 convert-a-yaml-to-string-in-helm which does not exactly answer my question but with its help I could find the correct syntax.写完这个问题几分钟后,我偶然发现了问题 #62432632 convert-a-yaml-to-string-in-helm ,它不能完全回答我的问题,但在它的帮助下,我可以找到正确的语法。
values.yaml
: values.yaml
:
myconfig:
myconfigfile1.properties: |-
property11 = value11
property12 = value12
myconfigfile2.properties: |-
property21 = value21
property22 = value22
template:模板:
apiVersion: v1
kind: ConfigMap
metadata:
name: myconfigmap
data:
{{- range $name, $config := .Values.myconfig }}
{{ $name }}: |-
{{ tpl $config $ | indent 4 }}
{{- end }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.