From 48b6f758290881c739e9c11fd72a06af4770075e Mon Sep 17 00:00:00 2001 From: "Bobby (Babak) Salamat" Date: Thu, 20 Dec 2018 17:28:23 -0800 Subject: [PATCH] Add pods in the backoff queue to the list of pending pods --- .../internal/cache/debugger/comparer.go | 4 ++-- pkg/scheduler/internal/cache/debugger/dumper.go | 4 ++-- pkg/scheduler/internal/queue/scheduling_queue.go | 14 +++++++++----- .../internal/queue/scheduling_queue_test.go | 16 ++++++++++++++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/pkg/scheduler/internal/cache/debugger/comparer.go b/pkg/scheduler/internal/cache/debugger/comparer.go index 434e7e511b..ac0c1ff4d6 100644 --- a/pkg/scheduler/internal/cache/debugger/comparer.go +++ b/pkg/scheduler/internal/cache/debugger/comparer.go @@ -54,13 +54,13 @@ func (c *CacheComparer) Compare() error { snapshot := c.Cache.Snapshot() - waitingPods := c.PodQueue.WaitingPods() + pendingPods := c.PodQueue.PendingPods() if missed, redundant := c.CompareNodes(nodes, snapshot.Nodes); len(missed)+len(redundant) != 0 { klog.Warningf("cache mismatch: missed nodes: %s; redundant nodes: %s", missed, redundant) } - if missed, redundant := c.ComparePods(pods, waitingPods, snapshot.Nodes); len(missed)+len(redundant) != 0 { + if missed, redundant := c.ComparePods(pods, pendingPods, snapshot.Nodes); len(missed)+len(redundant) != 0 { klog.Warningf("cache mismatch: missed pods: %s; redundant pods: %s", missed, redundant) } diff --git a/pkg/scheduler/internal/cache/debugger/dumper.go b/pkg/scheduler/internal/cache/debugger/dumper.go index 5e94c06560..497d4b1b71 100644 --- a/pkg/scheduler/internal/cache/debugger/dumper.go +++ b/pkg/scheduler/internal/cache/debugger/dumper.go @@ -52,9 +52,9 @@ func (d *CacheDumper) dumpNodes() { // dumpSchedulingQueue writes pods in the scheduling queue to the scheduler logs. func (d *CacheDumper) dumpSchedulingQueue() { - waitingPods := d.podQueue.WaitingPods() + pendingPods := d.podQueue.PendingPods() var podData strings.Builder - for _, p := range waitingPods { + for _, p := range pendingPods { podData.WriteString(printPod(p)) } klog.Infof("Dump of scheduling queue:\n%s", podData.String()) diff --git a/pkg/scheduler/internal/queue/scheduling_queue.go b/pkg/scheduler/internal/queue/scheduling_queue.go index cb185fbf0b..a72aced91e 100644 --- a/pkg/scheduler/internal/queue/scheduling_queue.go +++ b/pkg/scheduler/internal/queue/scheduling_queue.go @@ -65,7 +65,7 @@ type SchedulingQueue interface { AssignedPodAdded(pod *v1.Pod) AssignedPodUpdated(pod *v1.Pod) WaitingPodsForNode(nodeName string) []*v1.Pod - WaitingPods() []*v1.Pod + PendingPods() []*v1.Pod // Close closes the SchedulingQueue so that the goroutine which is // waiting to pop items can exit gracefully. Close() @@ -131,8 +131,8 @@ func (f *FIFO) Pop() (*v1.Pod, error) { return result.(*v1.Pod), err } -// WaitingPods returns all the waiting pods in the queue. -func (f *FIFO) WaitingPods() []*v1.Pod { +// PendingPods returns all the pods in the queue. +func (f *FIFO) PendingPods() []*v1.Pod { result := []*v1.Pod{} for _, pod := range f.FIFO.List() { result = append(result, pod.(*v1.Pod)) @@ -675,8 +675,9 @@ func (p *PriorityQueue) WaitingPodsForNode(nodeName string) []*v1.Pod { return nil } -// WaitingPods returns all the waiting pods in the queue. -func (p *PriorityQueue) WaitingPods() []*v1.Pod { +// PendingPods returns all the pending pods in the queue. This function is +// used for debugging purposes in the scheduler cache dumper and comparer. +func (p *PriorityQueue) PendingPods() []*v1.Pod { p.lock.Lock() defer p.lock.Unlock() @@ -684,6 +685,9 @@ func (p *PriorityQueue) WaitingPods() []*v1.Pod { for _, pod := range p.activeQ.List() { result = append(result, pod.(*v1.Pod)) } + for _, pod := range p.podBackoffQ.List() { + result = append(result, pod.(*v1.Pod)) + } for _, pod := range p.unschedulableQ.pods { result = append(result, pod) } diff --git a/pkg/scheduler/internal/queue/scheduling_queue_test.go b/pkg/scheduler/internal/queue/scheduling_queue_test.go index 60c0d7b30d..7ac5fc1fbd 100644 --- a/pkg/scheduler/internal/queue/scheduling_queue_test.go +++ b/pkg/scheduler/internal/queue/scheduling_queue_test.go @@ -338,6 +338,22 @@ func TestPriorityQueue_WaitingPodsForNode(t *testing.T) { } } +func TestPriorityQueue_PendingPods(t *testing.T) { + q := NewPriorityQueue(nil) + q.Add(&medPriorityPod) + q.unschedulableQ.addOrUpdate(&unschedulablePod) + q.unschedulableQ.addOrUpdate(&highPriorityPod) + expectedList := []*v1.Pod{&medPriorityPod, &unschedulablePod, &highPriorityPod} + if !reflect.DeepEqual(expectedList, q.PendingPods()) { + t.Error("Unexpected list of pending Pods for node.") + } + // Move all to active queue. We should still see the same set of pods. + q.MoveAllToActiveQueue() + if !reflect.DeepEqual(expectedList, q.PendingPods()) { + t.Error("Unexpected list of pending Pods for node.") + } +} + func TestUnschedulablePodsMap(t *testing.T) { var pods = []*v1.Pod{ {