<p>I am trying to deploy multiple cronjob using same helm chart. I have defined cronjobs in values.yaml file which is below.</p>
<pre><code>cronjob:
  crons:
    &quot;0&quot;:
    name: one-minute-cron
    schedule: &quot;*/1 * * * *&quot;
    &quot;1&quot;:
    name: five-minute-cron
    schedule: &quot;*/5 * * * *&quot;

  metadata:
    namespace: &quot;{{K8S_NS}}&quot;
    creationTimestamp: null

  restartPolicy: OnFailure

  image:
    repository: &quot;{{CI_REGISTRY_IMAGE}}/{{CI_COMMIT_REF_SLUG}}:{{CI_COMMIT_SHA}}.{{CI_PIPELINE_IID}}&quot;
    pullPolicy: &quot;Always&quot;
    imagePullSecrets: git-image-pull-secret-cron
    restartPolicy: OnFailure

  resources:
    requests:
      cpu: 1.0
      memory: &quot;128Mi&quot;
    limits:
      cpu: 2.0
      memory: &quot;192Mi&quot;
</code></pre>
<p>Below is my cronjob.yaml file from templates folder.</p>
<pre><code>{{- range $job, $val := .Values.cronjob.crons }}
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  namespace: {{ $.Values.cronjob.metadata.namespace }}
spec:
  concurrencyPolicy: Allow
  failedJobsHistoryLimit: 1
  jobTemplate:
    metadata:
      creationTimestamp: {{ $.Values.cronjob.metadata.creationTimestamp }}
      name: {{ $.Values.cronjob.crons.name }}
    spec:
      template:
        metadata:
          creationTimestamp: {{ $.Values.cronjob.metadata.creationTimestamp }}
        spec:
          containers:
          - image: {{ $.Values.cronjob.image.repository }}
            imagePullPolicy: {{ $.Values.cronjob.image.pullPolicy }}
            name: {{ $.Values.cronjob.crons.name }}
            resources:
              requests:
                memory: {{ $.Values.cronjob.resources.requests.memory }}
                cpu: {{ $.Values.cronjob.resources.requests.cpu }}
              limits:
                memory: {{ $.Values.cronjob.resources.limits.memory }}
                cpu: {{ $.Values.cronjob.resources.limits.cpu }}

          dnsPolicy: ClusterFirst
          restartPolicy: {{ $.Values.cronjob.image.restartPolicy }}
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
          imagePullSecrets:
            - name: {{ $.Values.cronjob.image.imagePullSecrets }}
  schedule: {{ quote $.Values.cronjob.crons.schedule }}
  successfulJobsHistoryLimit: 3
  suspend: false
status: {}
---
{{- end }}
</code></pre>
<p>When I run this in CICD pipeline for deployment in gitlab it throws below error.</p>
<pre><code>Error: UPGRADE FAILED: error validating &quot;&quot;: error validating data: [ValidationError(CronJob.spec.jobTemplate.spec.template.spec.containers[0]): missing required field &quot;name&quot; in io.k8s.api.core.v1.Container, ValidationError(CronJob.spec): missing required field &quot;schedule&quot; in io.k8s.api.batch.v1beta1.CronJobSpec]
</code></pre>
<p>Note: I have copied the whole repository from gitlab except the sensitive information such as gitlab secrets, templates. I have checked the other blogs as well for this but none of them are helping to get these crons working. Github repo link is <a href="https://github.com/shaileshsutar88/helm-multiple-cron" rel="nofollow noreferrer">here</a></p>

Shailesh Sutar
<p>First,
I think that <code>cronjob.crons</code> should be an array. Try changing it to:</p>
<pre><code>cronjob:
  crons:
    - id: &quot;0&quot;
      name: &quot;one-minute-cron&quot;
      schedule: &quot;*/1 * * * *&quot;
    - id: &quot;1&quot;
      name: five-minute-cron
      schedule: &quot;*/5 * * * *&quot;
</code></pre>
<p>Then you can iterate over &quot;crons&quot; via:</p>
<pre><code>{{- range $cron := .Values.cronjob.crons }}
</code></pre>
<p>You can then access the &quot;cron&quot; fields like so:</p>
<pre><code>...
imagePullPolicy: {{ $.Values.cronjob.image.pullPolicy }}
name: {{ $cron.name }}
</code></pre>
