Skip to content

Commit aee1ab3

Browse files
authored
Merge pull request kubernetes#72260 from bsalamat/fix_waiting_pods
Add pods in the backoff queue to the list of pending pods
2 parents 81a1f12 + 48b6f75 commit aee1ab3

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

pkg/scheduler/internal/cache/debugger/comparer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ func (c *CacheComparer) Compare() error {
5454

5555
snapshot := c.Cache.Snapshot()
5656

57-
waitingPods := c.PodQueue.WaitingPods()
57+
pendingPods := c.PodQueue.PendingPods()
5858

5959
if missed, redundant := c.CompareNodes(nodes, snapshot.Nodes); len(missed)+len(redundant) != 0 {
6060
klog.Warningf("cache mismatch: missed nodes: %s; redundant nodes: %s", missed, redundant)
6161
}
6262

63-
if missed, redundant := c.ComparePods(pods, waitingPods, snapshot.Nodes); len(missed)+len(redundant) != 0 {
63+
if missed, redundant := c.ComparePods(pods, pendingPods, snapshot.Nodes); len(missed)+len(redundant) != 0 {
6464
klog.Warningf("cache mismatch: missed pods: %s; redundant pods: %s", missed, redundant)
6565
}
6666

pkg/scheduler/internal/cache/debugger/dumper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ func (d *CacheDumper) dumpNodes() {
5252

5353
// dumpSchedulingQueue writes pods in the scheduling queue to the scheduler logs.
5454
func (d *CacheDumper) dumpSchedulingQueue() {
55-
waitingPods := d.podQueue.WaitingPods()
55+
pendingPods := d.podQueue.PendingPods()
5656
var podData strings.Builder
57-
for _, p := range waitingPods {
57+
for _, p := range pendingPods {
5858
podData.WriteString(printPod(p))
5959
}
6060
klog.Infof("Dump of scheduling queue:\n%s", podData.String())

pkg/scheduler/internal/queue/scheduling_queue.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type SchedulingQueue interface {
6565
AssignedPodAdded(pod *v1.Pod)
6666
AssignedPodUpdated(pod *v1.Pod)
6767
WaitingPodsForNode(nodeName string) []*v1.Pod
68-
WaitingPods() []*v1.Pod
68+
PendingPods() []*v1.Pod
6969
// Close closes the SchedulingQueue so that the goroutine which is
7070
// waiting to pop items can exit gracefully.
7171
Close()
@@ -131,8 +131,8 @@ func (f *FIFO) Pop() (*v1.Pod, error) {
131131
return result.(*v1.Pod), err
132132
}
133133

134-
// WaitingPods returns all the waiting pods in the queue.
135-
func (f *FIFO) WaitingPods() []*v1.Pod {
134+
// PendingPods returns all the pods in the queue.
135+
func (f *FIFO) PendingPods() []*v1.Pod {
136136
result := []*v1.Pod{}
137137
for _, pod := range f.FIFO.List() {
138138
result = append(result, pod.(*v1.Pod))
@@ -675,15 +675,19 @@ func (p *PriorityQueue) WaitingPodsForNode(nodeName string) []*v1.Pod {
675675
return nil
676676
}
677677

678-
// WaitingPods returns all the waiting pods in the queue.
679-
func (p *PriorityQueue) WaitingPods() []*v1.Pod {
678+
// PendingPods returns all the pending pods in the queue. This function is
679+
// used for debugging purposes in the scheduler cache dumper and comparer.
680+
func (p *PriorityQueue) PendingPods() []*v1.Pod {
680681
p.lock.Lock()
681682
defer p.lock.Unlock()
682683

683684
result := []*v1.Pod{}
684685
for _, pod := range p.activeQ.List() {
685686
result = append(result, pod.(*v1.Pod))
686687
}
688+
for _, pod := range p.podBackoffQ.List() {
689+
result = append(result, pod.(*v1.Pod))
690+
}
687691
for _, pod := range p.unschedulableQ.pods {
688692
result = append(result, pod)
689693
}

pkg/scheduler/internal/queue/scheduling_queue_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,22 @@ func TestPriorityQueue_WaitingPodsForNode(t *testing.T) {
338338
}
339339
}
340340

341+
func TestPriorityQueue_PendingPods(t *testing.T) {
342+
q := NewPriorityQueue(nil)
343+
q.Add(&medPriorityPod)
344+
q.unschedulableQ.addOrUpdate(&unschedulablePod)
345+
q.unschedulableQ.addOrUpdate(&highPriorityPod)
346+
expectedList := []*v1.Pod{&medPriorityPod, &unschedulablePod, &highPriorityPod}
347+
if !reflect.DeepEqual(expectedList, q.PendingPods()) {
348+
t.Error("Unexpected list of pending Pods for node.")
349+
}
350+
// Move all to active queue. We should still see the same set of pods.
351+
q.MoveAllToActiveQueue()
352+
if !reflect.DeepEqual(expectedList, q.PendingPods()) {
353+
t.Error("Unexpected list of pending Pods for node.")
354+
}
355+
}
356+
341357
func TestUnschedulablePodsMap(t *testing.T) {
342358
var pods = []*v1.Pod{
343359
{

0 commit comments

Comments
 (0)