Skip to content

Commit 66d66f4

Browse files
authored
Merge pull request #838 from googs1025/bugfix/preemption
bug(preemption): fix SelectVictimsOnNode method consistent with default scheduler
2 parents d535523 + fefba22 commit 66d66f4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/capacityscheduling/capacity_scheduling.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ func (p *preemptor) SelectVictimsOnNode(
620620

621621
var victims []*v1.Pod
622622
numViolatingVictim := 0
623+
// Sort potentialVictims by pod priority from high to low, which ensures to
624+
// reprieve higher priority pods first.
623625
sort.Slice(potentialVictims, func(i, j int) bool {
624626
return schedutil.MoreImportantPod(potentialVictims[i].Pod, potentialVictims[j].Pod)
625627
})
@@ -666,6 +668,11 @@ func (p *preemptor) SelectVictimsOnNode(
666668
return nil, 0, framework.AsStatus(err)
667669
}
668670
}
671+
672+
// Sort victims after reprieving pods to keep the pods in the victims sorted in order of priority from high to low.
673+
if len(violatingVictims) != 0 && len(nonViolatingVictims) != 0 {
674+
sort.Slice(victims, func(i, j int) bool { return schedutil.MoreImportantPod(victims[i], victims[j]) })
675+
}
669676
return victims, numViolatingVictim, framework.NewStatus(framework.Success)
670677
}
671678

pkg/preemptiontoleration/preemption_toleration.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ func (pl *PreemptionToleration) SelectVictimsOnNode(
250250
}
251251
var victims []*v1.Pod
252252
numViolatingVictim := 0
253+
// Sort potentialVictims by pod priority from high to low, which ensures to
254+
// reprieve higher priority pods first.
253255
sort.Slice(potentialVictims, func(i, j int) bool { return util.MoreImportantPod(potentialVictims[i].Pod, potentialVictims[j].Pod) })
254256
// Try to reprieve as many pods as possible. We first try to reprieve the PDB
255257
// violating victims and then other non-violating ones. In both cases, we start
@@ -284,6 +286,11 @@ func (pl *PreemptionToleration) SelectVictimsOnNode(
284286
return nil, 0, framework.AsStatus(err)
285287
}
286288
}
289+
290+
// Sort victims after reprieving pods to keep the pods in the victims sorted in order of priority from high to low.
291+
if len(violatingVictims) != 0 && len(nonViolatingVictims) != 0 {
292+
sort.Slice(victims, func(i, j int) bool { return util.MoreImportantPod(victims[i], victims[j]) })
293+
}
287294
return victims, numViolatingVictim, framework.NewStatus(framework.Success)
288295
}
289296

0 commit comments

Comments
 (0)