HELM: How to convert a string into lower/upper case inside if-else condition?

Viewed 4367

Use case: I have values.yaml where I have a field mode.

Values.yaml

mode: start

or user can enter a value for the field mode in any of the below mentioned ways:

mode: STart or START or sTart

Now, I have a file where I am using an if condition as shown below:

command: {{ if eq .Values.mode "start" }} do this {{ esle }} do that {{ end }}

Now, my challenge is how can I covert the ".Values.mode" into lower alphabets before doing the comparison. I have tried the below mentioned ways:

1.

{{ if eq .Values.mode | lower "start" }} do this {{ esle }} do that {{ end }}
{{ if eq lower .Values.mode "start" }} do this {{ esle }} do that {{ end }}

Both of the above methods errored out.

Note: we are using a third-party tool, hence JSON schema check won't help me.

1 Answers

lower is a function handed to you in the templates. It has a return value, which you wish to compare to another value.

Simply group the function call of lower with parenthesis:

{{ if eq "start" (lower .Values.mode) }} do this {{ else }} do that {{ end }}
Related