Anders Martini
Anders Martini

Reputation: 948

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.

Upvotes: 17

Views: 35779

Answers (1)

Jo&#227;o Antunes
Jo&#227;o Antunes

Reputation: 571

You can use the has function from the sprig functions library which is used by Helm. In your case should be something like this:

{{if has .Release.Namespace .Values.Namespaces }}
   <chart goes here>
{{ end }}

Upvotes: 31

Related Questions