Skip to content

Commit bd600cf

Browse files
authored
⚠ fix: Stop accumulating lists in multi-namespace cache implementation (#3195)
* fix: prevent list accumulation in multi-namespace cache implementation Signed-off-by: Xuhui zhang <xuhui@juicedata.io> * Add test Signed-off-by: Xuhui zhang <xuhui@juicedata.io> --------- Signed-off-by: Xuhui zhang <xuhui@juicedata.io>
1 parent f87e9da commit bd600cf

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

pkg/cache/cache_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,13 +1035,15 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
10351035
Version: "v1",
10361036
Kind: "PodList",
10371037
})
1038-
Expect(namespacedCache.List(context.Background(), out)).To(Succeed())
1039-
1040-
By("verifying the returned pod is from the watched namespace")
1041-
Expect(out.Items).NotTo(BeEmpty())
1042-
Expect(out.Items).Should(HaveLen(2))
1043-
for _, item := range out.Items {
1044-
Expect(item.GetNamespace()).To(Equal(testNamespaceOne))
1038+
for range 2 {
1039+
Expect(namespacedCache.List(context.Background(), out)).To(Succeed())
1040+
1041+
By("verifying the returned pod is from the watched namespace")
1042+
Expect(out.Items).NotTo(BeEmpty())
1043+
Expect(out.Items).Should(HaveLen(2))
1044+
for _, item := range out.Items {
1045+
Expect(item.GetNamespace()).To(Equal(testNamespaceOne))
1046+
}
10451047
}
10461048
By("listing all nodes - should still be able to list a cluster-scoped resource")
10471049
nodeList := &unstructured.UnstructuredList{}

pkg/cache/multi_namespace_cache.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,7 @@ func (c *multiNamespaceCache) List(ctx context.Context, list client.ObjectList,
279279
return err
280280
}
281281

282-
allItems, err := apimeta.ExtractList(list)
283-
if err != nil {
284-
return err
285-
}
282+
allItems := []runtime.Object{}
286283

287284
limitSet := listOpts.Limit > 0
288285

0 commit comments

Comments
 (0)