kubernetes-helmgo-templates

What is different between {{ ... }} and {{- ... -}} syntax in Helm3?


I couldn't find any documentation, but I keep seeing examples.

Like:

{{- 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 }}

Solution

  • Helm uses standard Go templating. Have a look at https://pkg.go.dev/text/template#hdr-Text_and_spaces In short {{- something }} means "trim left whitespace" and {{ something -}} means "trim right whitespace". | nindent 4 means "add 4 spaces before". You need this operators for correct indenting your yaml.