Skip to content

Conversation

@sohankunkerkar
Copy link
Member

What type of PR is this?

/kind bug
/kind flake

What this PR does / why we need it:

When a workload is evicted and re-queued, it can be added back to the queue while the scheduler is processing an older batch. This causes lower-priority workloads to be admitted before higher-priority ones. This fixes the issue by checking the queue for higher-priority workloads right before admission.

Which issue(s) this PR fixes:

Fixes #8141

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fix StrictFIFO priority ordering when higher-priority workloads are re-queued during scheduling

Add pre-admission check to detect when a higher-priority workload
was added to the queue after Heads() popped a lower-priority one.
This prevents admitting lower-priority workloads before evicted
higher-priority workloads in StrictFIFO mode.

Signed-off-by: Sohan Kunkerkar <sohank2602@gmail.com>
Copilot AI review requested due to automatic review settings December 9, 2025 18:04
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/bug Categorizes issue or PR as related to a bug. kind/flake Categorizes issue or PR as related to a flaky test. labels Dec 9, 2025
@netlify
Copy link

netlify bot commented Dec 9, 2025

Deploy Preview for kubernetes-sigs-kueue ready!

Name Link
🔨 Latest commit 5a325ba
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-sigs-kueue/deploys/693864970979e50007f1afbe
😎 Deploy Preview https://deploy-preview-8153--kubernetes-sigs-kueue.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sohankunkerkar
Once this PR has been reviewed and has the lgtm label, please assign tenzen-y for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

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

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 9, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a race condition in StrictFIFO priority ordering where higher-priority workloads that are evicted and re-queued during an active scheduling cycle could be admitted after lower-priority workloads. The fix adds a check right before admission to ensure no higher-priority workloads are waiting in the queue.

Key Changes

  • Added Peek() method to the heap utility to inspect the head without removal
  • Added HasStrictFIFOHigherPriorityPending() methods to check for higher priority workloads
  • Integrated priority check in scheduler before workload admission

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/util/heap/heap.go Adds Peek() method to inspect heap head without removal
pkg/util/heap/heap_test.go Comprehensive unit tests for Peek() functionality
pkg/cache/queue/cluster_queue.go Implements priority checking logic for StrictFIFO queues
pkg/cache/queue/cluster_queue_test.go Tests HasStrictFIFOHigherPriorityPending with various scenarios
pkg/cache/queue/manager.go Adds manager-level wrapper for priority checking
pkg/scheduler/scheduler.go Integrates priority check before workload admission

The implementation is sound, with proper thread-safety through read locks, comprehensive test coverage, and efficient O(1) operations. The fix is placed at the correct point in the scheduling flow - after nomination and flavor assignment, but before actual admission - to catch race conditions while minimizing unnecessary checks.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sohankunkerkar sohankunkerkar changed the title [WIP] pkg: fix race condition in StrictFIFO priority ordering pkg: fix race condition in StrictFIFO priority ordering Dec 10, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 10, 2025

// Check if a higher-priority workload was added to the queue after we popped this workload.
// This can happen due to race conditions during workload eviction.
if s.queues.HasStrictFIFOHigherPriorityPending(e.ClusterQueue, priority.Priority(e.Obj)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I have analyzed the logs and summarized it there: #8141 (comment)

The fix seems pretty complex, a lot of new code, which is very rarely useful, so I'm not sure about that PR. I'm not convinced this issue is worth the complication. In any case it requires more thinking / testing, so I was just thinking in the meanwhile we could just fix this test by removing the last line from the test :)

/hold
On the decision how we approach it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we have a number of flakes the priority for me is to eliminate them. I would leave this open as a dedicated issue, and then re-evaluate the fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just submitted the quick fix for the flake, ptal #8203

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/bug Categorizes issue or PR as related to a bug. kind/flake Categorizes issue or PR as related to a flaky test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flaky integration test] Preemption In a cohort with StrictFIFO Should reclaim from cohort even if another CQ has pending workloads

3 participants