Skip to content

Commit

Permalink
bug(preemption): fix SelectVictimsOnNode method consistent with defau…
Browse files Browse the repository at this point in the history
…lt scheduler
  • Loading branch information
googs1025 committed Dec 13, 2024
1 parent d535523 commit fefba22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/capacityscheduling/capacity_scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ func (p *preemptor) SelectVictimsOnNode(

var victims []*v1.Pod
numViolatingVictim := 0
// Sort potentialVictims by pod priority from high to low, which ensures to
// reprieve higher priority pods first.
sort.Slice(potentialVictims, func(i, j int) bool {
return schedutil.MoreImportantPod(potentialVictims[i].Pod, potentialVictims[j].Pod)
})
Expand Down Expand Up @@ -666,6 +668,11 @@ func (p *preemptor) SelectVictimsOnNode(
return nil, 0, framework.AsStatus(err)
}
}

// Sort victims after reprieving pods to keep the pods in the victims sorted in order of priority from high to low.
if len(violatingVictims) != 0 && len(nonViolatingVictims) != 0 {
sort.Slice(victims, func(i, j int) bool { return schedutil.MoreImportantPod(victims[i], victims[j]) })
}
return victims, numViolatingVictim, framework.NewStatus(framework.Success)
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/preemptiontoleration/preemption_toleration.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ func (pl *PreemptionToleration) SelectVictimsOnNode(
}
var victims []*v1.Pod
numViolatingVictim := 0
// Sort potentialVictims by pod priority from high to low, which ensures to
// reprieve higher priority pods first.
sort.Slice(potentialVictims, func(i, j int) bool { return util.MoreImportantPod(potentialVictims[i].Pod, potentialVictims[j].Pod) })
// Try to reprieve as many pods as possible. We first try to reprieve the PDB
// violating victims and then other non-violating ones. In both cases, we start
Expand Down Expand Up @@ -284,6 +286,11 @@ func (pl *PreemptionToleration) SelectVictimsOnNode(
return nil, 0, framework.AsStatus(err)
}
}

// Sort victims after reprieving pods to keep the pods in the victims sorted in order of priority from high to low.
if len(violatingVictims) != 0 && len(nonViolatingVictims) != 0 {
sort.Slice(victims, func(i, j int) bool { return util.MoreImportantPod(victims[i], victims[j]) })
}
return victims, numViolatingVictim, framework.NewStatus(framework.Success)
}

Expand Down

0 comments on commit fefba22

Please sign in to comment.