Skip to content

Commit d4d91d4

Browse files
committed
fix: use set methods
1 parent 623b2a2 commit d4d91d4

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

pkg/scheduler/framework/plugins/defaultpreemption/default_preemption.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,9 @@ func (pl *DefaultPreemption) PreEnqueue(ctx context.Context, p *v1.Pod) *framewo
116116
// EventsToRegister returns the possible events that may make a Pod
117117
// failed by this plugin schedulable.
118118
func (pl *DefaultPreemption) EventsToRegister(_ context.Context) ([]framework.ClusterEventWithHint, error) {
119-
return []framework.ClusterEventWithHint{
120-
// We don't need any QHint for the event
121-
// because the Pod rejected by the preemption plugin is the one that is running the preemption,
122-
// and the Pod won't be requeued until all the preemption API calls are completed
123-
// (we block the Pod from being requeued at PreEnqueue).
124-
{Event: framework.ClusterEvent{Resource: framework.Pod, ActionType: framework.Delete}},
125-
}, nil
119+
// The plugin moves the preemptor Pod to acviteQ/backoffQ once the preemption API calls are all done,
120+
// and we don't need to move the Pod with any events.
121+
return nil, nil
126122
}
127123

128124
// calculateNumCandidates returns the number of candidates the FindCandidates

pkg/scheduler/framework/preemption/preemption.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ func (ev *Evaluator) IsPodRunningPreemption(podUID types.UID) bool {
209209
ev.mu.RLock()
210210
defer ev.mu.RUnlock()
211211

212-
_, ok := ev.preempting[podUID]
213-
return ok
212+
return ev.preempting.Has(podUID)
214213
}
215214

216215
// Preempt returns a PostFilterResult carrying suggested nominatedNodeName, along with a Status.
@@ -483,7 +482,7 @@ func (ev *Evaluator) prepareCandidateAsync(c Candidate, pod *v1.Pod, pluginName
483482
}
484483

485484
ev.mu.Lock()
486-
ev.preempting[pod.UID] = struct{}{}
485+
ev.preempting.Insert(pod.UID)
487486
ev.mu.Unlock()
488487

489488
logger := klog.FromContext(ctx)
@@ -494,7 +493,7 @@ func (ev *Evaluator) prepareCandidateAsync(c Candidate, pod *v1.Pod, pluginName
494493
defer metrics.PreemptionGoroutinesExecutionTotal.WithLabelValues(result).Inc()
495494
defer func() {
496495
ev.mu.Lock()
497-
delete(ev.preempting, pod.UID)
496+
ev.preempting.Delete(pod.UID)
498497
ev.mu.Unlock()
499498
ev.Handler.Activate(logger, map[string]*v1.Pod{pod.Name: pod})
500499
}()

0 commit comments

Comments
 (0)