diff --git a/pkg/controlplane/reconcilers/lease.go b/pkg/controlplane/reconcilers/lease.go index ca3e1dee04b..891ab31c4d7 100644 --- a/pkg/controlplane/reconcilers/lease.go +++ b/pkg/controlplane/reconcilers/lease.go @@ -67,8 +67,9 @@ func (s *storageLeases) ListLeases() ([]string, error) { ResourceVersion: "0", ResourceVersionMatch: metav1.ResourceVersionMatchNotOlderThan, Predicate: storage.Everything, + Recursive: true, } - if err := s.storage.List(apirequest.NewDefaultContext(), s.baseKey, storageOpts, ipInfoList); err != nil { + if err := s.storage.GetList(apirequest.NewDefaultContext(), s.baseKey, storageOpts, ipInfoList); err != nil { return nil, err } diff --git a/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/dryrun.go b/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/dryrun.go index f746d097889..186537d19d7 100644 --- a/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/dryrun.go +++ b/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/dryrun.go @@ -64,12 +64,8 @@ func (s *DryRunnableStorage) Get(ctx context.Context, key string, opts storage.G return s.Storage.Get(ctx, key, opts, objPtr) } -func (s *DryRunnableStorage) GetToList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error { - return s.Storage.GetToList(ctx, key, opts, listObj) -} - -func (s *DryRunnableStorage) List(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error { - return s.Storage.List(ctx, key, opts, listObj) +func (s *DryRunnableStorage) GetList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error { + return s.Storage.GetList(ctx, key, opts, listObj) } func (s *DryRunnableStorage) GuaranteedUpdate( diff --git a/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go b/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go index 5721c3c98ee..6a090ae7b60 100644 --- a/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go +++ b/staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go @@ -347,16 +347,18 @@ func (e *Store) ListPredicate(ctx context.Context, p storage.SelectionPredicate, ResourceVersion: options.ResourceVersion, ResourceVersionMatch: options.ResourceVersionMatch, Predicate: p, + Recursive: true, } if name, ok := p.MatchesSingle(); ok { if key, err := e.KeyFunc(ctx, name); err == nil { - err := e.Storage.GetToList(ctx, key, storageOpts, list) + storageOpts.Recursive = false + err := e.Storage.GetList(ctx, key, storageOpts, list) return list, storeerr.InterpretListError(err, qualifiedResource) } // if we cannot extract a key based on the current context, the optimization is skipped } - err := e.Storage.List(ctx, e.KeyRootFunc(ctx), storageOpts, list) + err := e.Storage.GetList(ctx, e.KeyRootFunc(ctx), storageOpts, list) return list, storeerr.InterpretListError(err, qualifiedResource) } diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go index 001a96a02ba..231c999b4a4 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go @@ -604,23 +604,6 @@ func shouldDelegateList(opts storage.ListOptions) bool { return resourceVersion == "" || hasContinuation || hasLimit || opts.ResourceVersionMatch == metav1.ResourceVersionMatchExact } -// GetToList implements storage.Interface. -func (c *Cacher) GetToList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error { - return c.list(ctx, key, opts, listObj, false) -} - -// List implements storage.Interface. -func (c *Cacher) List(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error { - return c.list(ctx, key, opts, listObj, true) -} - -func (c *Cacher) delegateList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object, recursive bool) error { - if !recursive { - return c.storage.GetToList(ctx, key, opts, listObj) - } - return c.storage.List(ctx, key, opts, listObj) -} - func (c *Cacher) listItems(listRV uint64, key string, pred storage.SelectionPredicate, trace *utiltrace.Trace, recursive bool) ([]interface{}, uint64, string, error) { if !recursive { obj, exists, readResourceVersion, err := c.watchCache.WaitUntilFreshAndGet(listRV, key, trace) @@ -635,11 +618,13 @@ func (c *Cacher) listItems(listRV uint64, key string, pred storage.SelectionPred return c.watchCache.WaitUntilFreshAndList(listRV, pred.MatcherIndex(), trace) } -func (c *Cacher) list(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object, recursive bool) error { +// GetList implements storage.Interface +func (c *Cacher) GetList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error { + recursive := opts.Recursive resourceVersion := opts.ResourceVersion pred := opts.Predicate if shouldDelegateList(opts) { - return c.delegateList(ctx, key, opts, listObj, recursive) + return c.storage.GetList(ctx, key, opts, listObj) } // If resourceVersion is specified, serve it from cache. @@ -653,7 +638,7 @@ func (c *Cacher) list(ctx context.Context, key string, opts storage.ListOptions, if listRV == 0 && !c.ready.check() { // If Cacher is not yet initialized and we don't require any specific // minimal resource version, simply forward the request to storage. - return c.delegateList(ctx, key, opts, listObj, recursive) + return c.storage.GetList(ctx, key, opts, listObj) } trace := utiltrace.New("cacher list", utiltrace.Field{Key: "type", Value: c.objectType.String()}) @@ -1090,8 +1075,9 @@ func (lw *cacherListerWatcher) List(options metav1.ListOptions) (runtime.Object, storageOpts := storage.ListOptions{ ResourceVersionMatch: options.ResourceVersionMatch, Predicate: pred, + Recursive: true, } - if err := lw.storage.List(context.TODO(), lw.resourcePrefix, storageOpts, list); err != nil { + if err := lw.storage.GetList(context.TODO(), lw.resourcePrefix, storageOpts, list); err != nil { return nil, err } return list, nil diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go index 30fbe2388e0..a359e5befd7 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go @@ -311,10 +311,7 @@ func (d *dummyStorage) Watch(_ context.Context, _ string, _ storage.ListOptions) func (d *dummyStorage) Get(_ context.Context, _ string, _ storage.GetOptions, _ runtime.Object) error { return d.err } -func (d *dummyStorage) GetToList(_ context.Context, _ string, _ storage.ListOptions, _ runtime.Object) error { - return d.err -} -func (d *dummyStorage) List(_ context.Context, _ string, _ storage.ListOptions, listObj runtime.Object) error { +func (d *dummyStorage) GetList(_ context.Context, _ string, _ storage.ListOptions, listObj runtime.Object) error { podList := listObj.(*example.PodList) podList.ListMeta = metav1.ListMeta{ResourceVersion: "100"} return d.err @@ -326,7 +323,7 @@ func (d *dummyStorage) Count(_ string) (int64, error) { return 0, fmt.Errorf("unimplemented") } -func TestListCacheBypass(t *testing.T) { +func TestGetListCacheBypass(t *testing.T) { backingStorage := &dummyStorage{} cacher, _, err := newTestCacher(backingStorage) if err != nil { @@ -344,24 +341,26 @@ func TestListCacheBypass(t *testing.T) { // Inject error to underlying layer and check if cacher is not bypassed. backingStorage.err = errDummy - err = cacher.List(context.TODO(), "pods/ns", storage.ListOptions{ + err = cacher.GetList(context.TODO(), "pods/ns", storage.ListOptions{ ResourceVersion: "0", Predicate: pred, + Recursive: true, }, result) if err != nil { - t.Errorf("List with Limit and RV=0 should be served from cache: %v", err) + t.Errorf("GetList with Limit and RV=0 should be served from cache: %v", err) } - err = cacher.List(context.TODO(), "pods/ns", storage.ListOptions{ + err = cacher.GetList(context.TODO(), "pods/ns", storage.ListOptions{ ResourceVersion: "", Predicate: pred, + Recursive: true, }, result) if err != errDummy { - t.Errorf("List with Limit without RV=0 should bypass cacher: %v", err) + t.Errorf("GetList with Limit without RV=0 should bypass cacher: %v", err) } } -func TestGetToListCacheBypass(t *testing.T) { +func TestGetListNonRecursiveCacheBypass(t *testing.T) { backingStorage := &dummyStorage{} cacher, _, err := newTestCacher(backingStorage) if err != nil { @@ -379,20 +378,20 @@ func TestGetToListCacheBypass(t *testing.T) { // Inject error to underlying layer and check if cacher is not bypassed. backingStorage.err = errDummy - err = cacher.GetToList(context.TODO(), "pods/ns", storage.ListOptions{ + err = cacher.GetList(context.TODO(), "pods/ns", storage.ListOptions{ ResourceVersion: "0", Predicate: pred, }, result) if err != nil { - t.Errorf("GetToList with Limit and RV=0 should be served from cache: %v", err) + t.Errorf("GetList with Limit and RV=0 should be served from cache: %v", err) } - err = cacher.GetToList(context.TODO(), "pods/ns", storage.ListOptions{ + err = cacher.GetList(context.TODO(), "pods/ns", storage.ListOptions{ ResourceVersion: "", Predicate: pred, }, result) if err != errDummy { - t.Errorf("List with Limit without RV=0 should bypass cacher: %v", err) + t.Errorf("GetList with Limit without RV=0 should bypass cacher: %v", err) } } diff --git a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go index d263148cac8..c4e80aa8e4e 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go @@ -456,11 +456,6 @@ func (s *store) GuaranteedUpdate( } } -// GetToList implements storage.Interface.GetToList. -func (s *store) GetToList(ctx context.Context, key string, listOpts storage.ListOptions, listObj runtime.Object) error { - return s.list(ctx, key, listOpts, listObj, false) -} - func getNewItemFunc(listObj runtime.Object, v reflect.Value) func() runtime.Object { // For unstructured lists with a target group/version, preserve the group/version in the instantiated list items if unstructuredList, isUnstructured := listObj.(*unstructured.UnstructuredList); isUnstructured { @@ -557,12 +552,9 @@ func encodeContinue(key, keyPrefix string, resourceVersion int64) (string, error return base64.RawURLEncoding.EncodeToString(out), nil } -// List implements storage.Interface.List. -func (s *store) List(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error { - return s.list(ctx, key, opts, listObj, true) -} - -func (s *store) list(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object, recursive bool) error { +// GetList implements storage.Interface. +func (s *store) GetList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error { + recursive := opts.Recursive resourceVersion := opts.ResourceVersion match := opts.ResourceVersionMatch pred := opts.Predicate diff --git a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store_test.go b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store_test.go index b00eafdc361..2bc616db2c3 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store_test.go @@ -541,7 +541,7 @@ func TestPreconditionalDeleteWithSuggestion(t *testing.T) { } } -func TestGetToList(t *testing.T) { +func TestGetListNonRecursive(t *testing.T) { ctx, store, _ := testSetup(t) prevKey, prevStoredObj := testPropogateStore(ctx, t, store, &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "prev"}}) @@ -640,7 +640,13 @@ func TestGetToList(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { out := &example.PodList{} - err := store.GetToList(ctx, tt.key, storage.ListOptions{ResourceVersion: tt.rv, ResourceVersionMatch: tt.rvMatch, Predicate: tt.pred}, out) + storageOpts := storage.ListOptions{ + ResourceVersion: tt.rv, + ResourceVersionMatch: tt.rvMatch, + Predicate: tt.pred, + Recursive: false, + } + err := store.GetList(ctx, tt.key, storageOpts, out) if tt.expectRVTooLarge { if err == nil || !storage.IsTooLargeResourceVersion(err) { @@ -650,7 +656,7 @@ func TestGetToList(t *testing.T) { } if err != nil { - t.Fatalf("%s: GetToList failed: %v", tt.name, err) + t.Fatalf("GetList failed: %v", err) } if len(out.ResourceVersion) == 0 { t.Errorf("%s: unset resourceVersion", tt.name) @@ -1080,8 +1086,9 @@ func TestTransformationFailure(t *testing.T) { var got example.PodList storageOpts := storage.ListOptions{ Predicate: storage.Everything, + Recursive: true, } - if err := store.List(ctx, "/", storageOpts, &got); !storage.IsInternalError(err) { + if err := store.GetList(ctx, "/", storageOpts, &got); !storage.IsInternalError(err) { t.Errorf("Unexpected error %v", err) } @@ -1166,7 +1173,7 @@ func TestList(t *testing.T) { // we want to figure out the resourceVersion before we create anything initialList := &example.PodList{} - if err := store.List(ctx, "/", storage.ListOptions{Predicate: storage.Everything}, initialList); err != nil { + if err := store.GetList(ctx, "/", storage.ListOptions{Predicate: storage.Everything, Recursive: true}, initialList); err != nil { t.Errorf("Unexpected List error: %v", err) } initialRV := initialList.ResourceVersion @@ -1183,9 +1190,10 @@ func TestList(t *testing.T) { storageOpts := storage.ListOptions{ ResourceVersion: "0", Predicate: storage.Everything, + Recursive: true, } - if err := store.List(ctx, "/two-level", storageOpts, list); err != nil { - t.Errorf("Unexpected List error: %v", err) + if err := store.GetList(ctx, "/two-level", storageOpts, list); err != nil { + t.Errorf("Unexpected error: %v", err) } continueRV, _ := strconv.Atoi(list.ResourceVersion) secondContinuation, err := encodeContinue("/two-level/2", "/two-level/", int64(continueRV)) @@ -1576,12 +1584,13 @@ func TestList(t *testing.T) { ResourceVersion: tt.rv, ResourceVersionMatch: tt.rvMatch, Predicate: tt.pred, + Recursive: true, } var err error if tt.disablePaging { - err = disablePagingStore.List(ctx, tt.prefix, storageOpts, out) + err = disablePagingStore.GetList(ctx, tt.prefix, storageOpts, out) } else { - err = store.List(ctx, tt.prefix, storageOpts, out) + err = store.GetList(ctx, tt.prefix, storageOpts, out) } if tt.expectRVTooLarge { if err == nil || !storage.IsTooLargeResourceVersion(err) { @@ -1592,7 +1601,7 @@ func TestList(t *testing.T) { if err != nil { if !tt.expectError { - t.Fatalf("List failed: %v", err) + t.Fatalf("GetList failed: %v", err) } return } @@ -1690,8 +1699,9 @@ func TestListContinuation(t *testing.T) { options := storage.ListOptions{ ResourceVersion: "0", Predicate: pred(1, ""), + Recursive: true, } - if err := store.List(ctx, "/", options, out); err != nil { + if err := store.GetList(ctx, "/", options, out); err != nil { t.Fatalf("Unable to get initial list: %v", err) } if len(out.Continue) == 0 { @@ -1716,8 +1726,9 @@ func TestListContinuation(t *testing.T) { options = storage.ListOptions{ ResourceVersion: "0", Predicate: pred(0, continueFromSecondItem), + Recursive: true, } - if err := store.List(ctx, "/", options, out); err != nil { + if err := store.GetList(ctx, "/", options, out); err != nil { t.Fatalf("Unable to get second page: %v", err) } if len(out.Continue) != 0 { @@ -1742,8 +1753,9 @@ func TestListContinuation(t *testing.T) { options = storage.ListOptions{ ResourceVersion: "0", Predicate: pred(1, continueFromSecondItem), + Recursive: true, } - if err := store.List(ctx, "/", options, out); err != nil { + if err := store.GetList(ctx, "/", options, out); err != nil { t.Fatalf("Unable to get second page: %v", err) } if len(out.Continue) == 0 { @@ -1767,8 +1779,9 @@ func TestListContinuation(t *testing.T) { options = storage.ListOptions{ ResourceVersion: "0", Predicate: pred(1, continueFromThirdItem), + Recursive: true, } - if err := store.List(ctx, "/", options, out); err != nil { + if err := store.GetList(ctx, "/", options, out); err != nil { t.Fatalf("Unable to get second page: %v", err) } if len(out.Continue) != 0 { @@ -1861,8 +1874,9 @@ func TestListContinuationWithFilter(t *testing.T) { options := storage.ListOptions{ ResourceVersion: "0", Predicate: pred(2, ""), + Recursive: true, } - if err := store.List(ctx, "/", options, out); err != nil { + if err := store.GetList(ctx, "/", options, out); err != nil { t.Errorf("Unable to get initial list: %v", err) } if len(out.Continue) == 0 { @@ -1894,8 +1908,9 @@ func TestListContinuationWithFilter(t *testing.T) { options = storage.ListOptions{ ResourceVersion: "0", Predicate: pred(2, cont), + Recursive: true, } - if err := store.List(ctx, "/", options, out); err != nil { + if err := store.GetList(ctx, "/", options, out); err != nil { t.Errorf("Unable to get second page: %v", err) } if len(out.Continue) != 0 { @@ -1976,8 +1991,9 @@ func TestListInconsistentContinuation(t *testing.T) { options := storage.ListOptions{ ResourceVersion: "0", Predicate: pred(1, ""), + Recursive: true, } - if err := store.List(ctx, "/", options, out); err != nil { + if err := store.GetList(ctx, "/", options, out); err != nil { t.Fatalf("Unable to get initial list: %v", err) } if len(out.Continue) == 0 { @@ -2021,8 +2037,9 @@ func TestListInconsistentContinuation(t *testing.T) { options = storage.ListOptions{ ResourceVersion: "0", Predicate: pred(0, continueFromSecondItem), + Recursive: true, } - err = store.List(ctx, "/", options, out) + err = store.GetList(ctx, "/", options, out) if err == nil { t.Fatalf("unexpected no error") } @@ -2042,8 +2059,9 @@ func TestListInconsistentContinuation(t *testing.T) { options = storage.ListOptions{ ResourceVersion: "0", Predicate: pred(1, inconsistentContinueFromSecondItem), + Recursive: true, } - if err := store.List(ctx, "/", options, out); err != nil { + if err := store.GetList(ctx, "/", options, out); err != nil { t.Fatalf("Unable to get second page: %v", err) } if len(out.Continue) == 0 { @@ -2060,8 +2078,9 @@ func TestListInconsistentContinuation(t *testing.T) { options = storage.ListOptions{ ResourceVersion: "0", Predicate: pred(1, continueFromThirdItem), + Recursive: true, } - if err := store.List(ctx, "/", options, out); err != nil { + if err := store.GetList(ctx, "/", options, out); err != nil { t.Fatalf("Unable to get second page: %v", err) } if len(out.Continue) != 0 { @@ -2316,8 +2335,9 @@ func TestConsistentList(t *testing.T) { result1 := example.PodList{} options := storage.ListOptions{ Predicate: predicate, + Recursive: true, } - if err := store.List(ctx, "/", options, &result1); err != nil { + if err := store.GetList(ctx, "/", options, &result1); err != nil { t.Fatalf("failed to list objects: %v", err) } @@ -2326,10 +2346,11 @@ func TestConsistentList(t *testing.T) { Predicate: predicate, ResourceVersion: result1.ResourceVersion, ResourceVersionMatch: metav1.ResourceVersionMatchExact, + Recursive: true, } result2 := example.PodList{} - if err := store.List(ctx, "/", options, &result2); err != nil { + if err := store.GetList(ctx, "/", options, &result2); err != nil { t.Fatalf("failed to list objects: %v", err) } @@ -2341,7 +2362,7 @@ func TestConsistentList(t *testing.T) { options.ResourceVersionMatch = metav1.ResourceVersionMatchNotOlderThan result3 := example.PodList{} - if err := store.List(ctx, "/", options, &result3); err != nil { + if err := store.GetList(ctx, "/", options, &result3); err != nil { t.Fatalf("failed to list objects: %v", err) } @@ -2349,7 +2370,7 @@ func TestConsistentList(t *testing.T) { options.ResourceVersionMatch = metav1.ResourceVersionMatchExact result4 := example.PodList{} - if err := store.List(ctx, "/", options, &result4); err != nil { + if err := store.GetList(ctx, "/", options, &result4); err != nil { t.Fatalf("failed to list objects: %v", err) } diff --git a/staging/src/k8s.io/apiserver/pkg/storage/interfaces.go b/staging/src/k8s.io/apiserver/pkg/storage/interfaces.go index feda90e9f03..6e77ea700db 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/interfaces.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/interfaces.go @@ -183,24 +183,20 @@ type Interface interface { // and send it in an "ADDED" event, before watch starts. Watch(ctx context.Context, key string, opts ListOptions) (watch.Interface, error) - // Get unmarshals json found at key into objPtr. On a not found error, will either + // Get unmarshals object found at key into objPtr. On a not found error, will either // return a zero object of the requested type, or an error, depending on 'opts.ignoreNotFound'. // Treats empty responses and nil response nodes exactly like a not found error. // The returned contents may be delayed, but it is guaranteed that they will // match 'opts.ResourceVersion' according 'opts.ResourceVersionMatch'. Get(ctx context.Context, key string, opts GetOptions, objPtr runtime.Object) error - // GetToList unmarshals json found at key and opaque it into *List api object - // (an object that satisfies the runtime.IsList definition). + // GetList unmarshalls objects found at key into a *List api object (an object + // that satisfies runtime.IsList definition). + // If 'opts.Recursive' is false, 'key' is used as an exact match. If `opts.Recursive' + // is true, 'key' is used as a prefix. // The returned contents may be delayed, but it is guaranteed that they will // match 'opts.ResourceVersion' according 'opts.ResourceVersionMatch'. - GetToList(ctx context.Context, key string, opts ListOptions, listObj runtime.Object) error - - // List unmarshalls jsons found at directory defined by key and opaque them - // into *List api object (an object that satisfies runtime.IsList definition). - // The returned contents may be delayed, but it is guaranteed that they will - // match 'opts.ResourceVersion' according 'opts.ResourceVersionMatch'. - List(ctx context.Context, key string, opts ListOptions, listObj runtime.Object) error + GetList(ctx context.Context, key string, opts ListOptions, listObj runtime.Object) error // GuaranteedUpdate keeps calling 'tryUpdate()' to update key 'key' (of type 'ptrToType') // retrying the update until success if there is index conflict. @@ -265,8 +261,8 @@ type ListOptions struct { ResourceVersionMatch metav1.ResourceVersionMatch // Predicate provides the selection rules for the list operation. Predicate SelectionPredicate - // Recursive determines whether the watch is defined for a single object or for the whole set - // of objects. The option is ignored for non-watch requests. + // Recursive determines whether the list or watch is defined for a single object located at the + // given key, or for the whole set of objects with the given key as a prefix. Recursive bool // ProgressNotify determines whether storage-originated bookmark (progress notify) events should // be delivered to the users. The option is ignored for non-watch requests. diff --git a/staging/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go b/staging/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go index 791f63825f0..93bea21fc1a 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go @@ -196,7 +196,7 @@ func TestGet(t *testing.T) { } } -func TestGetToList(t *testing.T) { +func TestGetListNonRecursive(t *testing.T) { server, etcdStorage := newEtcdTestStorage(t, etcd3testing.PathPrefix()) defer server.Terminate(t) cacher, _, err := newTestCacher(etcdStorage) @@ -212,15 +212,15 @@ func TestGetToList(t *testing.T) { key string pred storage.SelectionPredicate expectedOut []*example.Pod - }{{ // test GetToList on existing key + }{{ // test non-recursive GetList on existing key key: key, pred: storage.Everything, expectedOut: []*example.Pod{storedObj}, - }, { // test GetToList on non-existing key + }, { // test non-recursive GetList on non-existing key key: "/non-existing", pred: storage.Everything, expectedOut: nil, - }, { // test GetToList with matching pod name + }, { // test non-recursive GetList with matching pod name key: "/non-existing", pred: storage.SelectionPredicate{ Label: labels.Everything(), @@ -235,9 +235,9 @@ func TestGetToList(t *testing.T) { for i, tt := range tests { out := &example.PodList{} - err := cacher.GetToList(context.TODO(), tt.key, storage.ListOptions{Predicate: tt.pred}, out) + err := cacher.GetList(context.TODO(), tt.key, storage.ListOptions{Predicate: tt.pred, Recursive: false}, out) if err != nil { - t.Fatalf("GetToList failed: %v", err) + t.Fatalf("GetList failed: %v", err) } if len(out.ResourceVersion) == 0 { t.Errorf("#%d: unset resourceVersion", i) @@ -293,8 +293,9 @@ func TestList(t *testing.T) { rvResult := &example.PodList{} options := storage.ListOptions{ Predicate: storage.Everything, + Recursive: true, } - if err := cacher.List(context.TODO(), "pods/ns", options, rvResult); err != nil { + if err := cacher.GetList(context.TODO(), "pods/ns", options, rvResult); err != nil { t.Errorf("Unexpected error: %v", err) } deletedPodRV := rvResult.ListMeta.ResourceVersion @@ -305,8 +306,9 @@ func TestList(t *testing.T) { options = storage.ListOptions{ ResourceVersion: deletedPodRV, Predicate: storage.Everything, + Recursive: true, } - if err := cacher.List(context.TODO(), "pods/ns", options, result); err != nil { + if err := cacher.GetList(context.TODO(), "pods/ns", options, result); err != nil { t.Errorf("Unexpected error: %v", err) } if result.ListMeta.ResourceVersion != deletedPodRV { @@ -371,8 +373,9 @@ func TestTooLargeResourceVersionList(t *testing.T) { options := storage.ListOptions{ ResourceVersion: listRV, Predicate: storage.Everything, + Recursive: true, } - err = cacher.List(context.TODO(), "pods/ns", options, result) + err = cacher.GetList(context.TODO(), "pods/ns", options, result) if !errors.IsTimeout(err) { t.Errorf("Unexpected error: %v", err) } @@ -408,12 +411,12 @@ type injectListError struct { storage.Interface } -func (self *injectListError) List(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error { +func (self *injectListError) GetList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error { if self.errors > 0 { self.errors-- return fmt.Errorf("injected error") } - return self.Interface.List(ctx, key, opts, listObj) + return self.Interface.GetList(ctx, key, opts, listObj) } func TestWatch(t *testing.T) { diff --git a/test/integration/apiserver/apiserver_test.go b/test/integration/apiserver/apiserver_test.go index eeb67f900dd..02ca413203f 100644 --- a/test/integration/apiserver/apiserver_test.go +++ b/test/integration/apiserver/apiserver_test.go @@ -561,7 +561,7 @@ func testListOptionsCase(t *testing.T, rsClient appsv1.ReplicaSetInterface, watc } count := int64(len(items)) - // Cacher.GetToList defines this for logic to decide if the watch cache is skipped. We need to know it to know if + // Cacher.GetList defines this for logic to decide if the watch cache is skipped. We need to know it to know if // the limit is respected when testing here. pagingEnabled := utilfeature.DefaultFeatureGate.Enabled(features.APIListChunking) hasContinuation := pagingEnabled && len(opts.Continue) > 0