@@ -46,6 +46,8 @@ func defaultAnn() Annotations {
4646 }
4747}
4848
49+ const testOnDeleteJob = "object-lease-controller.ullberg.io/on-delete-job"
50+
4951type stubMgr struct { c client.Client }
5052
5153func (s stubMgr ) GetClient () client.Client { return s .c }
@@ -481,7 +483,7 @@ func TestHandleExpired_CreatesCleanupJob_FireAndForget(t *testing.T) {
481483 obj .SetAnnotations (map [string ]string {
482484 defaultAnn ().TTL : "1s" ,
483485 defaultAnn ().LeaseStart : time .Now ().UTC ().Add (- time .Hour ).Format (time .RFC3339 ),
484- "object-lease-controller.ullberg.io/on-delete-job" : "scripts-cm/cleanup.sh" ,
486+ testOnDeleteJob : "scripts-cm/cleanup.sh" ,
485487 })
486488
487489 // Need a scheme that understands Jobs
@@ -494,7 +496,7 @@ func TestHandleExpired_CreatesCleanupJob_FireAndForget(t *testing.T) {
494496 // rebuild client with Job types registered
495497 cl2 := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (obj ).Build ()
496498 r .Client = cl2
497- r .Annotations .OnDeleteJob = "object-lease-controller.ullberg.io/on-delete-job"
499+ r .Annotations .OnDeleteJob = testOnDeleteJob
498500 reg := withIsolatedRegistry (t )
499501 r .Metrics = ometrics .NewLeaseMetrics (gvk )
500502 r .Recorder = record .NewFakeRecorder (10 )
@@ -507,7 +509,7 @@ func TestHandleExpired_CreatesCleanupJob_FireAndForget(t *testing.T) {
507509
508510 // job should exist in client - search by label
509511 jl := & batchv1.JobList {}
510- if err := r .Client . List (context .Background (), jl , client .InNamespace ("default" )); err != nil {
512+ if err := r .List (context .Background (), jl , client .InNamespace ("default" )); err != nil {
511513 t .Fatalf ("list jobs failed: %v" , err )
512514 }
513515 if len (jl .Items ) == 0 {
@@ -539,7 +541,7 @@ func TestHandleExpired_CleanupJobCreateFails(t *testing.T) {
539541 obj .SetAnnotations (map [string ]string {
540542 defaultAnn ().TTL : "1s" ,
541543 defaultAnn ().LeaseStart : time .Now ().UTC ().Add (- time .Hour ).Format (time .RFC3339 ),
542- "object-lease-controller.ullberg.io/on-delete-job" : "scripts-cm/cleanup.sh" ,
544+ testOnDeleteJob : "scripts-cm/cleanup.sh" ,
543545 })
544546
545547 scheme := runtime .NewScheme ()
@@ -551,7 +553,7 @@ func TestHandleExpired_CleanupJobCreateFails(t *testing.T) {
551553 // client that returns error on Create
552554
553555 r , _ , _ := newWatcher (t , gvk , obj )
554- r .Annotations .OnDeleteJob = "object-lease-controller.ullberg.io/on-delete-job"
556+ r .Annotations .OnDeleteJob = testOnDeleteJob
555557 r .Client = & failCreateClient {Client : base }
556558 r .Recorder = record .NewFakeRecorder (10 )
557559
@@ -601,8 +603,8 @@ func TestHandleExpired_CleanupJobWaitFailure(t *testing.T) {
601603 obj .SetAnnotations (map [string ]string {
602604 defaultAnn ().TTL : "1s" ,
603605 defaultAnn ().LeaseStart : time .Now ().UTC ().Add (- time .Hour ).Format (time .RFC3339 ),
604- "object-lease-controller.ullberg.io/on-delete-job" : "scripts-cm/cleanup.sh" ,
605- "object-lease-controller.ullberg.io/job-wait" : "true" ,
606+ testOnDeleteJob : "scripts-cm/cleanup.sh" ,
607+ "object-lease-controller.ullberg.io/job-wait" : "true" ,
606608 })
607609
608610 scheme := runtime .NewScheme ()
@@ -611,7 +613,7 @@ func TestHandleExpired_CleanupJobWaitFailure(t *testing.T) {
611613 base := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (obj ).Build ()
612614
613615 r , _ , _ := newWatcher (t , gvk , obj )
614- r .Annotations .OnDeleteJob = "object-lease-controller.ullberg.io/on-delete-job"
616+ r .Annotations .OnDeleteJob = testOnDeleteJob
615617 r .Annotations .JobWait = "object-lease-controller.ullberg.io/job-wait"
616618 r .Client = & failCompleteClient {Client : base }
617619 r .Recorder = record .NewFakeRecorder (10 )
@@ -662,11 +664,11 @@ func TestHandleExpired_InvalidCleanupConfigEmitsEvent(t *testing.T) {
662664 obj .SetAnnotations (map [string ]string {
663665 defaultAnn ().TTL : "1s" ,
664666 defaultAnn ().LeaseStart : time .Now ().UTC ().Add (- time .Hour ).Format (time .RFC3339 ),
665- "object-lease-controller.ullberg.io/on-delete-job" : "missingSlash" ,
667+ testOnDeleteJob : "missingSlash" ,
666668 })
667669
668670 r , _ , _ := newWatcher (t , gvk , obj )
669- r .Annotations .OnDeleteJob = "object-lease-controller.ullberg.io/on-delete-job"
671+ r .Annotations .OnDeleteJob = testOnDeleteJob
670672 r .Recorder = record .NewFakeRecorder (10 )
671673
672674 _ , err := r .handleExpired (context .Background (), obj , time .Now ().UTC ())
@@ -698,7 +700,7 @@ func TestExecuteCleanupJob_LeaseStartFallback(t *testing.T) {
698700 obj .SetAnnotations (map [string ]string {
699701 defaultAnn ().TTL : "1s" ,
700702 defaultAnn ().LeaseStart : "not-a-time" ,
701- "object-lease-controller.ullberg.io/on-delete-job" : "scripts-cm/cleanup.sh" ,
703+ testOnDeleteJob : "scripts-cm/cleanup.sh" ,
702704 })
703705
704706 scheme := runtime .NewScheme ()
@@ -707,7 +709,7 @@ func TestExecuteCleanupJob_LeaseStartFallback(t *testing.T) {
707709 base := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (obj ).Build ()
708710
709711 r , _ , _ := newWatcher (t , gvk , obj )
710- r .Annotations .OnDeleteJob = "object-lease-controller.ullberg.io/on-delete-job"
712+ r .Annotations .OnDeleteJob = testOnDeleteJob
711713 r .Client = base
712714 r .Recorder = record .NewFakeRecorder (10 )
713715
@@ -733,7 +735,7 @@ func TestExecuteCleanupJob_LeaseStartFallback(t *testing.T) {
733735
734736 // find created job and check LEASE_STARTED_AT env is RFC3339 (approx now)
735737 jl := & batchv1.JobList {}
736- if err := r .Client . List (context .Background (), jl , client .InNamespace ("default" )); err != nil {
738+ if err := r .List (context .Background (), jl , client .InNamespace ("default" )); err != nil {
737739 t .Fatalf ("list jobs failed: %v" , err )
738740 }
739741 if len (jl .Items ) == 0 {
@@ -764,8 +766,8 @@ func TestHandleExpired_CleanupJobWaitSuccess(t *testing.T) {
764766 obj .SetAnnotations (map [string ]string {
765767 defaultAnn ().TTL : "1s" ,
766768 defaultAnn ().LeaseStart : time .Now ().UTC ().Add (- time .Hour ).Format (time .RFC3339 ),
767- "object-lease-controller.ullberg.io/on-delete-job" : "scripts-cm/cleanup.sh" ,
768- "object-lease-controller.ullberg.io/job-wait" : "true" ,
769+ testOnDeleteJob : "scripts-cm/cleanup.sh" ,
770+ "object-lease-controller.ullberg.io/job-wait" : "true" ,
769771 })
770772
771773 scheme := runtime .NewScheme ()
@@ -778,7 +780,7 @@ func TestHandleExpired_CleanupJobWaitSuccess(t *testing.T) {
778780 // use top-level completeCreateClient
779781
780782 r , _ , _ := newWatcher (t , gvk , obj )
781- r .Annotations .OnDeleteJob = "object-lease-controller.ullberg.io/on-delete-job"
783+ r .Annotations .OnDeleteJob = testOnDeleteJob
782784 r .Annotations .JobWait = "object-lease-controller.ullberg.io/job-wait"
783785
784786 r .Client = & completeCreateClient {Client : base }
0 commit comments