<p>I am trying to patch a cronjob, but somehow it doesn't work as I would expect. I use the same folder structure for a deployment and that works.</p>
<p>This is the folder structure:</p>
<pre class="lang-sh prettyprint-override"><code>.
├── base
│   ├── kustomization.yaml
│   └── war.cron.yaml
└── overlays
    └── staging
        ├── kustomization.yaml
        ├── war.cron.patch.yaml
        └── war.cron.staging.env
</code></pre>
<p>base/kustomization.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>---
kind: Kustomization
resources:
- war.cron.yaml
</code></pre>
<p>base/war.cron.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: war-event-cron
spec:
  schedule: &quot;*/5 * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: war-event-cron
            image: my-registry/war-service
            imagePullPolicy: IfNotPresent
            command:
            - python
            - run.py
            args:
            - sync-events
            envFrom:
            - secretRef:
                name: war-event-cron-secret
          restartPolicy: OnFailure
</code></pre>
<p>Then I am trying to patch this in the staging overlay.</p>
<p>overlays/staging/kustomization.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>---
kind: Kustomization
namespace: staging
bases:
- &quot;../../base&quot;
patchesStrategicMerge:
- war.cron.patch.yaml
secretGenerator:
- name: war-event-cron-secret
  behavior: create
  envs:
  - war.cron.staging.env
</code></pre>
<p>overlays/staging/war.cron.patch.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: war-event-cron
spec:
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: war-event-cron
            image: my-registry/war-service:nightly
            args:
            - sync-events
            - --debug
</code></pre>
<p>But the result of <code>kustomize build overlays/staging/</code> is not what I want. The <code>command</code> is gone and the <code>secret</code> is not referenced.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
data:
  ...
kind: Secret
metadata:
  name: war-event-cron-secret-d8m6bh7284
  namespace: staging
type: Opaque
---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: war-event-cron
  namespace: staging
spec:
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - args:
            - sync-events
            - --debug
            image: my-registry/war-service:nightly
            name: war-event-cron
          restartPolicy: OnFailure
  schedule: '*/5 * * * *'
</code></pre>

The Fool
<p>It's known bug in <code>kustomize</code> - check and follow <a href="https://github.com/kubernetes-sigs/kustomize/issues/4062" rel="nofollow noreferrer">this</a> topic (created ~ one month ago) on GitHub for more information.</p>
<p>For now, fix for your issue is to use <code>apiVersion:batch/v1beta1</code> instead of <code>apiVersion: batch/v1</code> in <code>base/war.cron.yaml</code> and <code>overlays/staging/war.cron.patch.yaml</code> files.</p>
