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?
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 ) ).
The Helm template syntax is based on the Go programming language's text/template package. The braces {{ and }} are the opening and closing brackets to enter and exit template logic.
You can use the helm native commands to achieve this. In helm, there is a command called helm template . Using the template command you can convert any helm chart to a YAML manifest. The resultant manifest file will have all the default values set in the helm values.
What are Helm charts? Helm Charts are simply Kubernetes YAML manifests combined into a single package that can be advertised to your Kubernetes clusters.
As indicated in the Helm documentation on operators:
For templates, the operators (
eq,ne,lt,gt,and,orand 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 }}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With