Can we use OR operator in Helm yaml files

4/12/2018

Can I do something like this in Helm yamls :

{{- if eq .Values.isCar true }} OR {{- if eq .Values.isBus true }}
# do something
{{- end }}

I understand that we can do a single if check. But how would I check for multiple conditions? Are there some operators equivalent to OR and AND?

-- James Isaac
kubernetes-helm

1 Answer

4/13/2018

As indicated in the Helm documentation on operators:

For templates, the operators (eq, ne, lt, gt, and, or and so on) are all implemented as functions. In pipelines, operations can be grouped with parentheses ((, and )).

It means you could use

{{- if or (eq .Values.isCar true) (eq .Values.isBus true) }}

Furthermore, as noted in the if/else structure:

A pipeline is evaluated as false if 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)

Under all other conditions, the condition is true.

If your properties (isCar and isBus) are booleans, you can then skip the equal check:

{{- if or .Values.isCar .Values.isBus }}
-- ykweyer
Source: StackOverflow