-
Notifications
You must be signed in to change notification settings - Fork 118
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
Conversation
833790e
to
f71e65a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @isaacnboyd!
pkg/capacity/capacity.go
Outdated
@@ -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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"
### Filtering By Taints | |
### Filtering By Node Taints |
pkg/capacity/capacity.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
pkg/capacity/capacity.go
Outdated
|
||
if nodeTaints != "" { | ||
taintedNodeList := *nodeList | ||
taintedNmList := removeNodeMetricsWithTaints(nmList, taintedNodeList) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
10e1325
to
557f5cd
Compare
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. |
Lint is preventing the merge of PR robscott#98 Linter picked up no return value on splitTaint() And goformatting whitespace errors in capacity_test
7605696
to
05cdc41
Compare
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
3900024
to
903bc98
Compare
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
Hey @robscott this is ready for another review. |
Thanks @isaacnboyd! |
PR #98 required:
resolves #91
closes #98