how split if statement over multiple lines in helm chart

Viewed 61

Im trying to format my yml to be more readable. I have an if statement that is really long with a bunch of and/ors and I would like to be able to spread it across multiple lines So something along the lines of

{{-if or
   (eq 'abc' .values.foo)
   (eq 'def' . values.bar)
}}
Def:'works'
{{- end}}
   

But this throws up errors for incomplete if statement. Is there some special character or syntax I can use to achieve the above?

1 Answers

helm supports direct line breaks without special characters.

Missing a space between {{ and if.

There is an extra space between . and values.

String constants require double quotes.

demo:

values.yaml

foo: xxx
bar: yyy

templates/cm.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "test.fullname" . }}-v33
  labels:
    {{- include "test.labels" . | nindent 4 }}
data: 
  cfg: |-
    {{- if or
      (eq "abc" .Values.foo)
      (eq "def" .Values.bar)
    }}
    if
    {{- else }}
    else
    {{- end }}

cmd

helm template --debug test .

output

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data: 
  cfg: |-
    else
Related