sched: provide an option for plugin developers to move pods to activeQ

This commit is contained in:
Wei Huang
2021-06-30 09:57:53 -07:00
parent d7123a6524
commit fb9cafc99b
5 changed files with 240 additions and 0 deletions

View File

@@ -77,6 +77,10 @@ type PreEnqueueCheck func(pod *v1.Pod) bool
type SchedulingQueue interface {
framework.PodNominator
Add(pod *v1.Pod) error
// Activate moves the given pods to activeQ iff they're in unschedulableQ or backoffQ.
// The passed-in pods are originally compiled from plugins that want to activate Pods,
// by injecting the pods through a reserved CycleState struct (PodsToActivate).
Activate(pods map[string]*v1.Pod)
// AddUnschedulableIfNotPresent adds an unschedulable pod back to scheduling queue.
// The podSchedulingCycle represents the current scheduling cycle number which can be
// returned by calling SchedulingCycle().
@@ -301,6 +305,58 @@ func (p *PriorityQueue) Add(pod *v1.Pod) error {
return nil
}
// Activate moves the given pods to activeQ iff they're in unschedulableQ or backoffQ.
func (p *PriorityQueue) Activate(pods map[string]*v1.Pod) {
p.lock.Lock()
defer p.lock.Unlock()
activated := false
for _, pod := range pods {
if p.activate(pod) {
activated = true
}
}
if activated {
p.cond.Broadcast()
}
}
func (p *PriorityQueue) activate(pod *v1.Pod) bool {
// Verify if the pod is present in activeQ.
if _, exists, _ := p.activeQ.Get(newQueuedPodInfoForLookup(pod)); exists {
// No need to activate if it's already present in activeQ.
return false
}
var pInfo *framework.QueuedPodInfo
// Verify if the pod is present in unschedulableQ or backoffQ.
if pInfo = p.unschedulableQ.get(pod); pInfo == nil {
// If the pod doesn't belong to unschedulableQ or backoffQ, don't activate it.
if obj, exists, _ := p.podBackoffQ.Get(newQueuedPodInfoForLookup(pod)); !exists {
klog.ErrorS(nil, "To-activate pod does not exist in unschedulableQ or backoffQ", "pod", klog.KObj(pod))
return false
} else {
pInfo = obj.(*framework.QueuedPodInfo)
}
}
if pInfo == nil {
// Redundant safe check. We shouldn't reach here.
klog.ErrorS(nil, "Internal error: cannot obtain pInfo")
return false
}
if err := p.activeQ.Add(pInfo); err != nil {
klog.ErrorS(err, "Error adding pod to the scheduling queue", "pod", klog.KObj(pod))
return false
}
p.unschedulableQ.delete(pod)
p.podBackoffQ.Delete(pInfo)
metrics.SchedulerQueueIncomingPods.WithLabelValues("active", ForceActivate).Inc()
p.PodNominator.AddNominatedPod(pInfo.PodInfo, "")
return true
}
// isPodBackingoff returns true if a pod is still waiting for its backoff timer.
// If this returns true, the pod should not be re-tried.
func (p *PriorityQueue) isPodBackingoff(podInfo *framework.QueuedPodInfo) bool {