helm 图表:将 value.yaml 中的多行包含到 configmap 中

Mar*_*ner 6 yaml go-templates kubernetes kubernetes-helm

我想创建一个舵图,其结果是如下所示的配置图:

apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfigmap
data:
  myconfigfile1.properties: |
    property11 = value11
    property12 = value12
  myconfigfile1.properties: |
    property21 = value21
    property22 = value22
Run Code Online (Sandbox Code Playgroud)

而这部分应可在以下位置进行配置values.yaml

myconfig:
  myconfigfile1.properties: |
    property11 = value11
    property12 = value12
  myconfigfile1.properties: |
    property21 = value21
    property22 = value22
Run Code Online (Sandbox Code Playgroud)

现在我想迭代 的所有子项myconfig并将values.yaml它们添加到我的头盔模板中。到目前为止我对此模板的尝试:

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

Run Code Online (Sandbox Code Playgroud)

导致此错误消息:

$ 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
Run Code Online (Sandbox Code Playgroud)

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

非常感谢您提前的帮助。

亲切的问候,马丁

Mar*_*ner 9

写完这个问题几分钟后,我偶然发现了问题#62432632 Convert-a-yaml-to-string-in-helm,它并不能完全回答我的问题,但在它的帮助下我可以找到正确的语法。

values.yaml

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

  myconfigfile2.properties: |-
    property21 = value21
    property22 = value22
Run Code Online (Sandbox Code Playgroud)

模板:

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

Run Code Online (Sandbox Code Playgroud)