首页 > 解决方案 > Helm3 中的 {{ ... }} 和 {{- ... -}} 语法有什么不同?

问题描述

我找不到任何文档,但我不断看到示例。

喜欢:

{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{- include "example.serviceAccountName" . -}} ##<=== {{- -}}
  example: {{ .Values.example.example }} ##<=== {{ }}
  labels:
    {{- include "alma.labels" . | nindent 4 }} ##<=== {{- }}
  {{- with .Values.serviceAccount.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
{{- end }}

标签: helm3

解决方案


Helm 使用标准的 Go 模板。看看https://pkg.go.dev/text/template#hdr-Text_and_spaces简而言之{{- something }},意思是“修剪左边的空白”,{{ something -}}意思是“修剪右边的空白”。| nindent 4意思是“前面加4个空格”。您需要此运算符来正确缩进您的 yaml。


推荐阅读