Skip to content

fix: reverse potentialVictims order to reprieve higher priority pods first#5214

Open
dengaosong wants to merge 2 commits intovolcano-sh:masterfrom
dengaosong:fix/victim-reprieve-priority-order
Open

fix: reverse potentialVictims order to reprieve higher priority pods first#5214
dengaosong wants to merge 2 commits intovolcano-sh:masterfrom
dengaosong:fix/victim-reprieve-priority-order

Conversation

@dengaosong
Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

In SelectVictimsOnNode, potentialVictims was collected from victimsQueue.Pop() which returns lower priority pods first. This caused lower priority pods to be reprieved first, contradicting the expected behavior described in the code comment.
This fix reverses potentialVictims before the reprieve loop to ensure higher priority pods are reprieved first.

Which issue(s) this PR fixes:

Fixes #5208

Special notes for your reviewer:

The root cause is that BuildVictimsPriorityQueue uses !ssn.TaskOrderFn with negation, so Pop() returns pods in [low→high] priority order, which is opposite to the sort.Slice order [high→low].

Does this PR introduce a user-facing change?

None

Fixed victim reprieve logic in preempt action to reprieve higher priority pods first as intended.

Copilot AI review requested due to automatic review settings April 16, 2026 02:59
@volcano-sh-bot volcano-sh-bot added kind/bug Categorizes issue or PR as related to a bug. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. labels Apr 16, 2026
@volcano-sh-bot volcano-sh-bot requested review from dafu-wu and k82cn April 16, 2026 02:59
@volcano-sh-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

Details 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

@volcano-sh-bot
Copy link
Copy Markdown
Contributor

Welcome @dengaosong! It looks like this is your first PR to volcano-sh/volcano 🎉

@volcano-sh-bot volcano-sh-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 16, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the preemption logic in pkg/scheduler/actions/preempt/preempt.go by removing the explicit sorting of all potential victims. Instead, it implements a manual reversal of the potentialVictims slice to maintain the correct priority order for reprieving pods, as the priority queue returns them in ascending order of priority. I have no feedback to provide.

Copy link
Copy Markdown
Contributor

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

Fixes victim reprieve ordering in SelectVictimsOnNode so that when attempting to add back (“reprieve”) potential victims, higher-priority pods are considered first (aligning behavior with the intended priority semantics described in #5208).

Changes:

  • Removes the misleading/ineffective pre-sort of victims (and the associated k8sutil dependency).
  • Reverses potentialVictims prior to the reprieve loop so reprieve proceeds from higher → lower priority.

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

Comment on lines +814 to +819
// Reverse potentialVictims to reprieve higher priority pods first.
// potentialVictims is collected from victimsQueue.Pop() which returns lower priority first,
// so we need to reverse it to ensure higher priority pods are reprieved first.
for i, j := 0, len(potentialVictims)-1; i < j; i, j = i+1, j-1 {
potentialVictims[i], potentialVictims[j] = potentialVictims[j], potentialVictims[i]
}
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

The newly added reversal block is not gofmt-formatted (uses spaces instead of tabs and has inconsistent indentation vs the surrounding code). Please run gofmt (or adjust indentation) so the comment and for-loop align with the file’s standard formatting; this will also remove the trailing whitespace on the closing brace line.

Suggested change
// Reverse potentialVictims to reprieve higher priority pods first.
// potentialVictims is collected from victimsQueue.Pop() which returns lower priority first,
// so we need to reverse it to ensure higher priority pods are reprieved first.
for i, j := 0, len(potentialVictims)-1; i < j; i, j = i+1, j-1 {
potentialVictims[i], potentialVictims[j] = potentialVictims[j], potentialVictims[i]
}
// Reverse potentialVictims to reprieve higher priority pods first.
// potentialVictims is collected from victimsQueue.Pop() which returns lower priority first,
// so we need to reverse it to ensure higher priority pods are reprieved first.
for i, j := 0, len(potentialVictims)-1; i < j; i, j = i+1, j-1 {
potentialVictims[i], potentialVictims[j] = potentialVictims[j], potentialVictims[i]
}

Copilot uses AI. Check for mistakes.
Comment thread pkg/scheduler/actions/preempt/preempt.go Outdated
@dengaosong dengaosong force-pushed the fix/victim-reprieve-priority-order branch from c61fe72 to 4698b3a Compare April 16, 2026 03:16
@volcano-sh-bot volcano-sh-bot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Apr 16, 2026
@dengaosong dengaosong force-pushed the fix/victim-reprieve-priority-order branch from 4698b3a to f5f8495 Compare April 16, 2026 03:38
@dengaosong
Copy link
Copy Markdown
Author

Hi @k82cn @dafu-wu, could you please help approve the CI workflows to run?
This is my first contribution to this repo. Thank you!

@JesseStutler
Copy link
Copy Markdown
Member

/ok-to-test

@volcano-sh-bot volcano-sh-bot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Apr 25, 2026
@JesseStutler
Copy link
Copy Markdown
Member

You are right, but please resolve the go fmt error please @dengaosong

@JesseStutler
Copy link
Copy Markdown
Member

Also commits should not contain like Merge branch 'master' into xxx, please use rebase to resolve it

@dengaosong dengaosong force-pushed the fix/victim-reprieve-priority-order branch from 0d3d33e to 3d4b6b3 Compare April 30, 2026 06:08
@dengaosong dengaosong force-pushed the fix/victim-reprieve-priority-order branch from 3d4b6b3 to 3d934f1 Compare April 30, 2026 07:18
dengaosong and others added 2 commits April 30, 2026 15:23
…first

  In SelectVictimsOnNode, potentialVictims was collected from victimsQueue.Pop()
  which returns lower priority pods first. This caused lower priority pods to
  be reprieved first, contradicting the expected behavior.

  This fix reverses potentialVictims before the reprieve loop to ensure
  higher priority pods are reprieved first, as intended by the code comment.

Signed-off-by: Deng Aosong <dengaosong@gamil.com>
Signed-off-by: Deng Aosong <dengaosong@gmail.com>
Changed spaces to tabs for proper Go formatting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Deng Aosong <dengaosong@gmail.com>
@dengaosong dengaosong force-pushed the fix/victim-reprieve-priority-order branch from 3d934f1 to fc6ce37 Compare April 30, 2026 07:23
@dengaosong
Copy link
Copy Markdown
Author

Hi, I have resolved the issues:

  1. Fixed the gofmt formatting errors
  2. Rebased the branch to remove merge commits

All checks are passing now. Please take another look when you get a chance. Thanks!
@JesseStutler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Victim reprieve logic in SelectVictimsOnNode reprieves lower priority pods first instead of higher priority pods

4 participants