diff --git a/pkg/cache/cache_test.go b/pkg/cache/cache_test.go index 4509950fe7..9efd04877c 100644 --- a/pkg/cache/cache_test.go +++ b/pkg/cache/cache_test.go @@ -1035,15 +1035,13 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca Version: "v1", Kind: "PodList", }) - for range 2 { - Expect(namespacedCache.List(context.Background(), out)).To(Succeed()) - - By("verifying the returned pod is from the watched namespace") - Expect(out.Items).NotTo(BeEmpty()) - Expect(out.Items).Should(HaveLen(2)) - for _, item := range out.Items { - Expect(item.GetNamespace()).To(Equal(testNamespaceOne)) - } + Expect(namespacedCache.List(context.Background(), out)).To(Succeed()) + + By("verifying the returned pod is from the watched namespace") + Expect(out.Items).NotTo(BeEmpty()) + Expect(out.Items).Should(HaveLen(2)) + for _, item := range out.Items { + Expect(item.GetNamespace()).To(Equal(testNamespaceOne)) } By("listing all nodes - should still be able to list a cluster-scoped resource") nodeList := &unstructured.UnstructuredList{} diff --git a/pkg/cache/multi_namespace_cache.go b/pkg/cache/multi_namespace_cache.go index d7d7b0e7c2..525d93e0ab 100644 --- a/pkg/cache/multi_namespace_cache.go +++ b/pkg/cache/multi_namespace_cache.go @@ -279,7 +279,10 @@ func (c *multiNamespaceCache) List(ctx context.Context, list client.ObjectList, return err } - allItems := []runtime.Object{} + allItems, err := apimeta.ExtractList(list) + if err != nil { + return err + } limitSet := listOpts.Limit > 0