@@ -20,6 +20,7 @@ import (
20
20
"strings"
21
21
"testing"
22
22
23
+ apps "k8s.io/api/apps/v1"
23
24
batchv1 "k8s.io/api/batch/v1"
24
25
batchv1beta1 "k8s.io/api/batch/v1beta1"
25
26
corev1 "k8s.io/api/core/v1"
@@ -137,32 +138,34 @@ func TestCreateJob(t *testing.T) {
137
138
138
139
func TestCreateJobFromCronJob (t * testing.T ) {
139
140
jobName := "test-job"
140
- tests := map [string ]struct {
141
- from * batchv1beta1.CronJob
142
- expected * batchv1.Job
143
- }{
144
- "from CronJob" : {
145
- from : & batchv1beta1.CronJob {
146
- Spec : batchv1beta1.CronJobSpec {
147
- JobTemplate : batchv1beta1.JobTemplateSpec {
148
- Spec : batchv1.JobSpec {
149
- Template : corev1.PodTemplateSpec {
150
- Spec : corev1.PodSpec {
151
- Containers : []corev1.Container {
152
- {Image : "test-image" },
153
- },
154
- RestartPolicy : corev1 .RestartPolicyNever ,
155
- },
141
+ cronJob := & batchv1beta1.CronJob {
142
+ Spec : batchv1beta1.CronJobSpec {
143
+ JobTemplate : batchv1beta1.JobTemplateSpec {
144
+ Spec : batchv1.JobSpec {
145
+ Template : corev1.PodTemplateSpec {
146
+ Spec : corev1.PodSpec {
147
+ Containers : []corev1.Container {
148
+ {Image : "test-image" },
156
149
},
150
+ RestartPolicy : corev1 .RestartPolicyNever ,
157
151
},
158
152
},
159
153
},
160
154
},
155
+ },
156
+ }
157
+ tests := map [string ]struct {
158
+ from * batchv1beta1.CronJob
159
+ expected * batchv1.Job
160
+ }{
161
+ "from CronJob" : {
162
+ from : cronJob ,
161
163
expected : & batchv1.Job {
162
164
TypeMeta : metav1.TypeMeta {APIVersion : batchv1 .SchemeGroupVersion .String (), Kind : "Job" },
163
165
ObjectMeta : metav1.ObjectMeta {
164
- Name : jobName ,
165
- Annotations : map [string ]string {"cronjob.kubernetes.io/instantiate" : "manual" },
166
+ Name : jobName ,
167
+ Annotations : map [string ]string {"cronjob.kubernetes.io/instantiate" : "manual" },
168
+ OwnerReferences : []metav1.OwnerReference {* metav1 .NewControllerRef (cronJob , apps .SchemeGroupVersion .WithKind ("CronJob" ))},
166
169
},
167
170
Spec : batchv1.JobSpec {
168
171
Template : corev1.PodTemplateSpec {
@@ -184,6 +187,7 @@ func TestCreateJobFromCronJob(t *testing.T) {
184
187
Name : jobName ,
185
188
}
186
189
job := o .createJobFromCronJob (tc .from )
190
+
187
191
if ! apiequality .Semantic .DeepEqual (job , tc .expected ) {
188
192
t .Errorf ("expected:\n %#v\n got:\n %#v" , tc .expected , job )
189
193
}
0 commit comments