← Back to Pull requests

coscheduling: fix head-of-line blocking for Pods without a PodGroup #1019

Open
shadowdsp opened this pull request with 88 lines diff across 2 files
View on GitHub
shadowdsp shadowdsp commented on Oct 25, 2026 04:38 UTC
Author

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:

creationTime1 := cs.pgMgr.GetCreationTimestamp(context.TODO(), pod1, *podInfo1.GetInitialAttemptTimestamp())
creationTime2 := cs.pgMgr.GetCreationTimestamp(context.TODO(), pod2, *podInfo2.GetInitialAttemptTimestamp())

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:

creationTime1 := cs.pgMgr.GetCreationTimestamp(context.TODO(), pod1, podInfo1.GetTimestamp())
creationTime2 := cs.pgMgr.GetCreationTimestamp(context.TODO(), pod2, podInfo2.GetTimestamp())

Timestamp is refreshed every time the Pod is re-added to the queue (PriorityQueue.AddUnschedulableIfNotPresent() does pInfo.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 default PrioritySort plugin 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's CreationTimestamp (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 Fixes keyword.

Special notes for your reviewer:

  • TestLess now drives Timestamp instead of InitialAttemptTimestamp (the two fields have different lifecycles, so the test data had to change with the implementation), and gets two new cases:

  • - the starvation scenario: p1 has the earlier initial attempt timestamp but was re-enqueued after p2, so p2 must be popped first. On current master this case fails with Want 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.
  • Behavior for PodGroups is unchanged and still covered by the existing TestLess cases plus TestLessAfterScheduleFailure.

  • Verified locally with go test ./pkg/coscheduling/... and go 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.
    ``

    Diff: 88 lines (+61 / -27) across 2 files Reviewer: ffromani Review duration: 50418m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.38) × (1 − Review Confidence (0.84)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.38 · 88 lines diff across 2 files
    0.38
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.90 · 5 substantive comment(s)
    0.90
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    83%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.269
    Real PR Conversation Timeline
    8 items
    netlify[bot] netlify[bot] commented on Oct 25, 2026 04:38 UTC
    Bot

    <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 |

    linux-foundation-easycla[bot] linux-foundation-easycla[bot] commented on Oct 25, 2026 04:38 UTC
    Bot

    <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>

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Oct 25, 2026 04:38 UTC
    Bot

    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:

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Oct 25, 2026 04:38 UTC
    Bot

    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>

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Oct 25, 2026 04:38 UTC
    Bot

    [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:

  • OWNERS
  • 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"]} -->

    shadowdsp shadowdsp commented on Oct 25, 2026 07:45 UTC
    Author

    /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.

    ffromani ffromani commented on Nov 13, 2026 13:00 UTC
    Reviewer

    /ok-to-test

    Reviewers
    Assignees
    shadowdsp shadowdsp
    Labels
    risk: low confidence: 83.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 38.3% (MEDIUM) · Higher = larger blast radius
    38.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83.9% · Lower = rushed or shallow review
    83.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 6.2% · Safe to merge
    6.2%