In some of the examples I am following, I see, for a string value, I can do this:
{{- with .Values.cookieDomain }}
- --cookieDomain={{- toString . }}
{{- end }}
with this, if I have, e.g. cookieDomain: .mydomain.com in the values.yaml, the template gets the correct value.
How to do the same/similar for boolean values?
For example, if I have this: proxyPass: true in values.yaml, how do I interpret that in template, as there is no toBool function.
The function toString, in your example, is actually moot, if the value contained in cookieDoman is already a string it will just do nothing.
What you have to understand in with .Values.cookieDoman is that the context has now changed from . being the root of the variables definition to being .Values.cookieDoman.
A little like doing a change of directory in a computer, if I cd /tmp, then ./some_file looks for a file in /tmp/some_file. Now if I cd /etc, the same command, ./some_file, will now look for a file /etc/some_file.
This controls variable scoping. Recall that
.is a reference to the current scope. So.Valuestells the template to find theValuesobject in the current scope.
Source: https://helm.sh/docs/chart_template_guide/control_structures/#modifying-scope-using-with
So, in your example, it is fine enough already to do
flags:
{{- with .Values.cookieDomain }}
- --cookieDomain={{- . }}
{{- end }}
This will renders in
flags:
- --cookieDomain=.mydomain.com
And, so, if you have a boolean, it is the exact same:
flags:
{{- with .Values.proxyPass }}
- --proxyPass={{- . }}
{{- end }}
Will give:
flags:
- --proxyPass=true
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