Add pods in the backoff queue to the list of pending pods

pull/564/head
Bobby (Babak) Salamat 2018-12-20 17:28:23 -08:00
parent 29b3ec9108
commit 48b6f75829
4 changed files with 29 additions and 9 deletions

View File

@ -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)
}

View File

@ -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())

View File

@ -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)
}

View File

@ -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{
{