我的values.yaml文件:
podSelector:
app: myApp
app.kubernetes.io/instance: myApp
我的模板/temp.yaml文件
apiVersion: something/v1beta
kind: SomeResource
metadata:
name: someName
spec:
selection:
labels:
{{ .Values.podSelector | toYaml | indent 4 }}
helm template .
给我:-
apiVersion: something/v1beta
kind: SomeResource
metadata:
name: someName
spec:
selection:
labels:
app: myApp
app.kubernetes.io/instance: myApp #This is not indented
正如您所看到的,第二个键/值对没有缩进。如何实现正确的缩进?标签必须以相同的方式缩进
在您想要的输出中:
spec:
selector:
labels:
app: ...
#^^^^^
# there are exactly 6 spaces here
在Helm图中,{{ ... | indent ... }}
行需要从第一列开始,缩进值需要与空格数相匹配。
spec:
selector:
labels:
{{ .Values.podSelector | toYaml | indent 6 }}
{{/* no spaces at the start of the line; indent 6, not 4 */}}
如果使用... | toYaml | indent ...
,则indent
将应用于YAML的每一行。如果{{ ... }}
前面有空格,那么这些空格实际上只缩进第一行多余的内容,这将导致YAML解析错误。