mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 16:06:51 +00:00
sched: provide an option for plugin developers to move pods to activeQ
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user