-
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
Move sortPodsBasedOnPriority to pod util #322
Move sortPodsBasedOnPriority to pod util #322
Conversation
Hi @lixiang233. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
pkg/descheduler/pod/pods_test.go
Outdated
var ( | ||
lowPriority = int32(0) | ||
highPriority = int32(10000) | ||
) | ||
|
||
func setHighPriority(pod *v1.Pod) { pod.Spec.Priority = &highPriority } | ||
func setLowPriority(pod *v1.Pod) { pod.Spec.Priority = &lowPriority } | ||
|
||
func makeBestEffortPod(pod *v1.Pod) { | ||
pod.Spec.Containers[0].Resources.Requests = nil | ||
pod.Spec.Containers[0].Resources.Requests = nil | ||
pod.Spec.Containers[0].Resources.Limits = nil | ||
pod.Spec.Containers[0].Resources.Limits = nil | ||
} | ||
|
||
func makeBurstablePod(pod *v1.Pod) { | ||
pod.Spec.Containers[0].Resources.Limits = nil | ||
pod.Spec.Containers[0].Resources.Limits = nil | ||
} | ||
|
||
func makeGuaranteedPod(pod *v1.Pod) { | ||
pod.Spec.Containers[0].Resources.Limits[v1.ResourceCPU] = pod.Spec.Containers[0].Resources.Requests[v1.ResourceCPU] | ||
pod.Spec.Containers[0].Resources.Limits[v1.ResourceMemory] = pod.Spec.Containers[0].Resources.Requests[v1.ResourceMemory] | ||
} | ||
|
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.
Should I move these to test util? @ingvagabund @seanmalloy
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.
@lixiang233 yes, in my opinion I think it would be good to have makeGuaranteedPod
, makeBurstablePod
and makeBestEffortPod
in test/test_utils.go
/ok-to-test @lixiang233 I think the code change look pretty good. I just have two questions. Are you planning to update the You mentioned in #294 that the documentation in the Pod Evictions section of the README is not quite accurate because only the |
d4b1ee6
to
17b732f
Compare
Changed test util and README. I'm willing to work on sorting pods in |
// SortPodsBasedOnPriorityLowToHigh sorts pods based on their priorities from low to high. | ||
// If pods have same priorities, they will be sorted by QoS in the following order: | ||
// BestEffort, Burstable, Guaranteed | ||
func SortPodsBasedOnPriorityLowToHigh(pods []*v1.Pod) { |
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.
What about to have:
func PodComparePriorityLowToHigh(i, j int) bool {
if pods[i].Spec.Priority == nil && pods[j].Spec.Priority != nil {
return true
}
if pods[j].Spec.Priority == nil && pods[i].Spec.Priority != nil {
return false
}
if (pods[j].Spec.Priority == nil && pods[i].Spec.Priority == nil) || (*pods[i].Spec.Priority == *pods[j].Spec.Priority) {
if IsBestEffortPod(pods[i]) {
return true
}
if IsBurstablePod(pods[i]) && IsGuaranteedPod(pods[j]) {
return true
}
return false
}
return *pods[i].Spec.Priority < *pods[j].Spec.Priority
}
instead and replace all invocations of SortPodsBasedOnPriorityLowToHigh
with sort.Slice(pods, PodComparePriorityLowToHigh
? So the implementation is minimal and the function can be used by other sort.Slice* functions. E.g. SliceIsSorted
or SliceStable
.
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 implementation looks like less func of QueueSortPlugin, as func in Slice(slice interface{}, less func(i, j int)
only receives two int params, we may implement and use it like:
func PodComparePriorityLowToHigh(i, j pod) bool {...}
sort.Slice(pods, func(i, j int) bool {
return PodComparePriorityLowToHigh(pod[i], pod[j])
}
That looks a little complex, besides I think pod util
should provide a sort func
and not only a less func
, maybe we can provide both and refactor sort func
like:
func PodComparePriorityLowToHigh(i, j pod) bool {...}
func SortPodsBasedOnPriorityLowToHigh(pods []*v1.Pod) {
sort.Slice(pods, func(i, j int) bool {
return PodComparePriorityLowToHigh(pod[i], pod[j])
}
}
What do you think @ingvagabund ?
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.
Sorry about that. Yeah, you are right. Too much lambda calculus in my head :) We can elaborate on that later once we have more callers of the same "less" implementation for sorting.
@@ -52,23 +50,6 @@ func setHighPriority(pod *v1.Pod) { pod.Spec.Priority = &highPriority } | |||
func setLowPriority(pod *v1.Pod) { pod.Spec.Priority = &lowPriority } | |||
func setNodeUnschedulable(node *v1.Node) { node.Spec.Unschedulable = true } |
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.
There's nothing specific to LowNodeUtilization strategy about these helper functions. You can move all of them under test/test_utils.go
as well.
Updated, I think |
@lixiang233 can you put all the helpers function moved to the same commit? Two commits are more preferable here: 1 for moving the helper functions, 1 for moving the sort function. |
7084bd0
to
7b27c7f
Compare
Completed. @ingvagabund |
/lgtm |
@lixiang233 just a nit. Can you switch order of the commits so the helpers are not copied into pkg/descheduler/pod/pods_test.go and then removed in the next? Othwerwise, lgtm, |
7b27c7f
to
43525f6
Compare
switched. @ingvagabund |
@lixiang233 perfect, thanks!!! |
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.
There's nothing wrong with this change itself, but without applying the change to other strategies as mentioned in #294 this PR doesn't really do much.
I think moving sortPodsBasedOnPriority
is just a part of a whole PR which would use that function in other strategies. So I would like to see the rest of #294 implemented here (for at least a couple strategies), so that we can see the whole outcome of this change (and what it is intended to provide). Moving the function alone doesn't necessitate its own PR
I'm planning to work on What do you think @damemi ? |
@lixiang233 that sounds good to me, feel free to add the changes for multi-pods in a new commit. Thanks! I definitely agree that we don't need to make too many changes at once, I just felt like we could have a little more here to show the ultimate goal. |
Changed |
ba93a6d
to
65a03e7
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.
This looks good to me, I think the separate commits make sense here but if anyone prefers to squash I wouldn't mind that either.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: damemi, lixiang233 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 |
This looks good to me. Travis CI still seems to be flaky, so the e2e tests did not run. Someone should run the e2e tests on their laptop before this is merged. |
/lgtm I was able to run the e2e tests on my laptop using k8s 1.18.2 ...
|
Move sortPodsBasedOnPriority to pod util
As #294 mentioned, we may need to sort pods in other strategies, so I moved this func to pod util.