Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to substitute Boolean value from values.yaml

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.

like image 230
MacUsers Avatar asked Apr 28 '26 05:04

MacUsers


1 Answers

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 .Values tells the template to find the Values object 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
like image 134
β.εηοιτ.βε Avatar answered May 04 '26 04:05

β.εηοιτ.βε



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!