我正在为我的Helm图表设置ConfigMap。
按照优良作法,我想通过单独的文件而不是内联的方式包含非Yaml资源。目前,我正在尝试在ConfigMap中的“数据”下同时包含一个xml文件和一个tpl帮助程序。在下面的代码中,两者均被正确读取。但是我似乎无法使键的缩进正常工作。
我的ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "name" . }}
labels:
app: {{ template "name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ quote .Release.Name }}
heritage: {{ quote .Release.Service }}
name: {{ template "name" . }}
data:
logback.xml: |-
{{- .Files.Get "application-resources/logback.xml" | nindent 8 -}}
application.yml: |-
{{- include "application.yml" . | nindent 8 -}}
这会产生以下缩进(为了便于阅读,删除了实际值):
apiVersion: v1
kind: ConfigMap
metadata:
name: erklaering-anden-lov-detektor-app
labels:
app: name-of-app
chart: name-of-chart
release: "release-name"
heritage: "Tiller"
name: name-of-app
data:
logback.xml: |-
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<xml-stuff>
</configuration>
application.yml: |-
application.yml.contents
应该是:
apiVersion: v1
kind: ConfigMap
metadata:
name: erklaering-anden-lov-detektor-app
labels:
app: name-of-app
chart: name-of-chart
release: "release-name"
heritage: "Tiller"
name: name-of-app
data:
logback.xml: |-
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<xml-stuff>
</configuration>
application.yml: |-
application.yml.contents
我机智了。我究竟做错了什么?如何使yaml恢复识别ConfigMap自身的缩进和/或显式控制它?
答案 0 :(得分:0)
尝试一下:
data:
logback.xml: |-
{{- .Files.Get "application-resources/logback.xml" | nindent 8 }}
application.yml: |-
{{- include "application.yml" . | nindent 8 -}}
我从第三行中删除了“-”,因为它删除了以下空格。
您还可以查看此GitHub Issue #3470。
如果需要更多帮助,可以查看Chart Development Tips and Tricks的文档