-
Notifications
You must be signed in to change notification settings - Fork 669
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
Update nodes sorting function to respect available resources #1541
Conversation
02b7f90
to
7eeb07d
Compare
[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 |
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 { |
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.
Shouldn't this block be now removed, so we do not count the other resources twice?
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.
@@ -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() |
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.
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 { |
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.
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?
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.
We have not explored this avenue. It's still open for debate.
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 see
So
sortNodesByUsage
can be invoked over any list of resources