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.09k stars 114 forks source link

Add `--exclude-node-labels` flag #84

Closed yardenshoham closed 1 year ago

yardenshoham commented 1 year ago

Added a new flag --exclude-node-labels to exclude nodes with the provided label selector.

Behavior and examples

I'm testing with the following cluster configuration:

nodes:
- role: control-plane
  labels:
    color: red
- role: worker
  labels:
    color: red
    shape: square
- role: worker
  labels:
    color: red
- role: worker
  labels:
    shape: square

All nodes

$ ./kube-capacity 
NODE                 CPU REQUESTS   CPU LIMITS   MEMORY REQUESTS   MEMORY LIMITS
*                    1250m (2%)     400m (0%)    440Mi (1%)        540Mi (1%)
kind-control-plane   950m (7%)      100m (0%)    290Mi (3%)        390Mi (4%)
kind-worker          100m (0%)      100m (0%)    50Mi (0%)         50Mi (0%)
kind-worker2         100m (0%)      100m (0%)    50Mi (0%)         50Mi (0%)
kind-worker3         100m (0%)      100m (0%)    50Mi (0%)         50Mi (0%)

Only nodes with color=red

$ ./kube-capacity --node-labels color=red
NODE                 CPU REQUESTS   CPU LIMITS   MEMORY REQUESTS   MEMORY LIMITS
*                    1150m (3%)     300m (0%)    390Mi (1%)        490Mi (2%)
kind-control-plane   950m (7%)      100m (0%)    290Mi (3%)        390Mi (4%)
kind-worker          100m (0%)      100m (0%)    50Mi (0%)         50Mi (0%)
kind-worker2         100m (0%)      100m (0%)    50Mi (0%)         50Mi (0%)

Only nodes with shape=square

$ ./kube-capacity --node-labels shape=square
NODE           CPU REQUESTS   CPU LIMITS   MEMORY REQUESTS   MEMORY LIMITS
*              200m (0%)      200m (0%)    100Mi (0%)        100Mi (0%)
kind-worker    100m (0%)      100m (0%)    50Mi (0%)         50Mi (0%)
kind-worker3   100m (0%)      100m (0%)    50Mi (0%)         50Mi (0%)

Nodes with color=red, excluding those with shape=square

$ ./kube-capacity --node-labels color=red --exclude-node-labels shape=square
NODE                 CPU REQUESTS   CPU LIMITS   MEMORY REQUESTS   MEMORY LIMITS
*                    1050m (4%)     200m (0%)    340Mi (2%)        440Mi (2%)
kind-control-plane   950m (7%)      100m (0%)    290Mi (3%)        390Mi (4%)
kind-worker2         100m (0%)      100m (0%)    50Mi (0%)         50Mi (0%)

All nodes except those that have both color=red and shape=square

$ ./kube-capacity --exclude-node-labels color=red,shape=square
NODE                 CPU REQUESTS   CPU LIMITS   MEMORY REQUESTS   MEMORY LIMITS
*                    1150m (3%)     300m (0%)    390Mi (1%)        490Mi (2%)
kind-control-plane   950m (7%)      100m (0%)    290Mi (3%)        390Mi (4%)
kind-worker2         100m (0%)      100m (0%)    50Mi (0%)         50Mi (0%)
kind-worker3         100m (0%)      100m (0%)    50Mi (0%)         50Mi (0%)
yardenshoham commented 1 year ago

I now realize every example can work with native label selectors. For example:

$ ./kube-capacity --node-labels color=red,shape!=square
NODE                 CPU REQUESTS   CPU LIMITS   MEMORY REQUESTS   MEMORY LIMITS
*                    1050m (4%)     200m (0%)    340Mi (2%)        440Mi (2%)
kind-control-plane   950m (7%)      100m (0%)    290Mi (3%)        390Mi (4%)
kind-worker2         100m (0%)      100m (0%)    50Mi (0%)         50Mi (0%)

So I don't really see a reason for --exclude-node-labels.