Helm use default string when values is empty string
Solution 1:
The Go text/template
with
operator is helpful here. Like if
, it tests to see if the value is "truthy"; if it is, then inside the block, it binds the special variable .
to the value it matched. So here you could write:
name: {{ with .Values.nameOverride }}{{ . }}-{{ end }}init
Breaking this into more lines:
name: {{/* comment */}}
{{- with .Values.nameOverride -}} {{-/* if the value is defined */-}}
{{- . -}} {{-/* emit it */-}}
- {{-/* and a hyphen */-}}
{{- end -}}
init {{-/* and either way, the string "init" */}}