diff --git a/pkg/resourcegenerator/job/job.go b/pkg/resourcegenerator/job/job.go index 16f1589e..fe44342e 100644 --- a/pkg/resourcegenerator/job/job.go +++ b/pkg/resourcegenerator/job/job.go @@ -119,5 +119,9 @@ func getJobSpec(skipJob *skiperatorv1alpha1.SKIPJob, selector *metav1.LabelSelec Suspend: skipJob.Spec.Job.Suspend, } + // it's not a default label, maybe it could be? + // used for selecting workloads by netpols, grafana etc + jobSpec.Template.Labels["app"] = skipJob.KindPostFixedName() + return jobSpec } diff --git a/tests/skipjob/minimal-cron-job/skipjob-assert.yaml b/tests/skipjob/minimal-cron-job/skipjob-assert.yaml index 479fe19e..e0a494b6 100644 --- a/tests/skipjob/minimal-cron-job/skipjob-assert.yaml +++ b/tests/skipjob/minimal-cron-job/skipjob-assert.yaml @@ -13,7 +13,6 @@ kind: CronJob metadata: name: minimal-cron-job labels: - app: minimal-cron-job-skipjob skiperator.kartverket.no/skipjob: "true" skiperator.kartverket.no/skipjobName: minimal-cron-job app.kubernetes.io/managed-by: "skiperator" @@ -31,9 +30,33 @@ spec: successfulJobsHistoryLimit: 3 failedJobsHistoryLimit: 1 jobTemplate: + metadata: + labels: + skiperator.kartverket.no/skipjob: "true" + skiperator.kartverket.no/skipjobName: minimal-cron-job + app.kubernetes.io/managed-by: "skiperator" + skiperator.kartverket.no/controller: "skipjob" spec: template: + metadata: + labels: + app: minimal-cron-job-skipjob spec: containers: - name: minimal-cron-job-skipjob image: "perl:5.34.0" +--- +apiVersion: v1 +kind: Pod +metadata: + labels: + app: minimal-cron-job-skipjob + app.kubernetes.io/managed-by: skiperator + skiperator.kartverket.no/controller: skipjob + skiperator.kartverket.no/skipjob: 'true' + skiperator.kartverket.no/skipjobName: minimal-cron-job + ownerReferences: + - apiVersion: batch/v1 + kind: Job + controller: true + blockOwnerDeletion: true diff --git a/tests/skipjob/minimal-job/skipjob-assert.yaml b/tests/skipjob/minimal-job/skipjob-assert.yaml index c519a607..4e012cbe 100644 --- a/tests/skipjob/minimal-job/skipjob-assert.yaml +++ b/tests/skipjob/minimal-job/skipjob-assert.yaml @@ -8,7 +8,6 @@ kind: Job metadata: name: minimal-job labels: - app: minimal-job-skipjob skiperator.kartverket.no/skipjob: "true" skiperator.kartverket.no/skipjobName: minimal-job app.kubernetes.io/managed-by: "skiperator" @@ -22,6 +21,7 @@ spec: metadata: labels: job-name: minimal-job + app: minimal-job-skipjob skiperator.kartverket.no/skipjob: "true" skiperator.kartverket.no/skipjobName: minimal-job app.kubernetes.io/managed-by: "skiperator" @@ -50,3 +50,19 @@ spec: seccompProfile: type: RuntimeDefault serviceAccountName: minimal-job-skipjob +--- +apiVersion: v1 +kind: Pod +metadata: + labels: + app: minimal-job-skipjob + app.kubernetes.io/managed-by: skiperator + batch.kubernetes.io/job-name: minimal-job + job-name: minimal-job + skiperator.kartverket.no/controller: skipjob + skiperator.kartverket.no/skipjob: 'true' + skiperator.kartverket.no/skipjobName: minimal-job + ownerReferences: + - apiVersion: batch/v1 + kind: Job + name: minimal-job