Skip to content

Bug: multi_namespace_cache List() method accumulates results across subsequent calls #3194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zxh326 opened this issue Apr 10, 2025 · 0 comments · May be fixed by #3195
Open

Bug: multi_namespace_cache List() method accumulates results across subsequent calls #3194

zxh326 opened this issue Apr 10, 2025 · 0 comments · May be fixed by #3195

Comments

@zxh326
Copy link

zxh326 commented Apr 10, 2025

Problem

When using the controller-runtime cache with DefaultNamespaces configured (via ctrl.Options.NewCache), the List() method causes results to accumulate. Each subsequent call to List() includes the results from previous calls, causing the result set to continuously grow.

Steps to Reproduce

  1. Create a cache with DefaultNamespaces configuration:
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
    NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
        opts.DefaultNamespaces = map[string]cache.Config{
            "default": {},
        }
        return cache.New(config, opts)
    },
})
  1. Repeatedly call the List() method in a loop:
pods := &corev1.PodList{}
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()
for {
    select {
    case <-ctx.Done():
        t.Fatal("timeout")
    default:
        err := c.List(ctx, pods)
        // Examine pods.Items length - it grows with each call
    }
}

Each call to List() should return the current state of resources, not accumulate previous results. The result set should be reset and then populated with the current state of resources.

  • version: v0.20.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant