Helm Template If/Else: Difference between revisions
Jump to navigation
Jump to search
Line 40: | Line 40: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
= | =Expression= | ||
==Testing the Existence of Two Configuration Elements in the Same Expression== | ==Testing the Existence of Two Configuration Elements in the Same Expression== | ||
Line 54: | Line 54: | ||
<syntaxhighlight lang='yaml'> | <syntaxhighlight lang='yaml'> | ||
{{- if not .Values.myApp.something }} | {{- if not .Values.myApp.something }} | ||
... | |||
{{- end }} | |||
</syntaxhighlight> | |||
==Testing Equality and Inequality of Values== | |||
<syntaxhighlight lang='yaml'> | |||
{{- if eq .Values.myApp.color "blue" }} | |||
... | |||
{{- end }} | |||
</syntaxhighlight> | |||
<syntaxhighlight lang='yaml'> | |||
{{- if not eq .Values.myApp.color "blue" }} | |||
... | |||
{{- end }} | |||
</syntaxhighlight> | |||
<syntaxhighlight lang='yaml'> | |||
{{- if eq .Values.myApp.something .Values.myApp.somethingElse }} | |||
... | ... | ||
{{- end }} | {{- end }} |
Revision as of 23:11, 20 August 2020
External
Internal
Overview
if/else can be used to create conditional blocks.
The if control structures evaluate pipelines, not just values (values are a special case of a pipeline):
{{ if PIPELINE }}
# Do something
{{ else if OTHER_PIPELINE }}
# Do something else
{{ else }}
# Default case
{{ end }}
A pipeline evaluates to false
if the result of the pipeline, or the value, is:
- a boolean false
- a numeric zero
- an empty string
- a
nil
(empty or null) - an empty collection (map, slice, tuple, dict, array).
In any other case, the condition is evaluated to true.
Example:
{{ if .Values.debug }}
# Do something
{{ else }}
# Do something else
{{ end }}
Expression
Testing the Existence of Two Configuration Elements in the Same Expression
{{- if or .Values.myApp.config.local .Values.myApp.config.nfs }}
...
{{- end }}
Testing the Non-Existence of a Configuration Element
The following conditional evaluates to true and the embedded content is rendered if the configuration element does NOT exist:
{{- if not .Values.myApp.something }}
...
{{- end }}
Testing Equality and Inequality of Values
{{- if eq .Values.myApp.color "blue" }}
...
{{- end }}
{{- if not eq .Values.myApp.color "blue" }}
...
{{- end }}
{{- if eq .Values.myApp.something .Values.myApp.somethingElse }}
...
{{- end }}