Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have Helm ternary operator return arbitrary value instead of just True / False

I've made the use of helm ternary operator and I think it's pretty need, but it seems to be only able to return boolean values. Can I have it return any arbitrary value instead of just true or false?

This works as expected

sharedVPC: {{ true | (eq .Values.global.hyperscaler "gcp") false | quote }}

I would love to be able to do something like this

reclaimJobHours: {{ ternary (eq .Values.global.hyperscaler "aws") "36" "34" }}
like image 538
JonB Avatar asked Jan 26 '23 01:01

JonB


1 Answers

From sprig functions

The ternary function takes two values, and a test value. If the test value is true, the first value will be returned. If the test value is empty, the second value will be returned. This is similar to the c ternary operator.

{{ ternary "36" "34" (eq .Values.global.hyperscaler "aws")}}

The following expression will return 36 if global.hyperscaler is aws and 34 in all other cases.

like image 82
edbighead Avatar answered Apr 05 '23 20:04

edbighead