coscheduling: fix head-of-line blocking for Pods without a PodGroup #1019
<span aria-hidden="true">✅</span> Deploy Preview for kubernetes-sigs-scheduler-plugins canceled.
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 5bfa8dbd57ac289668f6cd464af84f163e75177f |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/kubernetes-sigs-scheduler-plugins/deploys/6add87c2f3f63652b2aeebb0 |
<a href="https://easycla.lfx.linuxfoundation.org/#/?version=2"><img src="https://s3.amazonaws.com/cla-project-logo-prod/cla-signed.svg?v=2" alt="CLA Signed" align="left" height="28" width="328" ></a><br >The committers listed above are authorized under a signed CLA.<ul><li>:white_check_mark: login: shadowdsp / name: shadowdsp (5bfa8dbd57ac289668f6cd464af84f163e75177f)</li></ul>
Welcome @shadowdsp! <br><br>It looks like this is your first PR to <a href='https://github.com/kubernetes-sigs/scheduler-plugins'>kubernetes-sigs/scheduler-plugins</a> 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval. <br><br>You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation. <br><br>You can also check if kubernetes-sigs/scheduler-plugins has its own contribution guidelines. <br><br>You may want to refer to our testing guide if you run into trouble with your tests not passing. <br><br>If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs! <br><br>Thank you, and welcome to Kubernetes. :smiley:
Hi @shadowdsp. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.
Regular contributors should join the org to skip this step.
Once the patch is verified, the new status will be reflected by the ok-to-test label.
I understand the commands that are listed here.
<details>
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-sigs/prow repository.
</details>
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: <a href="https://github.com/kubernetes-sigs/scheduler-plugins/pull/1019#" title="Author self-approved">shadowdsp</a>
Once this PR has been reviewed and has the lgtm label, please assign ffromani for approval. For more information see the Code Review Process.
The full list of commands accepted by this bot can be found here.
<details open>
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
</details>
<!-- META={"approvers":["ffromani"]} -->
/cc @Huang-Wei
Could you take a look at this PR when convenient? Thanks!
It's a follow-up to the PodGroup-side fix in #949: Pods that don't belong to a PodGroup still fall back to GetInitialAttemptTimestamp() in Less(). That value is never refreshed, so a re-enqueued Pod keeps its original sort key and the Pods behind it starve (#110, #874). This passes QueuedPodInfo.GetTimestamp() instead — refreshed on every re-enqueue, the same ordering PrioritySort uses. PodGroup ordering is unchanged.
/ok-to-test
ffromani
shadowdsp
What type of PR is this?
/kind bug
What this PR does / why we need it:
Coscheduling.Less()uses the Pod's initial attempt timestamp as the fallback sort key for Pods that don't belong to a PodGroup, or whose PodGroup can't be found yet:That timestamp is written once, when the Pod first enters the scheduling queue, and is never refreshed — per the framework docs (
kube-scheduler/framework/types.go) it exists to record the e2e scheduling latency metric, not to order the queue. A Pod whose scheduling keeps failing therefore holds on to the oldest key forever and is always popped before every Pod enqueued after it. Once enough such Pods pile up, the scheduler never even attempts the newer Pods. That is the starvation described in #110 and #874, and it hits every Pod that is not managed by a PodGroup — i.e. the bulk of a typical cluster — even when coscheduling is only used by a small subset of the workloads.PR #949 fixed this for Pods that do belong to a PodGroup (their sort key became the last scheduling failure time). This PR closes the remaining gap by passing the enqueue timestamp,
QueuedPodInfo.GetTimestamp(), instead:Timestampis refreshed every time the Pod is re-added to the queue (PriorityQueue.AddUnschedulableIfNotPresent()doespInfo.Timestamp = p.clock.Now()), so a re-enqueued Pod moves behind the Pods that have been waiting for less time. That is exactly the ordering the defaultPrioritySortplugin uses, so a Pod without a PodGroup now behaves the way it would if the coscheduling plugin weren't enabled.Scope: only the fallback path changes. For a Pod that belongs to an existing PodGroup,
GetCreationTimestamp()still returns the PodGroup'sCreationTimestamp(or its last scheduling failure timestamp), so a co-scheduling unit stays ordered as a whole and sibling Pods are not reordered mid-group.Which issue(s) this PR fixes:
Refs #110, #874 — this covers the non-PodGroup half of the starvation described there; PodGroup-level ordering (making the PodGroup the queueing unit) is out of scope, hence no
Fixeskeyword.Special notes for your reviewer:
TestLessnow drivesTimestampinstead ofInitialAttemptTimestamp(the two fields have different lifecycles, so the test data had to change with the implementation), and gets two new cases:- the starvation scenario:
p1has the earlier initial attempt timestamp but was re-enqueued afterp2, sop2must be popped first. On current master this case fails withWant false, got true, i.e. the stale Pod jumps the queue.- a Pod without a PodGroup vs. a Pod whose PodGroup exists: the latter is still keyed by the PodGroup creation timestamp, not by its own enqueue timestamp.
TestLesscases plusTestLessAfterScheduleFailure.go test ./pkg/coscheduling/...andgo vet ./pkg/coscheduling/....Does this PR introduce a user-facing change?
``
release-note
``coscheduling: Pods that don't belong to a PodGroup are now sorted by their enqueue timestamp instead of their initial attempt timestamp, so Pods that repeatedly fail to schedule no longer starve the Pods enqueued after them.