Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no "break" support for flow control methods in helm template

I have a range function but would like to break from the control if certain condition is met. Is there a way this can be achieved in helm template

UPDATE:

I have seen some related queries where conclusion is "break" is unsupported. But would like to get some official documentation OR reason in case this is not supported.

like image 996
ambikanair Avatar asked Sep 03 '25 13:09

ambikanair


1 Answers

Have some good news here! Not sure from which exact version of helm the update happened but you can for sure use the break in your templates with the newest [email protected].

This is because the new version of helm bumped the go version to 1.20 and the break has been introduced in the text/template in go v1.18.

So now you can do stuff like this:

  {{- range $i, $e := until 10 -}}
    {{- if lt $i 5 -}}
      Less than five.
    {{- else -}}
      {{- break -}}
    {{- end -}}
  {{- end -}}

Happy helming!

like image 193
Mr.Coffee Avatar answered Sep 05 '25 17:09

Mr.Coffee