fix: use set methods

This commit is contained in:
Kensei Nakada 2024-11-06 13:19:57 +09:00
parent 623b2a20d2
commit d4d91d4ace
2 changed files with 6 additions and 11 deletions

View File

@ -116,13 +116,9 @@ func (pl *DefaultPreemption) PreEnqueue(ctx context.Context, p *v1.Pod) *framewo
// EventsToRegister returns the possible events that may make a Pod
// failed by this plugin schedulable.
func (pl *DefaultPreemption) EventsToRegister(_ context.Context) ([]framework.ClusterEventWithHint, error) {
return []framework.ClusterEventWithHint{
// We don't need any QHint for the event
// because the Pod rejected by the preemption plugin is the one that is running the preemption,
// and the Pod won't be requeued until all the preemption API calls are completed
// (we block the Pod from being requeued at PreEnqueue).
{Event: framework.ClusterEvent{Resource: framework.Pod, ActionType: framework.Delete}},
}, nil
// The plugin moves the preemptor Pod to acviteQ/backoffQ once the preemption API calls are all done,
// and we don't need to move the Pod with any events.
return nil, nil
}
// calculateNumCandidates returns the number of candidates the FindCandidates

View File

@ -209,8 +209,7 @@ func (ev *Evaluator) IsPodRunningPreemption(podUID types.UID) bool {
ev.mu.RLock()
defer ev.mu.RUnlock()
_, ok := ev.preempting[podUID]
return ok
return ev.preempting.Has(podUID)
}
// 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
}
ev.mu.Lock()
ev.preempting[pod.UID] = struct{}{}
ev.preempting.Insert(pod.UID)
ev.mu.Unlock()
logger := klog.FromContext(ctx)
@ -494,7 +493,7 @@ func (ev *Evaluator) prepareCandidateAsync(c Candidate, pod *v1.Pod, pluginName
defer metrics.PreemptionGoroutinesExecutionTotal.WithLabelValues(result).Inc()
defer func() {
ev.mu.Lock()
delete(ev.preempting, pod.UID)
ev.preempting.Delete(pod.UID)
ev.mu.Unlock()
ev.Handler.Activate(logger, map[string]*v1.Pod{pod.Name: pod})
}()