<p>I have a cron file and i am trying to pass it thru <code>--set-file</code> option.
I want to loop thru the cron file lines and create for each line new Kubernetes Object of kind CronJob.</p>

<p>I used it like this <code>helm instal ... --set-file crons.file=mycron</code></p>

<p>where mycron file looks like a typical cron file:</p>

<pre><code>0,10,20,30,40,50 * * * * /usr/bin/cmd1 opta optb
35 2-23/3 * * * /usr/bin/cmd2
</code></pre>

<p>i am not able to iterate thru lines of this simple plain text : </p>

<pre><code>{{- range $indx, $line := .Values.crons.file }}
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: {{ regexFind "[^/]+$" "$line"}}
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: cron-{{ $indx }}
            image: busybox
            args: 
            - /bin/sh
            - -c
            - {{ regexFind "[^/]+$" "$line"}}
          restartPolicy: OnFailure
{{- end  }}
</code></pre>

<p>Is there a function like <code>fromYaml</code> which makes a plain text file iterable by <code>range</code> function ?</p>

Abdennour TOUMI
<p>The <a href="http://masterminds.github.io/sprig/" rel="noreferrer">Sprig</a> support library includes functions for <a href="http://masterminds.github.io/sprig/string_slice.html" rel="noreferrer">splitting and joining strings into lists</a>, and for <a href="http://masterminds.github.io/sprig/lists.html" rel="noreferrer">manipulating lists in general</a>.  If <code>splitList</code> the file on newlines, you'll get a list of lines.  You can again <code>splitList</code> each line on spaces to get the separate time and command parts out of the individual cron lines.</p>

<pre><code>{{/* Iterate over individual lines in the string */}}
{{- range $line := splitList "\n" .Values.crons.file -}}

{{/* Break the line into words */}}
{{- $words := splitList " " $line -}}

{{/* Reconstitute the schedule and command parts from the words */}}
{{- $time := slice $words 0 5 | join " " -}}
{{- $command := slice $words 5 -}}

---
schedule: {{ $time }}
command: {{- $command | toYaml | nindent 2}}
{{ end -}}
</code></pre>
