helm 模板在使用 nindent 时添加空行
helm templating add empty line when using nindent
我的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:
.
The nindent function is the same as the indent function, but prepends
a new line to the beginning of the string.
参考:https://helm.sh/docs/chart_template_guide/function_list/#nindent
您应该使用 indent
而不是 nindent
,以避免在 spec:
之后换行
我的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:
.
The nindent function is the same as the indent function, but prepends a new line to the beginning of the string.
参考:https://helm.sh/docs/chart_template_guide/function_list/#nindent
您应该使用 indent
而不是 nindent
,以避免在 spec: