Can we use OR operator in Helm yaml files

Solution 1:

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 }}

Solution 2:

Note that or can also be used instead of default like this:

{{ or .Values.someSetting "dafault_value" }}

This would render to .Values.someSetting if it is set or to "dafault_value" otherwise.