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

FIX PR #98 -- advanced node taint querying #113

Merged
merged 10 commits into from
Feb 7, 2024

Conversation

isaacnboyd
Copy link
Contributor

PR #98 required:

  • Rebasing Add support for node taints #98 branch on main and resolving numerous conflicts, especially in the capacity tests (please review)
  • Cleaning lint (no return value on splitTaint() and goformatting)
  • Testing new feature and adding instructions in README

resolves #91
closes #98

Copy link
Owner

@robscott robscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @isaacnboyd!

@@ -59,7 +60,103 @@ func FetchAndPrint(showContainers, showPods, showUtil, showPodCount, excludeTain
printList(&cm, showContainers, showPods, showUtil, showPodCount, showNamespace, output, sortBy, availableFormat)
}

func getPodsAndNodes(clientset kubernetes.Interface, excludeTainted bool, podLabels, nodeLabels, namespaceLabels, namespace string) (*corev1.PodList, *corev1.NodeList) {
// Taints can have two possible formats, key1:effect or key1=value1:effect. This function handles both formats and returns each part as a separate string for comparison.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'm used to function comments starting with the name of the function in golang, would recommend using that pattern throughout. Would also slightly prefer wrapping comment lines at 80 chars, but I don't think I've done great at following that here, it's just a common pattern in k8s projects.

README.md Outdated
@@ -131,6 +131,27 @@ kube-capacity --namespace-labels team=api
kube-capacity --node-labels kubernetes.io/role=node
```

### Filtering By Taints
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding docs to the readme, this is really great! One tiny suggestion would be to use "Node Taints" instead of just "Taints"

Suggested change
### Filtering By Taints
### Filtering By Node Taints

@@ -59,7 +60,103 @@ func FetchAndPrint(showContainers, showPods, showUtil, showPodCount, excludeTain
printList(&cm, showContainers, showPods, showUtil, showPodCount, showNamespace, output, sortBy, availableFormat)
}

func getPodsAndNodes(clientset kubernetes.Interface, excludeTainted bool, podLabels, nodeLabels, namespaceLabels, namespace string) (*corev1.PodList, *corev1.NodeList) {
// Taints can have two possible formats, key1:effect or key1=value1:effect. This function handles both formats and returns each part as a separate string for comparison.
func splitTaint(taint string) (string, string, string) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use one of the the k8s helper functions instead here? Maybe something like this https://github.com/kubernetes/kubernetes/blob/a07b1aaa5b39b351ec8586de800baa5715304a3f/pkg/apis/core/helper/helpers.go#L428 or https://github.com/kubernetes/kubernetes/blob/a07b1aaa5b39b351ec8586de800baa5715304a3f/pkg/util/taints/taints.go#L91. I know those might not be quite a perfect fit, but maybe there's something along those lines that could help. Also in case it's ever helpful cs.k8s.io is a k8s-wide codesearch that helps find if helper functions like this already exist - that's what I used here fwiw.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh cs.k8s.io is nifty! I'll have to do some digging there.

Apparently you can create node taints that have no value. Like kubectl taint nodes foo bar:NoSchedule
as opposed to a k/v taint like kubectl taint nodes foo dedicated=special-user:NoSchedule.
That's what this function is handling. Those 2 possible taint expressions.

I'll look around and see what's been built.

Copy link
Contributor Author

@isaacnboyd isaacnboyd Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right ParseTaints() helper function can be a replacement for splitTaint(), it will change the user syntax from kube-capacity --node-taints !node.kubernetes.io/unschedulable:NoSchedule to a more familiar syntax kube-capacity --node-taints node.kubernetes.io/unschedulable:NoSchedule- with the - denoting removing a taint instead of !.

I think that's a valuable addition I'll try to get this added in the next few days.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

splitTaint() has been replaced with k8s helper function ParseTaint(). See 903bc98


if nodeTaints != "" {
taintedNodeList := *nodeList
taintedNmList := removeNodeMetricsWithTaints(nmList, taintedNodeList)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a dumb question, but if we're just doing a join with the nodes later, and we're already removing the nodes that are tainted separately, do we need to actually remove the node metrics? I'd thought that might just automatically happen if corresponding nodes didn't exist, but it's been awhile since I've worked with this code.

Copy link
Contributor Author

@isaacnboyd isaacnboyd Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you are correct. I tested kube-capactiy -t <taint key>=<taint value>:<taint effect> --util with and without this block of code and the results are the same.

See 903bc98

@isaacnboyd isaacnboyd changed the title FIX PR #98 FIX PR #98 -- advanced node taint querying Jan 22, 2024
@isaacnboyd isaacnboyd force-pushed the FIX-PR-#98 branch 3 times, most recently from 10e1325 to 557f5cd Compare January 22, 2024 15:24
@robscott
Copy link
Owner

Hey @isaacnboyd, let me know if you think you'll have some time to work on this in the next week or so. Largely thanks to all your great improvements, I think it's probably close to time to cut another release (probably v0.8.0), but don't want this to miss the cut if you've got plans to work on it sometime soon.

@isaacnboyd
Copy link
Contributor Author

Hey @isaacnboyd, let me know if you think you'll have some time to work on this in the next week or so. Largely thanks to all your great improvements, I think it's probably close to time to cut another release (probably v0.8.0), but don't want this to miss the cut if you've got plans to work on it sometime soon.

Hey howdy Rob, yes I'd like to get this one into the release. I should be able to find some time to work on it here in the next few days.

@isaacnboyd isaacnboyd force-pushed the FIX-PR-#98 branch 3 times, most recently from 7605696 to 05cdc41 Compare January 26, 2024 19:57
@robscott
Copy link
Owner

Thanks @isaacnboyd! Just let me know whenever it's ready for another round of review (or if it already is).

Testing with --util shows additional removal of tainted node metrics
to be unnecessary
@isaacnboyd isaacnboyd force-pushed the FIX-PR-#98 branch 2 times, most recently from 3900024 to 903bc98 Compare January 31, 2024 14:57
Use k8s helper function to parse taints with familiar syntax.
In order to parse a node, kube-capacity
requires at least a key and effect.
It will also handle key,value, and effect taints.
taints can be referenced by key=value:effect
and by key:effect
@isaacnboyd
Copy link
Contributor Author

Thanks @isaacnboyd! Just let me know whenever it's ready for another round of review (or if it already is).

Hey @robscott this is ready for another review.

@robscott
Copy link
Owner

robscott commented Feb 7, 2024

Thanks @isaacnboyd!

@robscott robscott merged commit 5e9ad1b into robscott:main Feb 7, 2024
3 checks passed
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 for node taints
3 participants