@@ -31,6 +31,7 @@ import (
31
31
"k8s.io/apimachinery/pkg/util/wait"
32
32
"k8s.io/client-go/informers"
33
33
"k8s.io/client-go/kubernetes/fake"
34
+ "k8s.io/client-go/tools/cache"
34
35
testingclock "k8s.io/utils/clock/testing"
35
36
"k8s.io/utils/ptr"
36
37
)
@@ -697,6 +698,7 @@ func TestController(t *testing.T) {
697
698
if err != nil {
698
699
t .Fatal (err )
699
700
}
701
+ controller .clock = fakeClock
700
702
701
703
for _ , obj := range tc .leases {
702
704
t .Logf ("Pre-creating lease %s/%s" , obj .Namespace , obj .Name )
@@ -715,6 +717,9 @@ func TestController(t *testing.T) {
715
717
716
718
informerFactory .Start (ctx .Done ())
717
719
informerFactory .WaitForCacheSync (ctx .Done ())
720
+ if ! cache .WaitForNamedCacheSync (controllerName , ctx .Done (), controller .leaseRegistration .HasSynced , controller .leaseCandidateRegistration .HasSynced ) {
721
+ return
722
+ }
718
723
go controller .Run (ctx , 1 )
719
724
720
725
if rand .Intn (2 ) == 0 {
@@ -747,9 +752,9 @@ func TestController(t *testing.T) {
747
752
continue // only candidate-aware controllers will follow preferredHolder
748
753
}
749
754
750
- t . Logf ("Deleting lease %s/%s because of preferredHolder %q != %q" , l .Namespace , l .Name , * ph , * l .Spec .HolderIdentity )
755
+ fmt . Printf ("Deleting lease %s/%s because of preferredHolder %q != %q" , l .Namespace , l .Name , * ph , * l .Spec .HolderIdentity )
751
756
if err = client .CoordinationV1 ().Leases (expectedLease .Namespace ).Delete (ctx , expectedLease .Name , metav1.DeleteOptions {}); err != nil {
752
- t . Logf ("Error deleting lease %s/%s: %v" , l .Namespace , l .Name , err )
757
+ fmt . Printf ("Error deleting lease %s/%s: %v" , l .Namespace , l .Name , err )
753
758
}
754
759
}
755
760
}
@@ -768,12 +773,12 @@ func TestController(t *testing.T) {
768
773
for _ , lc := range tc .createAfterControllerStart {
769
774
c , err := client .CoordinationV1alpha1 ().LeaseCandidates (lc .Namespace ).Get (ctx , lc .Name , metav1.GetOptions {})
770
775
if err == nil {
771
- if c .Spec .PingTime != nil {
772
- t . Logf ("Answering ping for %s/%s" , c .Namespace , c .Name )
776
+ if c .Spec .PingTime != nil && c . Spec . PingTime . Before ( c . Spec . RenewTime ) {
777
+ fmt . Printf ("Answering ping for %s/%s" , c .Namespace , c .Name )
773
778
c .Spec .RenewTime = & metav1.MicroTime {Time : fakeClock .Now ()}
774
779
_ , err = client .CoordinationV1alpha1 ().LeaseCandidates (lc .Namespace ).Update (ctx , c , metav1.UpdateOptions {})
775
780
if err != nil {
776
- t . Logf ("Error updating lease candidate %s/%s: %v" , c .Namespace , c .Name , err )
781
+ fmt . Printf ("Error updating lease candidate %s/%s: %v" , c .Namespace , c .Name , err )
777
782
}
778
783
}
779
784
}
0 commit comments