@@ -25,6 +25,7 @@ import (
2525"k8s.io/apimachinery/pkg/watch"
2626"k8s.io/apiserver/pkg/apis/example"
2727"k8s.io/apiserver/pkg/features"
28+ "k8s.io/apiserver/pkg/storage"
2829storagetesting "k8s.io/apiserver/pkg/storage/testing"
2930utilfeature "k8s.io/apiserver/pkg/util/feature"
3031"k8s.io/client-go/tools/cache"
@@ -218,3 +219,79 @@ func TestCacherListerWatcherWhenListWatchDisabled(t *testing.T) {
218219t .Fatalf ("Expected error %q, but got %q" , expectedErrMsg , err .Error ())
219220}
220221}
222+
223+ func TestListerWatcherListResourceVersionPropagation (t * testing.T ) {
224+ scenarios := []struct {
225+ name string
226+ options metav1.ListOptions
227+ watchListEnabled bool
228+ watchListConsistencyCheckEnabled bool
229+ expectedStorageResourceVer string
230+ }{
231+ {
232+ name : "WatchList FG disabled - RV not propagated" ,
233+ options : metav1.ListOptions {
234+ ResourceVersion : "123" ,
235+ ResourceVersionMatch : metav1 .ResourceVersionMatchExact ,
236+ },
237+ watchListEnabled : false ,
238+ watchListConsistencyCheckEnabled : true ,
239+ expectedStorageResourceVer : "" ,
240+ },
241+ {
242+ name : "WatchList consistency check disabled - RV not propagated" ,
243+ options : metav1.ListOptions {
244+ ResourceVersion : "123" ,
245+ ResourceVersionMatch : metav1 .ResourceVersionMatchExact ,
246+ },
247+ watchListEnabled : true ,
248+ watchListConsistencyCheckEnabled : false ,
249+ expectedStorageResourceVer : "" ,
250+ },
251+ {
252+ name : "Unsupported RVM - RV not propagated" ,
253+ options : metav1.ListOptions {
254+ ResourceVersion : "123" ,
255+ ResourceVersionMatch : metav1 .ResourceVersionMatchNotOlderThan ,
256+ },
257+ watchListEnabled : true ,
258+ watchListConsistencyCheckEnabled : true ,
259+ expectedStorageResourceVer : "" ,
260+ },
261+ {
262+ name : "all conditions satisfied - RV propagated" ,
263+ options : metav1.ListOptions {
264+ ResourceVersion : "123" ,
265+ ResourceVersionMatch : metav1 .ResourceVersionMatchExact ,
266+ },
267+ watchListEnabled : true ,
268+ watchListConsistencyCheckEnabled : true ,
269+ expectedStorageResourceVer : "123" ,
270+ },
271+ }
272+
273+ for _ , scenario := range scenarios {
274+ t .Run (scenario .name , func (t * testing.T ) {
275+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .WatchList , scenario .watchListEnabled )
276+
277+ backingStorage := & dummyStorage {}
278+ var capturedOpts storage.ListOptions
279+ backingStorage .getListFn = func (ctx context.Context , resPrefix string , opts storage.ListOptions , listObj runtime.Object ) error {
280+ capturedOpts = opts
281+ return nil
282+ }
283+
284+ targetInterface := NewListerWatcher (backingStorage , "/pods/" , func () runtime.Object { return & example.PodList {} }, nil )
285+ target := targetInterface .(* listerWatcher )
286+ target .watchListConsistencyCheckEnabled = scenario .watchListConsistencyCheckEnabled
287+
288+ if _ , err := target .List (scenario .options ); err != nil {
289+ t .Fatalf ("List returned error: %v" , err )
290+ }
291+
292+ if capturedOpts .ResourceVersion != scenario .expectedStorageResourceVer {
293+ t .Fatalf ("expected storage ResourceVersion %q, got %q" , scenario .expectedStorageResourceVer , capturedOpts .ResourceVersion )
294+ }
295+ })
296+ }
297+ }
0 commit comments