Skip to content

Commit 10b1bbe

Browse files
committed
Don't try watching items without resourceVersion
Signed-off-by: Daniel Vassdal <[email protected]>
1 parent e5ef2e1 commit 10b1bbe

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pkg/cache/cluster.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,29 @@ func (c *clusterCache) watchEvents(ctx context.Context, api kube.APIResourceInfo
666666
}
667667
}
668668

669+
// If the resourceVersion is still missing, watchutil.NewRetryWatcher will fail.
670+
// https://github.com/kubernetes/client-go/blob/78d2af792babf2dd937ba2e2a8d99c753a5eda89/tools/watch/retrywatcher.go#L68-L71
671+
// Instead, let's just check if the resourceVersion exists at the next resync ...
672+
if resourceVersion == "" {
673+
c.log.V(1).Info(fmt.Sprintf("Ignoring watch for %s on %s due to missing resourceVersion", api.GroupKind, c.config.Host))
674+
675+
var watchResyncTimeoutCh <-chan time.Time
676+
if c.watchResyncTimeout > 0 {
677+
shouldResync := time.NewTimer(c.watchResyncTimeout)
678+
defer shouldResync.Stop()
679+
watchResyncTimeoutCh = shouldResync.C
680+
}
681+
682+
for {
683+
select {
684+
case <-ctx.Done():
685+
return nil
686+
case <-watchResyncTimeoutCh:
687+
return fmt.Errorf("Resyncing %s on %s due to timeout", api.GroupKind, c.config.Host)
688+
}
689+
}
690+
}
691+
669692
w, err := watchutil.NewRetryWatcher(resourceVersion, &cache.ListWatch{
670693
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
671694
res, err := resClient.Watch(ctx, options)

0 commit comments

Comments
 (0)