Skip to content

Conversation

@Serializator
Copy link

What this PR does / why we need it:
Add support for dynamic namespace discovery. This allows the user to filter namespaces by label, providing more dynamic and granular control over what namespaces to watch.

This is a work in progress but I'd really appreciate early feedback.

The most impactful change is actually the refactoring of the metrics store to filter objects by their namespace at the event handler level instead of starting a dedicated reflector per namespace.

I'd love feedback on this approach. Performance-wise this reduces the number of events being handled concurrently at any point in time as there is one goroutine per resource instead of per resource and namespace.

The counter-part is a goroutine per resource and namespace. With dynamic namespace discovery instead of a static list, there will be rate limiting at the API level due to the design of one reflector (list & watch) per namespace.

How does this change affect the cardinality of KSM:
No change.

Which issue(s) this PR fixes:
Fixes #2820

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 1, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Serializator
Once this PR has been reviewed and has the lgtm label, please assign mrueg for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 1, 2026
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If kube-state-metrics contributors determine this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Feb 1, 2026
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG Instrumentation Feb 1, 2026
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Feb 1, 2026
@Serializator Serializator changed the title [WIP] Issue 2820 dynamic namespaces [WIP] Support dynamic namespace discovery Feb 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

Dynamic namespace filtering

2 participants