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

Add --exclude-node-labels flag #84

Closed
wants to merge 3 commits into from
Closed

Add --exclude-node-labels flag #84

wants to merge 3 commits into from

Conversation

yardenshoham
Copy link
Contributor

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%)

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:
```yaml
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
```shell
$ ./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`
```shell
$ ./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`
```shell
$ ./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`
```shell
$ ./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`
```shell
$ ./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%)
```

Signed-off-by: Yarden Shoham <hrsi88@gmail.com>
Signed-off-by: Yarden Shoham <hrsi88@gmail.com>
@yardenshoham yardenshoham marked this pull request as draft January 24, 2023 21:41
Signed-off-by: Yarden Shoham <hrsi88@gmail.com>
@yardenshoham
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support to exclude node labels
1 participant