简体   繁体   English

关于 helm yaml 语法

[英]about helm yaml syntax

the configmap.yaml configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "test.fullname" . }}-config-map
data:
  brokerConf: |
    {{ .Values.configmap }}


the below values.yaml is right.下面的 values.yaml 是正确的。

configmap: |
  key=values

but the values.yaml is wrong但是 values.yaml 是错误的

configmap: |
  key=values
  key2=values2

the helm template core content is helm模板核心内容是

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config-map
data:
  brokerConf: |
    key=values
key2=values2

the error错误

Error: YAML parse error on test/templates/config-map.yaml: error converting YAML to JSON: yaml: line 9: could not find expected ':'
helm.go:84: [debug] error converting YAML to JSON: yaml: line 9: could not find expected ':'
YAML parse error on v5-proxy/templates/config-map.yaml
helm.sh/helm/v3/pkg/releaseutil.(*manifestFile).sort
    helm.sh/helm/v3/pkg/releaseutil/manifest_sorter.go:146
helm.sh/helm/v3/pkg/releaseutil.SortManifests
    helm.sh/helm/v3/pkg/releaseutil/manifest_sorter.go:106
helm.sh/helm/v3/pkg/action.(*Configuration).renderResources
    helm.sh/helm/v3/pkg/action/action.go:165

how to fix it?如何解决?

You may update the configmap as below:您可以按如下方式更新configmap

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-map
data:
  brokerConf:
    {{ .Values.configmap| indent 4|trim }}

The error is caused because the 2nd line in data.brokerConf is not indented properly.该错误是由于data.brokerConf中的第二行没有正确缩进引起的。 Something like below, where key2=values2 is an invalid statement in yaml world, the correct is key2: values2 .如下所示,其中key2=values2是 yaml 世界中的无效语句,正确的是key2: values2

configmap: 
  key=values
key2=values2

To fix it we have to use indent , but it will do indent the first line additionally.要修复它,我们必须使用indent ,但它会另外缩进第一行。 To address that , trim is used.为了解决这个问题,使用了trim

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM