Skip to content
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

Support namespace selector for filtering #2132

Open
cskinfill opened this issue Jul 31, 2023 · 6 comments
Open

Support namespace selector for filtering #2132

cskinfill opened this issue Jul 31, 2023 · 6 comments
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@cskinfill
Copy link

What would you like to be added:
Support using namespace selector for filtering which resources to acquire metrics for.

Why is this needed:
This would seem to fit more naturally into the kubernetes model of using selectors to select resources. Also, this makes it easier to select on namespaces that have a label, rather then trying to manage a list of namespace names.

Describe the solution you'd like
--namespace-selector workload=testme would select all namespaces with the label workload equal to the value testm.
Additional context

@cskinfill cskinfill added the kind/feature Categorizes issue or PR as related to a new feature. label Jul 31, 2023
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jul 31, 2023
@nerzhul
Copy link

nerzhul commented Aug 3, 2023

Hello,
I was about to ask the same thing. Where i work we are moving kube-state-metrics from a global instance to a per client instance, and i'd like to use a namespace selector to discard migrated clients from the global instance (like we can do with prometheus operator).
Is it possible ?

@dashpole
Copy link

/assign @dgrisonnet
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Aug 10, 2023
@buger

This comment was marked as spam.

@dgrisonnet
Copy link
Member

What you are proposing would be to add label selector rather than a namespace selector. We already have a namespace selector with the --namespaces option: https://github.com/kubernetes/kube-state-metrics/blob/main/pkg/options/options.go#L145

What you could do today to have a similar result would be to do:

kubectl get namespaces -l workload=testme

and append the list of namespaces to the --namespaces option of kube-state-metrics.

@AntoineNGUYEN31
Copy link

AntoineNGUYEN31 commented Oct 13, 2023

@dgrisonnet your solution works, but cannot be scaled especiallyon on a managed k8s cluster. Admin will be solliciated on very newly created important namespace, and it implies redeployement of the stack.

@Serializator
Copy link
Contributor

Just want to mention this here. This idea could help with #2400 as well. In a limited privilege environment this could help with only listing resources on namespaces the service account is privy too through the use of labels and selector at the namespace level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

No branches or pull requests

8 participants