我试图创建一个包含多个文件的秘密。
myvalue.yaml(多行的格式不是yaml或json(
secretFiles:
- name: helm-template-file
subPath: ".file1"
mode: "0644"
value: |
This is a multiline
value, aka heredoc.
然后我的秘密文件模板是secret.yaml:
apiVersion: v1
kind: Secret
metadata:
name: {{ include "helm-template.fullname" . }}-file
namespace: {{ .Release.Namespace }}
labels:
app: {{ include "helm-template.name" . }}
chart: {{ include "helm-template.chart" . }}
type: Opaque
stringData:
{{- range .Values.secretFiles }}
{{ .subPath}}: |
{{ .value | indent 4}}
{{- end }}
舵杆安装出现错误";将YAML转换为JSON:YAML:行12时出错:未找到预期的注释或换行符";。我该怎么修?非常感谢。
values.yaml
secretFiles:
- name: helm-template-file
subPath: ".file1"
mode: "0644"
value: |
This is a multiline
value, aka heredoc.
- name: helm-template-file2
subPath: ".file2"
mode: "0644"
value: |
This is a multiline222
value, aka heredoc.
xxx_tpl.yaml
...
stringData:
{{- range .Values.secretFiles }}
{{ .subPath}}: |
{{- .value | nindent 4}}
{{- end }}
输出
...
stringData:
.file1: |
This is a multiline
value, aka heredoc.
.file2: |
This is a multiline222
value, aka heredoc.
参考:
nindent
nindent函数与indent函数相同,但在字符串的开头加上一行换行符。
缩进
缩进函数将给定字符串中的每一行缩进到指定的缩进宽度
indent
一行时,需要确保该行中的标记从第一列开始。
stringData:
{{- range .Values.secretFiles }}
{{ .subPath}}: |
{{ .value | indent 4}}{{/* no space at start of this line */}}
{{- end }}
在原始问题中的形式中,行开头的四个空格被复制到输出中,然后indent
表达式在每行开头再添加四个空格。这导致第一行缩进八个空格,第二行缩进4,这种不一致性导致您看到的YAML解析错误。
如果你在图表上运行helm template --debug
,你也可以直观地看到这一点;您将看到相同的错误,但也会看到无法解析的模板输出。
(@z.x的答案以不同的方式解决了同样的问题:将-
放在大括号内会删除前导空格和前面的换行符,然后将indent
更改为nindent
会将换行符放回。(