-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I see |
||
if resourceName == v1.ResourceCPU { | ||
ti += nodes[i].usage[resourceName].MilliValue() | ||
} else { | ||
ti += nodes[i].usage[resourceName].Value() | ||
} | ||
} | ||
for resourceName := range nodes[j].usage { | ||
if resourceName == v1.ResourceCPU { | ||
tj += nodes[j].usage[resourceName].MilliValue() | ||
} 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
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 ;)