I have a chart that I want to deploy if a certain value is in a list of values. I've tried the following
{{if .Release.Namespace in .Values.Namespaces }}
<chart goes here>
{{ end }}
where the values file used contains the following
Namespaces:
-value1
-value2
but i get an error function "in" not defined
Searching the interwebs I've been unable to find what the proper syntax is for checking if a value exists in a list in helm.
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.
trunc 63 truncates it to 63 characters in length. trimSuffix "-" removes ONE trailing - if one exists.
The $_ is used to suppress undesired output as "set" returns the new dictionary. The above returns: - name: mongod-none. Any values added to the dictionary will live beyond the call. If you want to avoid polluting an existing dictionary you can force a deep copy with: {{- $d := merge (dict) . -}}
You can use the has
function from the sprig functions library which is used by Helm. Please note however that there's an issue with the documentation of the function (the order of the parameters is wrong). In your case should be something like this:
{{if has .Release.Namespace .Values.Namespaces }}
<chart goes here>
{{ end }}
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