Helm simple for loop

12/29/2018

I can not find a way to just iterate over a simple range, 10 -> 20 using helm templating.

{{range 10 until 20 }}
    - port: {{ . }}
      targetPort: {{ . }}
      protocol: TCP
      name: brick-{{ . }}
{{end}}
-- Greg
kubernetes-helm

1 Answer

12/29/2018

Helm uses the standard Go text/template system for rendering templates, plus (most of) the Sprig extension library, plus a couple more things. In particular, Sprig includes until and untilStep functions to generate lists of numbers, which you can then range over. So you should be able to:

{{- range untilStep 10 20 1 }}
    - port: {{ . }}
      ...
{{- end }}
-- David Maze
Source: StackOverflow