@@ -553,6 +553,7 @@ func (c *clusterCache) listResources(ctx context.Context, resClient dynamic.Reso
553
553
}
554
554
555
555
listRetry .Steps = int (c .listRetryLimit )
556
+ opts .ResourceVersion = "0"
556
557
err := retry .OnError (listRetry , c .listRetryFunc , func () error {
557
558
var ierr error
558
559
res , ierr = resClient .List (ctx , opts )
@@ -605,6 +606,7 @@ func (c *clusterCache) loadInitialState(ctx context.Context, api kube.APIResourc
605
606
}
606
607
607
608
func (c * clusterCache ) watchEvents (ctx context.Context , api kube.APIResourceInfo , resClient dynamic.ResourceInterface , ns string , resourceVersion string ) {
609
+ timeoutSeconds := int64 (c .watchResyncTimeout .Seconds ())
608
610
kube .RetryUntilSucceed (ctx , watchResourcesRetryTimeout , fmt .Sprintf ("watch %s on %s" , api .GroupKind , c .config .Host ), c .log , func () (err error ) {
609
611
defer func () {
610
612
if r := recover (); r != nil {
@@ -622,6 +624,7 @@ func (c *clusterCache) watchEvents(ctx context.Context, api kube.APIResourceInfo
622
624
623
625
w , err := watchutil .NewRetryWatcher (resourceVersion , & cache.ListWatch {
624
626
WatchFunc : func (options metav1.ListOptions ) (watch.Interface , error ) {
627
+ options .TimeoutSeconds = & timeoutSeconds
625
628
res , err := resClient .Watch (ctx , options )
626
629
if errors .IsNotFound (err ) {
627
630
c .stopWatching (api .GroupKind , ns )
@@ -633,30 +636,17 @@ func (c *clusterCache) watchEvents(ctx context.Context, api kube.APIResourceInfo
633
636
return err
634
637
}
635
638
636
- defer func () {
637
- w .Stop ()
638
- resourceVersion = ""
639
- }()
640
-
641
- var watchResyncTimeoutCh <- chan time.Time
642
- if c .watchResyncTimeout > 0 {
643
- shouldResync := time .NewTimer (c .watchResyncTimeout )
644
- defer shouldResync .Stop ()
645
- watchResyncTimeoutCh = shouldResync .C
646
- }
639
+ defer w .Stop ()
647
640
648
641
for {
649
642
select {
650
643
// stop watching when parent context got cancelled
651
644
case <- ctx .Done ():
652
645
return nil
653
646
654
- // re-synchronize API state and restart watch periodically
655
- case <- watchResyncTimeoutCh :
656
- return fmt .Errorf ("Resyncing %s on %s due to timeout" , api .GroupKind , c .config .Host )
657
-
658
647
// re-synchronize API state and restart watch if retry watcher failed to continue watching using provided resource version
659
648
case <- w .Done ():
649
+ resourceVersion = ""
660
650
return fmt .Errorf ("Watch %s on %s has closed" , api .GroupKind , c .config .Host )
661
651
662
652
case event , ok := <- w .ResultChan ():
@@ -666,8 +656,10 @@ func (c *clusterCache) watchEvents(ctx context.Context, api kube.APIResourceInfo
666
656
667
657
obj , ok := event .Object .(* unstructured.Unstructured )
668
658
if ! ok {
659
+ resourceVersion = ""
669
660
return fmt .Errorf ("Failed to convert to *unstructured.Unstructured: %v" , event .Object )
670
661
}
662
+ resourceVersion = obj .GetResourceVersion ()
671
663
672
664
c .processEvent (event .Type , obj )
673
665
if kube .IsCRD (obj ) {
0 commit comments