From e4550b54cc8eec7e4e18fbc24e830ee7f305fd84 Mon Sep 17 00:00:00 2001 From: Xuhui zhang Date: Fri, 11 Apr 2025 13:34:29 +0800 Subject: [PATCH 1/2] fix: prevent list accumulation in multi-namespace cache implementation Signed-off-by: Xuhui zhang --- pkg/cache/multi_namespace_cache.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/cache/multi_namespace_cache.go b/pkg/cache/multi_namespace_cache.go index 525d93e0ab..d7d7b0e7c2 100644 --- a/pkg/cache/multi_namespace_cache.go +++ b/pkg/cache/multi_namespace_cache.go @@ -279,10 +279,7 @@ func (c *multiNamespaceCache) List(ctx context.Context, list client.ObjectList, return err } - allItems, err := apimeta.ExtractList(list) - if err != nil { - return err - } + allItems := []runtime.Object{} limitSet := listOpts.Limit > 0 From 106b1d090a35915ae2a3110f389ce6b92ac3a140 Mon Sep 17 00:00:00 2001 From: Xuhui zhang Date: Mon, 12 May 2025 22:38:27 +0800 Subject: [PATCH 2/2] Add test Signed-off-by: Xuhui zhang --- pkg/cache/cache_test.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/cache/cache_test.go b/pkg/cache/cache_test.go index 9efd04877c..4509950fe7 100644 --- a/pkg/cache/cache_test.go +++ b/pkg/cache/cache_test.go @@ -1035,13 +1035,15 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca Version: "v1", Kind: "PodList", }) - 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)) + 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)) + } } By("listing all nodes - should still be able to list a cluster-scoped resource") nodeList := &unstructured.UnstructuredList{}