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

Update nodes sorting function to respect available resources #1541

Conversation

ingvagabund
Copy link
Contributor

So sortNodesByUsage can be invoked over any list of resources

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 11, 2024
@ingvagabund ingvagabund force-pushed the sortNodesByUsage-dont-hardcode-resource-names branch from 02b7f90 to 7eeb07d Compare November 11, 2024 15:27
@ingvagabund ingvagabund added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 13, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 1e48cfe into kubernetes-sigs:master Nov 13, 2024
9 checks passed
@ingvagabund ingvagabund deleted the sortNodesByUsage-dont-hardcode-resource-names branch November 13, 2024 12:46
@ingvagabund
Copy link
Contributor Author

Conducting a self-review due to a limited availability of reviewers. However, contributors are still encouraged to perform a post-merge review to identify any additional improvements or to catch any potential regressions introduced by these changes. Your feedback, even after the merge, will help enhance the quality and robustness of the code.

} else {
tj += nodes[j].usage[resourceName].Value()
}
}

// extended resources
for name := range nodes[i].usage {

Choose a reason for hiding this comment

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

Shouldn't this block be now removed, so we do not count the other resources twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -368,8 +368,22 @@ func evictPods(
// sortNodesByUsage sorts nodes based on usage according to the given plugin.
func sortNodesByUsage(nodes []NodeInfo, ascending bool) {
sort.Slice(nodes, func(i, j int) bool {
ti := nodes[i].usage[v1.ResourceMemory].Value() + nodes[i].usage[v1.ResourceCPU].MilliValue() + nodes[i].usage[v1.ResourcePods].Value()
tj := nodes[j].usage[v1.ResourceMemory].Value() + nodes[j].usage[v1.ResourceCPU].MilliValue() + nodes[j].usage[v1.ResourcePods].Value()
ti := resource.NewQuantity(0, resource.DecimalSI).Value()

Choose a reason for hiding this comment

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

this seems like a quite elaborate way to declare int64 variable ;)

tj := nodes[j].usage[v1.ResourceMemory].Value() + nodes[j].usage[v1.ResourceCPU].MilliValue() + nodes[j].usage[v1.ResourcePods].Value()
ti := resource.NewQuantity(0, resource.DecimalSI).Value()
tj := resource.NewQuantity(0, resource.DecimalSI).Value()
for resourceName := range nodes[i].usage {

Choose a reason for hiding this comment

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

Offtopic: intriguing to see that all resources have the same weight. Not sure if it makes sense, but this is decided by the user when configuring it, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have not explored this avenue. It's still open for debate.

Choose a reason for hiding this comment

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

I see

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants