Skip to content

refactor(multicache): use controller-runtime DefaultNamespaces - #9412

Open
armru wants to merge 2 commits into
mainfrom
dev/5688
Open

armru wants to merge 2 commits into
mainfrom
dev/5688

Conversation

@armru

@armru armru commented Dec 12, 2025 •

Copy link
Copy Markdown
Member

Replace the custom multinamespace watcher (pkg/multicache) with
cache.Options.DefaultNamespaces from controller-runtime. The operator
namespace is always added to the watched set so that resources shared
across tenants remain cached.

Closes #5688

@armru
armru requested review from a team and Copilot December 12, 2025 13:34
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Dec 12, 2025
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 release-1.28 labels Dec 12, 2025
@github-actions

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

@dosubot dosubot Bot added the chore Intangible work to reduce technical debt label Dec 12, 2025
@armru

armru commented Dec 12, 2025

Copy link
Copy Markdown
Member Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the namespace watching functionality by removing the custom pkg/multicache implementation and replacing it with controller-runtime's built-in cache.Options.DefaultNamespaces feature. This simplification leverages upstream functionality instead of maintaining custom cache delegation logic.

Key Changes

  • Removed the entire custom pkg/multicache package that implemented a delegating multi-namespace cache with separate internal and external caches
  • Introduced getNamespacesToWatch() function that builds a namespace map for controller-runtime's built-in multi-namespace cache support
  • Added comprehensive unit tests for the new namespace configuration logic

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/multicache/multinamespaced_cache.go Removed custom cache implementation that delegated between watched namespaces and external resources
internal/cmd/manager/controller/controller.go Replaced multicache usage with built-in cache options and added helper function to configure watched namespaces
internal/cmd/manager/controller/controller_test.go Added comprehensive tests for namespace configuration including edge cases for whitespace and duplicate handling
internal/cmd/manager/controller/suite_test.go Added Ginkgo test suite setup for controller tests

namespaces[namespace] = cache.Config{}
}

setupLog.Info("Listening for changes", "watchNamespaces", conf.WatchedNamespaces())

Copilot AI Dec 12, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log message doesn't accurately reflect all namespaces being watched. The function adds the operator namespace to the map (line 492-494), but this log only shows the result of WatchedNamespaces(), which may not include the operator namespace. This could be misleading when debugging or monitoring the operator's behavior. Consider logging all keys from the namespaces map instead to show the complete set of watched namespaces.

Suggested change
setupLog.Info("Listening for changes", "watchNamespaces", conf.WatchedNamespaces())
// Log all namespaces being watched, including the operator namespace
watchedNamespaces := make([]string, 0, len(namespaces))
for ns := range namespaces {
watchedNamespaces = append(watchedNamespaces, ns)
}
setupLog.Info("Listening for changes", "watchNamespaces", watchedNamespaces)

Copilot uses AI. Check for mistakes.
armru and others added 2 commits April 17, 2026 19:38
…me DefaultNamespaces

Replace the custom multinamespace watcher implementation (pkg/multicache)
with the built-in cache.Options.DefaultNamespaces from controller-runtime.

Signed-off-by: Armando Ruocco <[email protected]>
Guard on the parsed namespaces list instead of the raw string, so a
value like ",, ," still results in a nil DefaultNamespaces map and a
cluster-wide watch, matching the prior custom-multicache behavior.
Controller-runtime gates namespaced vs cluster-wide scope on
len(DefaultNamespaces) > 0, so seeding the map with the operator
namespace before the emptiness check silently scoped the cache to
just that namespace.

Also log the effective watched set (including the operator namespace),
sorted for deterministic output across map-iteration randomization.

Assisted-by: Claude
Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia mnencia changed the title refactor: replace custom multicache with controller-runtime multicache refactor(multicache): use controller-runtime DefaultNamespaces Apr 17, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 17, 2026
@mnencia

mnencia commented Apr 17, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

@bergdavi

Copy link
Copy Markdown

Hi @armru, @mnencia

Are you planning to merge this change in the foreseeable future? I'm looking into some potential solutions for #10924, which impacts the same part of the code. I'm asking if I should consider any potential fix on top of this PR, or on top of the latest main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases chore Intangible work to reduce technical debt lgtm This PR has been approved by a maintainer ok to merge 👌 This PR can be merged release-1.28 release-1.30 size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Chore]: use builtin multi namespace watcher

5 participants