@@ -35,6 +35,7 @@ import (
35
35
"k8s.io/kubectl/pkg/util"
36
36
"k8s.io/kubectl/pkg/util/i18n"
37
37
"k8s.io/kubectl/pkg/util/templates"
38
+ "k8s.io/utils/ptr"
38
39
)
39
40
40
41
var (
@@ -261,10 +262,21 @@ func (o *CreateJobOptions) createJobFromCronJob(cronJob *batchv1.CronJob) *batch
261
262
// this is ok because we know exactly how we want to be serialized
262
263
TypeMeta : metav1.TypeMeta {APIVersion : batchv1 .SchemeGroupVersion .String (), Kind : "Job" },
263
264
ObjectMeta : metav1.ObjectMeta {
264
- Name : o .Name ,
265
- Annotations : annotations ,
266
- Labels : cronJob .Spec .JobTemplate .Labels ,
267
- OwnerReferences : []metav1.OwnerReference {* metav1 .NewControllerRef (cronJob , batchv1 .SchemeGroupVersion .WithKind ("CronJob" ))},
265
+ Name : o .Name ,
266
+ Annotations : annotations ,
267
+ Labels : cronJob .Spec .JobTemplate .Labels ,
268
+ OwnerReferences : []metav1.OwnerReference {
269
+ {
270
+ // we are not using metav1.NewControllerRef because it
271
+ // sets BlockOwnerDeletion to true which additionally mandates
272
+ // cronjobs/finalizer role and not backwards-compatible.
273
+ APIVersion : batchv1 .SchemeGroupVersion .String (),
274
+ Kind : "CronJob" ,
275
+ Name : cronJob .GetName (),
276
+ UID : cronJob .GetUID (),
277
+ Controller : ptr .To (true ),
278
+ },
279
+ },
268
280
},
269
281
Spec : cronJob .Spec .JobTemplate .Spec ,
270
282
}
0 commit comments