helm chart:将来自values.yaml的多行内容包括到configmap中

问题描述 投票:1回答:1

我想创建一个舵图,以生成如下所示的配置图:

apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfigmap
data:
  myconfigfile1.properties: |
    property11 = value11
    property12 = value12
  myconfigfile1.properties: |
    property21 = value21
    property22 = value22

而此部分应可在values.yaml中配置:

myconfig:
  myconfigfile1.properties: |
    property11 = value11
    property12 = value12
  myconfigfile1.properties: |
    property21 = value21
    property22 = value22

现在,我要遍历myconfig中所有values.yaml的孩子,并将它们添加到我的头盔模板中。到目前为止,我使用此模板的尝试:

apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfigmap
data: 
  # {{- range $key, $val := .Values.myconfig}}
  # {{ $key }}: |
  #   {{ $val }}
  # {{- end }}

导致此错误消息:

$ 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

我可以通过删除|myconfigfile1.properties:之后的values.yaml来避免错误,但是我丢失了换行符,结果不是我想要的。

非常感谢您的提前帮助。

亲切的问候,马丁

kubernetes yaml kubernetes-helm go-templates
1个回答
0
投票

写完这个问题几分钟后,我在Question #62432632 convert-a-yaml-to-string-in-helm上打了个小号,虽然它不能完全回答我的问题,但是在它的帮助下,我可以找到正确的语法。

values.yaml

myconfig:
  myconfigfile1.properties: |-
    property11 = value11
    property12 = value12

  myconfigfile2.properties: |-
    property21 = value21
    property22 = value22

模板:

apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfigmap
data: 
{{- range $name, $config := .Values.myconfig }}
  {{ $name }}: |-
{{ tpl $config $ | indent 4 }}
  {{- end }}

© www.soinside.com 2019 - 2024. All rights reserved.