Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding news lines when defining collection

I am trying to define a collection (dict), and I would like to add a new line on each definition (for readability), Eg:

{{ $deployment := dict 
"Release" .Release 
"Chart" .Chart 
"Values" .Values }}

But when I do this, helm respond a parse error :

Error: parse error in "XXX": template: XXX:2: unclosed action
Error: UPGRADE FAILED: parse error in "XXX": template: XXX:2: unclosed action

Is there a way in HELM to do this?

like image 753
Ngob Avatar asked Oct 19 '25 08:10

Ngob


1 Answers

I achieved this by defining the dict first and then setting one key per line.

{{- $myDict := dict "" "" -}}
{{- $_ := set $myDict "myKey1" "myValue1" -}}
{{- $_ := set $myDict "myKey2" "myValue2" -}}
{{- $_ := set $myDict "myKey3" "myValue3" -}}
{{- $_ := set $myDict "myKey4" "myValue4" -}}

Bonus Tip: Since dict get function is available seemingly in only helm3 and later, you can use this hack to get a value from a dict to a string.

{{/* Hack needed until helm 3 which has 'get' for 'dict' */}}
{{- $myValue3Var := pluck "myKey3" $myDict | first -}}
like image 106
yosefrow Avatar answered Oct 20 '25 21:10

yosefrow