@@ -338,8 +338,6 @@ func TestWatchCacheBypass(t *testing.T) {
338
338
t .Fatalf ("unexpected error waiting for the cache to be ready" )
339
339
}
340
340
341
- // Inject error to underlying layer and check if cacher is not bypassed.
342
- backingStorage .injectError (errDummy )
343
341
_ , err = cacher .Watch (context .TODO (), "pod/ns" , storage.ListOptions {
344
342
ResourceVersion : "0" ,
345
343
Predicate : storage .Everything ,
@@ -348,12 +346,32 @@ func TestWatchCacheBypass(t *testing.T) {
348
346
t .Errorf ("Watch with RV=0 should be served from cache: %v" , err )
349
347
}
350
348
351
- // With unset RV, check if cacher is bypassed.
352
349
_ , err = cacher .Watch (context .TODO (), "pod/ns" , storage.ListOptions {
353
350
ResourceVersion : "" ,
351
+ Predicate : storage .Everything ,
354
352
})
355
- if err != errDummy {
356
- t .Errorf ("Watch with unset RV should bypass cacher: %v" , err )
353
+ if err != nil {
354
+ t .Errorf ("Watch with RV=0 should be served from cache: %v" , err )
355
+ }
356
+
357
+ defer featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .WatchFromStorageWithoutResourceVersion , false )()
358
+ _ , err = cacher .Watch (context .TODO (), "pod/ns" , storage.ListOptions {
359
+ ResourceVersion : "" ,
360
+ Predicate : storage .Everything ,
361
+ })
362
+ if err != nil {
363
+ t .Errorf ("With WatchFromStorageWithoutResourceVersion disabled, watch with unset RV should be served from cache: %v" , err )
364
+ }
365
+
366
+ // Inject error to underlying layer and check if cacher is not bypassed.
367
+ backingStorage .injectError (errDummy )
368
+ defer featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .WatchFromStorageWithoutResourceVersion , true )()
369
+ _ , err = cacher .Watch (context .TODO (), "pod/ns" , storage.ListOptions {
370
+ ResourceVersion : "" ,
371
+ Predicate : storage .Everything ,
372
+ })
373
+ if ! errors .Is (err , errDummy ) {
374
+ t .Errorf ("With WatchFromStorageWithoutResourceVersion enabled, watch with unset RV should be served from storage: %v" , err )
357
375
}
358
376
}
359
377
@@ -2032,9 +2050,11 @@ func TestGetWatchCacheResourceVersion(t *testing.T) {
2032
2050
// | Unset | true/false | nil/true/false |
2033
2051
// +-----------------+---------------------+-----------------------+
2034
2052
{
2035
- name : "RV=unset, allowWatchBookmarks=true, sendInitialEvents=nil" ,
2036
- opts : listOptions (true , nil , "" ),
2037
- expectedWatchResourceVersion : 100 ,
2053
+ name : "RV=unset, allowWatchBookmarks=true, sendInitialEvents=nil" ,
2054
+ opts : listOptions (true , nil , "" ),
2055
+ // Expecting RV 0, due to https://github.com/kubernetes/kubernetes/pull/123935 reverted to serving those requests from watch cache.
2056
+ // Set to 100, when WatchFromStorageWithoutResourceVersion is set to true.
2057
+ expectedWatchResourceVersion : 0 ,
2038
2058
},
2039
2059
{
2040
2060
name : "RV=unset, allowWatchBookmarks=true, sendInitialEvents=true" ,
@@ -2047,9 +2067,11 @@ func TestGetWatchCacheResourceVersion(t *testing.T) {
2047
2067
expectedWatchResourceVersion : 100 ,
2048
2068
},
2049
2069
{
2050
- name : "RV=unset, allowWatchBookmarks=false, sendInitialEvents=nil" ,
2051
- opts : listOptions (false , nil , "" ),
2052
- expectedWatchResourceVersion : 100 ,
2070
+ name : "RV=unset, allowWatchBookmarks=false, sendInitialEvents=nil" ,
2071
+ opts : listOptions (false , nil , "" ),
2072
+ // Expecting RV 0, due to https://github.com/kubernetes/kubernetes/pull/123935 reverted to serving those requests from watch cache.
2073
+ // Set to 100, when WatchFromStorageWithoutResourceVersion is set to true.
2074
+ expectedWatchResourceVersion : 0 ,
2053
2075
},
2054
2076
{
2055
2077
name : "RV=unset, allowWatchBookmarks=false, sendInitialEvents=true, legacy" ,
0 commit comments