From bb34d19eeb8c676b845781e9f561a3b7df0ed813 Mon Sep 17 00:00:00 2001 From: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Date: Tue, 11 Jul 2023 12:04:40 +0000 Subject: [PATCH] fix(action): copy metadata on create-job action (#14232) (#14233) Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> --- .../batch/CronJob/actions/create-job/action.lua | 6 +++++- .../batch/CronJob/actions/testdata/cronjob.yaml | 10 ++++++++++ .../batch/CronJob/actions/testdata/job.yaml | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) 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