简体   繁体   中英

how split if statement over multiple lines in helm chart

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM