<p>I'm trying to apply the same job history limits to a number of CronJobs using a <a href="https://github.com/kubernetes-sigs/kustomize/blob/572d5841c60b9a4db1a75443b8badb7e8334f727/examples/patchMultipleObjects.md" rel="nofollow noreferrer">patch</a> like the following, named <code>kubeJobHistoryLimit.yml</code>:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: batch/v1beta1
kind: CronJob
spec:
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
</code></pre>
<p>My <code>kustomization.yml</code> looks like:</p>
<pre class="lang-yaml prettyprint-override"><code>bases:
  - ../base
configMapGenerator:
- name: inductions-config
  env: config.properties
patches:
  - path: kubeJobHistoryLimit.yml
    target:
      kind: CronJob
patchesStrategicMerge:
  - job_specific_patch_1.yml
  - job_specific_patch_2.yml
  ...
resources:
  - secrets-uat.yml
</code></pre>
<p>And at some point in my CI pipeline I have:</p>
<pre><code>kubectl --kubeconfig $kubeconfig apply --force -k ./
</code></pre>
<p>The <code>kubectl</code> version is <code>1.21.9</code>.</p>
<p>The issue is that the job history limit values don't seem to be getting picked up. Is there something wrong w/ the configuration or the version of K8s I'm using?</p>

Tianxiang Xiong
<p>With kustomize 4.5.2, your patch as written doesn't apply; it fails with:</p>
<pre><code>Error: trouble configuring builtin PatchTransformer with config: `
path: kubeJobHistoryLimit.yml
target:
  kind: CronJob
`: unable to parse SM or JSON patch from [apiVersion: batch/v1
kind: CronJob
spec:
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
]
</code></pre>
<p>This is because it's missing <code>metadata.name</code>, which is required, even if it's ignored when patching multiple objects. If I modify the patch to look like this:</p>
<pre><code>apiVersion: batch/v1
kind: CronJob
metadata:
  name: ignored
spec:
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
</code></pre>
<p>It seems to work.</p>
<p>If I have <code>base/cronjob1.yaml</code> that looks like:</p>
<pre><code>apiVersion: batch/v1
kind: CronJob
metadata:
  name: cronjob1
spec:
  failedJobsHistoryLimit: 2
  successfulJobsHistoryLimit: 5
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - command:
            - sleep
            - 60
            image: docker.io/alpine:latest
            name: example
  schedule: 30 3 * * *
</code></pre>
<p>Then using the above patch and a <code>overlay/kustomization.yaml</code> like this:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
patches:
- path: kubeJobHistoryLimit.yml
  target:
    kind: CronJob
</code></pre>
<p>I see the following output from <code>kustomize build overlay</code>:</p>
<pre><code>apiVersion: batch/v1
kind: CronJob
metadata:
  name: cronjob2
spec:
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - command:
            - sleep
            - 60
            image: docker.io/alpine:latest
            name: example
  schedule: 30 3 * * *
  successfulJobsHistoryLimit: 1
</code></pre>
<p>You can see the two attributes have been updated correctly.</p>
