Skip to content

Commit 5eaf2ef

Browse files
Add OwnerReference to generated Jobs
1 parent be15d33 commit 5eaf2ef

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

internal/pkg/callbacks/rolling_upgrade.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,15 @@ func UpdateDeployment(clients kube.Clients, namespace string, resource runtime.O
339339
func CreateJobFromCronjob(clients kube.Clients, namespace string, resource runtime.Object) error {
340340
cronJob := resource.(*batchv1.CronJob)
341341
job := &batchv1.Job{
342-
ObjectMeta: cronJob.Spec.JobTemplate.ObjectMeta,
343-
Spec: cronJob.Spec.JobTemplate.Spec,
342+
ObjectMeta: meta_v1.ObjectMeta{
343+
GenerateName: cronJob.Name + "-",
344+
Namespace: cronJob.Namespace,
345+
Annotations: cronJob.Spec.JobTemplate.Annotations,
346+
Labels: cronJob.Spec.JobTemplate.Labels,
347+
OwnerReferences: []meta_v1.OwnerReference{*meta_v1.NewControllerRef(cronJob, batchv1.SchemeGroupVersion.WithKind("CronJob"))},
348+
},
349+
Spec: cronJob.Spec.JobTemplate.Spec,
344350
}
345-
job.GenerateName = cronJob.Name + "-"
346351
_, err := clients.KubernetesClient.BatchV1().Jobs(namespace).Create(context.TODO(), job, meta_v1.CreateOptions{FieldManager: "Reloader"})
347352
return err
348353
}

0 commit comments

Comments
 (0)