How can I check if a variable is a boolean value "true" in helm chart? I have in Values.yaml a parameter set as:
myParameter: true
I don't understand well difference between:
{{- if .Values.service.myParameter }}
and
{{- if eq .Values.service.myParameter "true" }}
I want that flow goes in if clause if the parameter is set as boolean "true"
The documentation for the Go text/template
package explains what the if
statement considers as "true":
The empty ["false"] values are false, 0, any nil pointer or interface value, and any array, slice, map, or string of length zero.
YAML values are typed and the usual rules are that bare true
and false
are booleans:
boolean: true
string: other text, but not "true", "false", or "null"
also a string: 'true'
In your examples:
{{- if .Values.service.myParameter }}...{{ end }}
will evaluate to true whenever myParameter
exists (isn't Go nil
) and isn't zero, literal false
, or an empty string.
{{- if eq .Values.service.myParameter "true" }}...{{ end }}
will evaluate to true whenever myParameter
is exactly the string "true"
, but not a boolean true
. (I think you will get a type error from the template engine if it's a boolean, in fact.)
You can use the following snipped for checking the boolean value
{{if (default .Values.seLinux true)}}
securityContext:
seLinuxOptions:
user: system_u
{{ end }}
Then the Values file will have following snippet
seLinux: true
Please let me know if this helps.
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