Allow namespace exclusion on cluster-wide watch via label selector#9123
Allow namespace exclusion on cluster-wide watch via label selector#9123BobVanB wants to merge 12 commits intoelastic:mainfrom
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
🔍 Preview links for changed docs |
|
Thanks for this contribution and for picking up from #8893! The idea of making namespace scoping more dynamic is something we've heard interest in. However, after reviewing the implementation, I don't think we can move forward with this approach. Let me explain why. The core problem: filtering at the wrong layerThis implementation filters at the reconciler level — each controller fetches the resource, then fetches the Namespace object, checks labels, and returns early if they don't match. But the operator still watches all namespaces at the informer/cache level. This means:
For context, the existing Resource lifecycle risksReconciler-level filtering creates real operational hazards:
Functionally, this ends up being equivalent to a namespace-scoped version of the What we'd recommend insteadIf you need label-based namespace selection today, there are approaches that work with the existing operator:
If we were to build label-based namespace filtering into the operator itself, there are two approaches worth considering:
Code-level notesIn case it's useful context, there are also some implementation issues that would need addressing regardless of the architectural direction:
I hope this context is helpful. We appreciate you investing time in this — the underlying need is real, and I'd encourage exploring the external resolution approach (option 1 above) as a solution that works today without operator changes. |
✅ Vale Linting ResultsNo issues found on modified lines! The Vale linter checks documentation changes against the Elastic Docs style guide. To use Vale locally or report issues, refer to Elastic style guide for Vale. |
|
Thanks for the detailed review and for the clear guidance. You are right about the architectural concern: reconciler-level filtering alone does not reduce informer/event load. We agree that true filtering should happen at cache/watch scope where possible. On the code-level notes:
Direction we took after your feedback:
Final note: this new code is not running in our production environment yet, so it has not been live-tested in prod. |
1d09217 to
75ec3f5
Compare
Problem
Currently, an operator or controller can only:
This makes it difficult to run a cluster-wide watch while ignoring certain namespaces (e.g.,
kube-systemor internal namespaces).Solution
This change introduces:
This provides more flexibility and prevents unnecessary events from non-relevant namespaces.
Implementation
selector.Example
Start the operator with a namespace exclusion selector:
manager --namespace-label-selector='environment!=internal'Namespaces with the label
environment=internalwill be ignored by the operator.Benefits
Testing
Breaking Changes?
No, existing configurations continue to work. The new functionality is optional.