<p>Is it possible, within a <a href="/questions/tagged/helm" class="post-tag" title="show questions tagged &#39;helm&#39;" rel="tag">helm</a> chart to create a single string which is a comma-separated representation (similar to using the <code>",".join()</code> command in Python) of strings with a common prefix and a variable suffix?</p>

<p>For example, I have a CLI application that requires an argument like so via the <code>extraArgs</code> parameter in a <a href="/questions/tagged/kubernetes" class="post-tag" title="show questions tagged &#39;kubernetes&#39;" rel="tag">kubernetes</a> pod definition:</p>

<pre><code>extraArgs: &gt;-
  -M {{ $.Values.global.hostname }}/100
</code></pre>

<p>I now have to modify this value to be over a range (i.e. from <code>{{$.Values.global.minval}}</code> to <code>{{$.Values.global.maxval}}</code>, inclusive). So, for a <code>minval=100</code> and <code>maxval=105</code>, my chart needs to now become (note the lack of a trailing comma, and no spaces other than the space after <code>-M</code>):</p>

<pre><code>extraArgs: &gt;-
  -M {{ $.Values.global.hostname }}/100,{{ $.Values.global.hostname }}/101,{{ $.Values.global.hostname }}/102,{{ $.Values.global.hostname }}/103,{{ $.Values.global.hostname }}/104,{{ $.Values.global.hostname }}/105
</code></pre>

<p>Is there some way I can execute this in a range/loop in my chart? I have several instances of this chart that will use different min/max values, and I'd like to automate this tedious task as much as I can (additionally, I <strong>do not</strong> have access to the app's source, so I can't change the CLI interface to the application).</p>

<p>In Python, I could accomplish this roughly by:</p>

<pre><code>minval = 100
minval = 105
s = "-M "
L = []
for i in range(minval, maxval+1):
    L.append("{{{{ $.Values.global.hostname }}}}/{}".format(i))
s = s + ",".join(L)
# print(s)
</code></pre>

<p>I'm not sure where to begin doing this in a Helm template beyond starting with the <code>range()</code> function.</p>

<p>Helm includes the <a href="https://masterminds.github.io/sprig" rel="nofollow noreferrer">sprig library</a> of template functions which contains <a href="https://masterminds.github.io/sprig/integer_slice.html" rel="nofollow noreferrer"><code>untilStep</code></a> and <a href="https://masterminds.github.io/sprig/string_slice.html" rel="nofollow noreferrer"><code>join</code></a>. </p>

<p>There is no concept of a <a href="https://github.com/Masterminds/sprig/issues/91" rel="nofollow noreferrer"><code>map</code> or <code>each</code> operator in sprig</a> yet so you can construct the list in a <code>range</code> loop to be joined later (<a href="https://stackoverflow.com/a/59173597/1318694">from here</a>)</p>

<pre><code>{{- $minval :=  int .Values.minval -}}
{{- $maxval :=  int .Values.maxval | add1 | int -}}
{{- $args := list -}}
{{- range untilStep $minval $maxval 1 -}}
{{-   $args = printf "%s/%d" $hostname . | append $args -}}
{{- end }}
extraArgs: '-M {{ $args | join "," }}'
</code></pre>
