Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if list contains item in Helm chart

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.

like image 243
Anders Martini Avatar asked Oct 25 '18 11:10

Anders Martini


People also ask

What does {{ }} mean 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.

What is trunc 63 in Helm?

trunc 63 truncates it to 63 characters in length. trimSuffix "-" removes ONE trailing - if one exists.

What is $_ in Helm?

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) . -}}


1 Answers

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 }}
like image 130
João Antunes Avatar answered Oct 17 '22 03:10

João Antunes