Skip to content

Commit c9bd841

Browse files
authored
Merge pull request kubernetes#120984 from p0lyn0mial/upstream-reflector-always-fallback-to-listwatch
reflector: fallback to the previous mode on any error
2 parents 3c94af7 + 4b39150 commit c9bd841

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

staging/src/k8s.io/client-go/tools/cache/reflector.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,9 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
334334
return nil
335335
}
336336
if err != nil {
337-
if !apierrors.IsInvalid(err) {
338-
return err
339-
}
340-
klog.Warning("The watch-list feature is not supported by the server, falling back to the previous LIST/WATCH semantics")
337+
klog.Warningf("The watchlist request ended with an error, falling back to the standard LIST/WATCH semantics because making progress is better than deadlocking, err = %v", err)
341338
fallbackToList = true
342-
// Ensure that we won't accidentally pass some garbage down the watch.
339+
// ensure that we won't accidentally pass some garbage down the watch.
343340
w = nil
344341
}
345342
}

staging/src/k8s.io/client-go/tools/cache/reflector_watchlist_test.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,39 @@ func TestWatchList(t *testing.T) {
9494
expectedStoreContent: []v1.Pod{*makePod("p1", "1")},
9595
},
9696
{
97-
name: "returning any other error than apierrors.NewInvalid stops the reflector and reports the error",
97+
name: "returning any other error than apierrors.NewInvalid forces fallback",
9898
watchOptionsPredicate: func(options metav1.ListOptions) error {
99-
return fmt.Errorf("dummy error")
99+
if options.SendInitialEvents != nil && *options.SendInitialEvents {
100+
return fmt.Errorf("dummy error")
101+
}
102+
return nil
103+
},
104+
podList: &v1.PodList{
105+
ListMeta: metav1.ListMeta{ResourceVersion: "1"},
106+
Items: []v1.Pod{*makePod("p1", "1")},
107+
},
108+
closeAfterWatchEvents: 1,
109+
watchEvents: []watch.Event{{Type: watch.Added, Object: makePod("p2", "2")}},
110+
expectedWatchRequests: 2,
111+
expectedListRequests: 1,
112+
expectedStoreContent: []v1.Pod{*makePod("p1", "1"), *makePod("p2", "2")},
113+
expectedRequestOptions: []metav1.ListOptions{
114+
{
115+
SendInitialEvents: pointer.Bool(true),
116+
AllowWatchBookmarks: true,
117+
ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan,
118+
TimeoutSeconds: pointer.Int64(1),
119+
},
120+
{
121+
ResourceVersion: "0",
122+
Limit: 500,
123+
},
124+
{
125+
AllowWatchBookmarks: true,
126+
ResourceVersion: "1",
127+
TimeoutSeconds: pointer.Int64(1),
128+
},
100129
},
101-
expectedError: fmt.Errorf("dummy error"),
102-
expectedWatchRequests: 1,
103-
expectedRequestOptions: []metav1.ListOptions{{
104-
SendInitialEvents: pointer.Bool(true),
105-
AllowWatchBookmarks: true,
106-
ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan,
107-
TimeoutSeconds: pointer.Int64(1),
108-
}},
109130
},
110131
{
111132
name: "the reflector can fall back to old LIST/WATCH semantics when a server doesn't support streaming",

0 commit comments

Comments
 (0)