@@ -40,13 +40,23 @@ func TestConfigMapUnpacker(t *testing.T) {
40
40
return start
41
41
}
42
42
backoffLimit := int32 (3 )
43
+ // Used to set the default value for job.spec.ActiveDeadlineSeconds
44
+ // that would normally be passed from the cmdline flag
45
+ defaultUnpackDuration := 10 * time .Minute
46
+ defaultUnpackTimeoutSeconds := int64 (defaultUnpackDuration .Seconds ())
47
+
48
+ // Custom timeout to override the default cmdline flag ActiveDeadlineSeconds value
49
+ customAnnotationDuration := 2 * time .Minute
50
+ customAnnotationTimeoutSeconds := int64 (customAnnotationDuration .Seconds ())
43
51
44
52
type fields struct {
45
53
objs []runtime.Object
46
54
crs []runtime.Object
47
55
}
48
56
type args struct {
49
57
lookup * operatorsv1alpha1.BundleLookup
58
+ // A negative timeout duration arg means it will be ignored and the default flag timeout will be used
59
+ annotationTimeout time.Duration
50
60
}
51
61
type expected struct {
52
62
res * BundleUnpackResult
@@ -67,6 +77,7 @@ func TestConfigMapUnpacker(t *testing.T) {
67
77
description : "NoCatalogSource/NoConfigMap/NoJob/NotCreated/Pending" ,
68
78
fields : fields {},
69
79
args : args {
80
+ annotationTimeout : - 1 * time .Minute ,
70
81
lookup : & operatorsv1alpha1.BundleLookup {
71
82
Path : bundlePath ,
72
83
Replaces : "" ,
@@ -108,7 +119,7 @@ func TestConfigMapUnpacker(t *testing.T) {
108
119
},
109
120
},
110
121
{
111
- description : "CatalogSourcePresent/NoConfigMap/NoJob/Created /Pending" ,
122
+ description : "CatalogSourcePresent/NoConfigMap/NoJob/JobCreated /Pending/WithCustomTimeout " ,
112
123
fields : fields {
113
124
crs : []runtime.Object {
114
125
& operatorsv1alpha1.CatalogSource {
@@ -123,6 +134,9 @@ func TestConfigMapUnpacker(t *testing.T) {
123
134
},
124
135
},
125
136
args : args {
137
+ // We override the default timeout and expect to see the job created with
138
+ // the custom annotation based timeout value
139
+ annotationTimeout : customAnnotationDuration ,
126
140
lookup : & operatorsv1alpha1.BundleLookup {
127
141
Path : bundlePath ,
128
142
Replaces : "" ,
@@ -194,7 +208,9 @@ func TestConfigMapUnpacker(t *testing.T) {
194
208
},
195
209
},
196
210
Spec : batchv1.JobSpec {
197
- BackoffLimit : & backoffLimit ,
211
+ // The expected job's timeout should be set to the custom annotation timeout
212
+ ActiveDeadlineSeconds : & customAnnotationTimeoutSeconds ,
213
+ BackoffLimit : & backoffLimit ,
198
214
Template : corev1.PodTemplateSpec {
199
215
ObjectMeta : metav1.ObjectMeta {
200
216
Name : pathHash ,
@@ -371,7 +387,8 @@ func TestConfigMapUnpacker(t *testing.T) {
371
387
},
372
388
},
373
389
Spec : batchv1.JobSpec {
374
- BackoffLimit : & backoffLimit ,
390
+ ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
391
+ BackoffLimit : & backoffLimit ,
375
392
Template : corev1.PodTemplateSpec {
376
393
ObjectMeta : metav1.ObjectMeta {
377
394
Name : pathHash ,
@@ -507,6 +524,7 @@ func TestConfigMapUnpacker(t *testing.T) {
507
524
},
508
525
},
509
526
args : args {
527
+ annotationTimeout : - 1 * time .Minute ,
510
528
lookup : & operatorsv1alpha1.BundleLookup {
511
529
Path : bundlePath ,
512
530
Replaces : "" ,
@@ -586,7 +604,8 @@ func TestConfigMapUnpacker(t *testing.T) {
586
604
},
587
605
},
588
606
Spec : batchv1.JobSpec {
589
- BackoffLimit : & backoffLimit ,
607
+ ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
608
+ BackoffLimit : & backoffLimit ,
590
609
Template : corev1.PodTemplateSpec {
591
610
ObjectMeta : metav1.ObjectMeta {
592
611
Name : pathHash ,
@@ -797,7 +816,8 @@ func TestConfigMapUnpacker(t *testing.T) {
797
816
},
798
817
},
799
818
Spec : batchv1.JobSpec {
800
- BackoffLimit : & backoffLimit ,
819
+ ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
820
+ BackoffLimit : & backoffLimit ,
801
821
Template : corev1.PodTemplateSpec {
802
822
ObjectMeta : metav1.ObjectMeta {
803
823
Name : pathHash ,
@@ -915,6 +935,7 @@ func TestConfigMapUnpacker(t *testing.T) {
915
935
},
916
936
917
937
args : args {
938
+ annotationTimeout : - 1 * time .Minute ,
918
939
lookup : & operatorsv1alpha1.BundleLookup {
919
940
Path : bundlePath ,
920
941
Replaces : "" ,
@@ -949,7 +970,7 @@ func TestConfigMapUnpacker(t *testing.T) {
949
970
Type : operatorsv1alpha1 .BundleLookupPending ,
950
971
Status : corev1 .ConditionTrue ,
951
972
Reason : JobIncompleteReason ,
952
- Message : fmt .Sprintf ("%s: Unpack pod(ns-a/%s) container(pull) is pending. Reason: ErrImagePull, Message: pod pending for some reason | " ,
973
+ Message : fmt .Sprintf ("%s: Unpack pod(ns-a/%s) container(pull) is pending. Reason: ErrImagePull, Message: pod pending for some reason" ,
953
974
JobIncompleteMessage , pathHash + "-pod" ),
954
975
LastTransitionTime : & start ,
955
976
},
@@ -977,7 +998,8 @@ func TestConfigMapUnpacker(t *testing.T) {
977
998
},
978
999
},
979
1000
Spec : batchv1.JobSpec {
980
- BackoffLimit : & backoffLimit ,
1001
+ ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
1002
+ BackoffLimit : & backoffLimit ,
981
1003
Template : corev1.PodTemplateSpec {
982
1004
ObjectMeta : metav1.ObjectMeta {
983
1005
Name : pathHash ,
@@ -1106,6 +1128,7 @@ func TestConfigMapUnpacker(t *testing.T) {
1106
1128
},
1107
1129
},
1108
1130
args : args {
1131
+ annotationTimeout : - 1 * time .Minute ,
1109
1132
lookup : & operatorsv1alpha1.BundleLookup {
1110
1133
Path : bundlePath ,
1111
1134
Replaces : "" ,
@@ -1168,7 +1191,8 @@ func TestConfigMapUnpacker(t *testing.T) {
1168
1191
},
1169
1192
},
1170
1193
Spec : batchv1.JobSpec {
1171
- BackoffLimit : & backoffLimit ,
1194
+ ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
1195
+ BackoffLimit : & backoffLimit ,
1172
1196
Template : corev1.PodTemplateSpec {
1173
1197
ObjectMeta : metav1.ObjectMeta {
1174
1198
Name : pathHash ,
@@ -1310,11 +1334,11 @@ func TestConfigMapUnpacker(t *testing.T) {
1310
1334
WithOPMImage (opmImage ),
1311
1335
WithUtilImage (utilImage ),
1312
1336
WithNow (now ),
1337
+ WithUnpackTimeout (defaultUnpackDuration ),
1313
1338
)
1314
1339
require .NoError (t , err )
1315
1340
1316
- // The annotation unpack timeout arg is negative so it is ignored for these tests
1317
- res , err := unpacker .UnpackBundle (tt .args .lookup , - 1 * time .Minute )
1341
+ res , err := unpacker .UnpackBundle (tt .args .lookup , tt .args .annotationTimeout )
1318
1342
require .Equal (t , tt .expected .err , err )
1319
1343
1320
1344
if tt .expected .res == nil {
0 commit comments