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
[postfilter-impl-1] Refactor scheduler preempt interface #92009
Conversation
/assign @ahg-g |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Huang-Wei 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 |
3dd60a9
to
c7175b2
Compare
/retest |
/assign @ahg-g It's ready for review. |
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!
pkg/scheduler/util/utils.go
Outdated
func RemoveNominatedNodeName(cs kubernetes.Interface, pod *v1.Pod) error { | ||
if len(pod.Status.NominatedNodeName) == 0 { | ||
return nil | ||
} | ||
podCopy := pod.DeepCopy() | ||
podCopy.Status.NominatedNodeName = "" | ||
return PatchPod(cs, pod, podCopy) | ||
} |
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.
how about
func ClearNominatedNodeName(cs kubernetes.Interface, pods ...*v1.Pod) error {
for _, p := range pods {
if len(pod.Status.NominatedNodeName) == 0 {
continue
}
podCopy := p.DeepCopy()
podCopy.Status.NominatedNodeName = ""
if err := PatchPod(cs, p, podCopy); err != nil {
klog.Errorf("Cannot clear 'NominatedNodeName' field of pod %v/%v: %v", p.Namespace, p.Name, err)
// We do not return as this error is not critical.
}
}
}
and remove CleanUpNominatedPods
below
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.
SG.
|
||
// GetUpdatedPod returns the latest version of <pod> from API server. | ||
func GetUpdatedPod(cs kubernetes.Interface, pod *v1.Pod) (*v1.Pod, error) { | ||
return cs.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{}) |
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 should change this to get the pod from informer cache, not in this PR though.
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.
Let me add a todo.
test.pod.Status.NominatedNodeName = node | ||
client.CoreV1().Pods(test.pod.Namespace).Update(context.TODO(), test.pod, metav1.UpdateOptions{}) |
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.
why are we doing this inside the loop iterating over the victims?
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.
As mentioned in your previous comment, we're now still fetching the pod from clientset, so the test needs to update the pod in fake clienset as well.
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.
sure, but why are we doing the update inside the loop iterating over deletedPodNames
, shouldn't the update happen once after or before the loop?
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.
Ah, the old logic which assigns "node" to "test.pod.Status.NominatedNodeName" misleads me. Updated.
PS: technically I can make expectedPods
as a string set to shorten the code, but I have a PR on refactoring the whole TestPreempt testcase, which'd make this more neat. So for now, I'd prefer to just make minimum change.
now := metav1.Now() | ||
pod.DeletionTimestamp = &now | ||
deletedPodNames.Delete(pod.Name) |
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.
why not do this inside the loop above that iterates over deletedPodNames?
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.
The test.expectedPods
in the above loop is a string slice, so I cannot update the pod there.
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.
As mentioned in #92009 (comment), there will be a PR refactoring whole TestPreempt test later.
c7175b2
to
2b27457
Compare
Thanks, please squash. |
- replace error with NodeToStatusMap in Preempt() signature - eliminate podPreemptor interface and expose its functions statelessly - move logic in scheduler.go#preempt to generic_scheduler.go#Preempt()
5a0c664
to
36c8ecc
Compare
/lgtm |
@ahg-g Thanks for reviewing! Commits squashed. PTAL. |
/retest |
What type of PR is this?
/kind feature
/sig scheduling
What this PR does / why we need it:
This is the first PR of defaultpreemption plugin, which covers:
error
withNodeToStatusMap
inPreempt()
signaturepodPreemptor
interface and expose its original functions statelesslyscheduler.go#preempt()
togeneric_scheduler.go#Preempt()
It corresponds to the first part of @ahg-g's #91426 (comment)
Which issue(s) this PR fixes:
Part of #91038.
Special notes for your reviewer:
Does this PR introduce a user-facing change?: