robscott / kube-capacity

A simple CLI that provides an overview of the resource requests, limits, and utilization in a Kubernetes cluster
Apache License 2.0
2.11k stars 114 forks source link

Cannot use `--pods` and `-n` namespace filtering together #38

Closed Dentrax closed 3 years ago

Dentrax commented 3 years ago

$ kubectl resource-capacity --pods shows too many pods, so I want to filter those with a given namespace-labels argument. If you try this: $ kubectl resource-capacity --pods -n kube-system, it shows all empty for some reason. What I expect is that it should gather the exact same values in the previous run and should list only the given namespace. But It prints * in the NAMESPACE column, not kube-system.

Screen Shot 2021-01-28 at 17 35 16 Screen Shot 2021-01-28 at 17 36 19
robscott commented 3 years ago

Thanks for raising this issue @Dentrax! This is a very confusing part of kube-capacity and I think I should probably add support for a proper --namespace flag and repurpose the shorthand -n to map to it. As it is now, -n maps to --namespace-labels. If you label a namespace or set of namespaces (kubectl label ns kube-system test=foo ), you can then query them like this:

kube-capacity -n test=foo --pods --util

If the selector does not match anything, kube-capacity shows the unfortunate output you're seeing above. Although that's a bug, it seems like the biggest priority should be to add support for a --namespace label to work as expected here. Unfortunately I'm pretty underwater right now so not sure how soon I'll be able to get to this. If anyone happens to have any free cycles, contributions are always appreciated :)

Dentrax commented 3 years ago

Thanks for the detailed explanation! It is a bit off to understand that we have to label specific namespace to do some filtering stuff, as you said. So are understanding differences between --namespace and --namespace-labels. Additionally to -n, --namespace-labels is another cool filtering feature, but we can handle that in another shorthand flag, i.e., -l, instead of replacing -n's default behavior. :)