Skip to content

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

@zxh326

Description

@zxh326

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions