如何解决使用 nindent 时,helm 模板添加空行
我的deployment.yaml
:
apiVersion: apps/v1
kind: Deployment
Metadata:
name: foo
labels:
app: foo
spec:
selector:
matchLabels:
app: foo
template:
Metadata:
labels:
app: foo
spec:
{{- include "pod" . | nindent 6 }}
我的_pod.tpl
:
{{- define "pod" -}}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 2 }}
{{- end }}
serviceAccountName: foo
containers:
- name: foo
image: Nginx:latest
{{- end }}
给我:
# Source: foo/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
Metadata:
name: foo
labels:
app: foo
spec:
selector:
matchLabels:
app: foo
template:
Metadata:
labels:
app: foo
spec:
imagePullSecrets:
- name: bar
serviceAccountName: foo
containers:
- name: foo
image: Nginx:latest
为什么 spec:
后面有一个空行?
已编辑
然而,在Deployment中使用{{- include "pod" . | indent 6 }}
时没有空行,但是spec:
之后有6个空格,例如:spec:
。
解决方法
nindent 函数与 indent 函数相同,但添加了前缀 字符串开头的新行。
参考:https://helm.sh/docs/chart_template_guide/function_list/#nindent
您应该使用 indent
而不是 nindent
,以避免在 spec:
之后换行
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。