diff --git a/resource_customizations/batch/CronJob/actions/create-job/action.lua b/resource_customizations/batch/CronJob/actions/create-job/action.lua index 119e0d35eccb6..17b6455fa3d5d 100644 --- a/resource_customizations/batch/CronJob/actions/create-job/action.lua +++ b/resource_customizations/batch/CronJob/actions/create-job/action.lua @@ -32,7 +32,10 @@ job = {} job.apiVersion = "batch/v1" job.kind = "Job" -job.metadata = {} +job.metadata = deepCopy(obj.spec.jobTemplate.metadata) +if job.metadata == nil then + job.metadata = {} +end job.metadata.name = obj.metadata.name .. "-" ..os.date("!%Y%m%d%H%M") job.metadata.namespace = obj.metadata.namespace @@ -47,6 +50,7 @@ job.metadata.ownerReferences[1] = ownerRef job.spec = {} job.spec.suspend = false job.spec.template = {} +job.spec.template.metadata = deepCopy(obj.spec.jobTemplate.spec.template.metadata) job.spec.template.spec = deepCopy(obj.spec.jobTemplate.spec.template.spec) impactedResource = {} diff --git a/resource_customizations/batch/CronJob/actions/testdata/cronjob.yaml b/resource_customizations/batch/CronJob/actions/testdata/cronjob.yaml index 118fc83929e96..d422c82da393a 100644 --- a/resource_customizations/batch/CronJob/actions/testdata/cronjob.yaml +++ b/resource_customizations/batch/CronJob/actions/testdata/cronjob.yaml @@ -7,8 +7,18 @@ metadata: spec: schedule: "* * * * *" jobTemplate: + metadata: + labels: + my: label + annotations: + my: annotation spec: template: + metadata: + labels: + pod: label + annotations: + pod: annotation spec: containers: - name: hello diff --git a/resource_customizations/batch/CronJob/actions/testdata/job.yaml b/resource_customizations/batch/CronJob/actions/testdata/job.yaml index cf0f92da24818..16d4e4960b0dc 100644 --- a/resource_customizations/batch/CronJob/actions/testdata/job.yaml +++ b/resource_customizations/batch/CronJob/actions/testdata/job.yaml @@ -5,8 +5,17 @@ metadata: name: hello-00000000000 namespace: test-ns + labels: + my: label + annotations: + my: annotation spec: template: + metadata: + labels: + pod: label + annotations: + pod: annotation spec: containers: - name: hello