@@ -50,6 +50,7 @@ func TestConfigMapUnpacker(t *testing.T) {
5050 return start
5151 }
5252 backoffLimit := int32 (3 )
53+ ttlSecondsAfterFinished := int32 (300 ) // 5 minutes TTL for automatic cleanup
5354 // Used to set the default value for job.spec.ActiveDeadlineSeconds
5455 // that would normally be passed from the cmdline flag
5556 defaultUnpackDuration := 10 * time .Minute
@@ -263,8 +264,9 @@ func TestConfigMapUnpacker(t *testing.T) {
263264 },
264265 Spec : batchv1.JobSpec {
265266 // The expected job's timeout should be set to the custom annotation timeout
266- ActiveDeadlineSeconds : & customAnnotationTimeoutSeconds ,
267- BackoffLimit : & backoffLimit ,
267+ ActiveDeadlineSeconds : & customAnnotationTimeoutSeconds ,
268+ BackoffLimit : & backoffLimit ,
269+ TTLSecondsAfterFinished : & ttlSecondsAfterFinished ,
268270 Template : corev1.PodTemplateSpec {
269271 ObjectMeta : metav1.ObjectMeta {
270272 Name : pathHash ,
@@ -484,8 +486,9 @@ func TestConfigMapUnpacker(t *testing.T) {
484486 },
485487 },
486488 Spec : batchv1.JobSpec {
487- ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
488- BackoffLimit : & backoffLimit ,
489+ ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
490+ BackoffLimit : & backoffLimit ,
491+ TTLSecondsAfterFinished : & ttlSecondsAfterFinished ,
489492 Template : corev1.PodTemplateSpec {
490493 ObjectMeta : metav1.ObjectMeta {
491494 Name : digestHash ,
@@ -744,8 +747,9 @@ func TestConfigMapUnpacker(t *testing.T) {
744747 },
745748 },
746749 Spec : batchv1.JobSpec {
747- ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
748- BackoffLimit : & backoffLimit ,
750+ ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
751+ BackoffLimit : & backoffLimit ,
752+ TTLSecondsAfterFinished : & ttlSecondsAfterFinished ,
749753 Template : corev1.PodTemplateSpec {
750754 ObjectMeta : metav1.ObjectMeta {
751755 Name : digestHash ,
@@ -999,8 +1003,9 @@ func TestConfigMapUnpacker(t *testing.T) {
9991003 },
10001004 },
10011005 Spec : batchv1.JobSpec {
1002- ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
1003- BackoffLimit : & backoffLimit ,
1006+ ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
1007+ BackoffLimit : & backoffLimit ,
1008+ TTLSecondsAfterFinished : & ttlSecondsAfterFinished ,
10041009 Template : corev1.PodTemplateSpec {
10051010 ObjectMeta : metav1.ObjectMeta {
10061011 Name : pathHash ,
@@ -1224,8 +1229,9 @@ func TestConfigMapUnpacker(t *testing.T) {
12241229 },
12251230 },
12261231 Spec : batchv1.JobSpec {
1227- ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
1228- BackoffLimit : & backoffLimit ,
1232+ ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
1233+ BackoffLimit : & backoffLimit ,
1234+ TTLSecondsAfterFinished : & ttlSecondsAfterFinished ,
12291235 Template : corev1.PodTemplateSpec {
12301236 ObjectMeta : metav1.ObjectMeta {
12311237 Name : pathHash ,
@@ -1462,8 +1468,9 @@ func TestConfigMapUnpacker(t *testing.T) {
14621468 },
14631469 },
14641470 Spec : batchv1.JobSpec {
1465- ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
1466- BackoffLimit : & backoffLimit ,
1471+ ActiveDeadlineSeconds : & defaultUnpackTimeoutSeconds ,
1472+ BackoffLimit : & backoffLimit ,
1473+ TTLSecondsAfterFinished : & ttlSecondsAfterFinished ,
14671474 Template : corev1.PodTemplateSpec {
14681475 ObjectMeta : metav1.ObjectMeta {
14691476 Name : pathHash ,
@@ -2075,3 +2082,43 @@ func TestSortUnpackJobs(t *testing.T) {
20752082 assert .ElementsMatch (t , tc .expectedToDelete , toDelete )
20762083 }
20772084}
2085+
2086+ // TestBundleUnpackJobHasTTL verifies that bundle unpack jobs have TTL set for automatic cleanup
2087+ func TestBundleUnpackJobHasTTL (t * testing.T ) {
2088+ cmRef := & corev1.ObjectReference {
2089+ APIVersion : "v1" ,
2090+ Kind : "ConfigMap" ,
2091+ Name : "test-bundle" ,
2092+ Namespace : "test-namespace" ,
2093+ UID : "test-uid" ,
2094+ }
2095+ bundlePath := "quay.io/test/bundle:v1.0.0"
2096+ secrets := []corev1.LocalObjectReference {{Name : "test-secret" }}
2097+ timeout := 10 * time .Minute
2098+
2099+ unpacker := & ConfigMapUnpacker {
2100+ opmImage : "test-opm:latest" ,
2101+ utilImage : "test-util:latest" ,
2102+ unpackTimeout : timeout ,
2103+ runAsUser : 1001 ,
2104+ }
2105+
2106+ job := unpacker .job (cmRef , bundlePath , secrets , timeout )
2107+
2108+ // Verify TTL is set to 5 minutes (300 seconds)
2109+ require .NotNil (t , job .Spec .TTLSecondsAfterFinished , "TTLSecondsAfterFinished should be set" )
2110+ assert .Equal (t , int32 (300 ), * job .Spec .TTLSecondsAfterFinished , "TTL should be 300 seconds (5 minutes) for faster recovery" )
2111+
2112+ // Verify other important job specs are still set correctly
2113+ assert .NotNil (t , job .Spec .BackoffLimit , "BackoffLimit should be set" )
2114+ assert .Equal (t , int32 (3 ), * job .Spec .BackoffLimit )
2115+
2116+ assert .NotNil (t , job .Spec .ActiveDeadlineSeconds , "ActiveDeadlineSeconds should be set" )
2117+ assert .Equal (t , int64 (timeout .Seconds ()), * job .Spec .ActiveDeadlineSeconds )
2118+
2119+ // Verify job metadata
2120+ assert .Equal (t , cmRef .Name , job .Name )
2121+ assert .Equal (t , cmRef .Namespace , job .Namespace )
2122+ assert .Contains (t , job .Labels , install .OLMManagedLabelKey )
2123+ assert .Contains (t , job .Labels , BundleUnpackRefLabel )
2124+ }
0 commit comments