<p>Right now, I have a values.yaml with a section that looks a bit like this:</p>
<pre><code>...
imageName:
  ports:
    - containerPort: 7980
      name: db0
      protocol: TCP
    - containerPort: 7981
      name: db1
      protocol: TCP
    - containerPort: 7982
      name: db2
      protocol: TCP
    - containerPort: 7983
      name: db3
      protocol: TCP
    - containerPort: 7984
      name: db4
      protocol: TCP
    - containerPort: 7985
      name: db5
      protocol: TCP
    - containerPort: 7986
      name: db6
      protocol: TCP
    - containerPort: 7987
      name: db7
      protocol: TCP
    - containerPort: 7988
      name: db8
      protocol: TCP
    - containerPort: 7989
      name: db9
      protocol: TCP
    - containerPort: 7990
      name: db10
      protocol: TCP
...
</code></pre>
<p>I'd like to clean this up by creating a function in _helpers.tpl that will take the min port value (7980) and the max port value (7990) and create the structure for each one in that format.</p>
<p>I am wondering: Is this possible? I am having a lot of trouble with this and using the helpers file in general so if anyone can nudge me in the right direction with how to accomplish this, I would appreciate that too!</p>
<p>Thanks :)</p>

<p>This should be possible.  Say you configure your chart with the number of ports and the starting port:</p>
<pre class="lang-yaml prettyprint-override"><code># values.yaml (or a `helm install -f` values file)
numberOfPorts: 11
startingPort: 7980
</code></pre>
<p>You can use the <a href="https://docs.helm.sh/docs/chart_template_guide/function_list/#until" rel="noreferrer"><code>until</code> template function</a> to turn that into a list of numbers:</p>
<pre class="lang-yaml prettyprint-override"><code>{{- $dbs := until .Values.numberOfPorts }}
</code></pre>
<p>Now you can use the standard <code>range</code> function to loop over that list.  Inside the loop body the value will be an integer from 0 to <code>numberOfPorts - 1</code> and you can produce the list item accordingly.  Also note that <code>range</code> takes over the <code>.</code> special variable, so you'll need to save anything you need from <code>.Values</code> outside the <code>range</code> loop.</p>
<pre class="lang-yaml prettyprint-override"><code>imageName:
  ports:
{{- $startingPort := .Values.startingPort }}
{{- range $i := until .Values.numberOfPorts }}
    - containerPort: {{ add $startingPort $i }}
      name: db{{ $i }}
      protocol: TCP
{{- end }}
</code></pre>
