mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Expose a pending pods summary in scheudler's dummper output
This commit is contained in:
parent
64ed914545
commit
7df9bfcfef
@ -54,7 +54,7 @@ func (c *CacheComparer) Compare() error {
|
|||||||
|
|
||||||
dump := c.Cache.Dump()
|
dump := c.Cache.Dump()
|
||||||
|
|
||||||
pendingPods := c.PodQueue.PendingPods()
|
pendingPods, _ := c.PodQueue.PendingPods()
|
||||||
|
|
||||||
if missed, redundant := c.CompareNodes(nodes, dump.Nodes); len(missed)+len(redundant) != 0 {
|
if missed, redundant := c.CompareNodes(nodes, dump.Nodes); len(missed)+len(redundant) != 0 {
|
||||||
klog.InfoS("Cache mismatch", "missedNodes", missed, "redundantNodes", redundant)
|
klog.InfoS("Cache mismatch", "missedNodes", missed, "redundantNodes", redundant)
|
||||||
|
@ -54,12 +54,12 @@ func (d *CacheDumper) dumpNodes() {
|
|||||||
|
|
||||||
// dumpSchedulingQueue writes pods in the scheduling queue to the scheduler logs.
|
// dumpSchedulingQueue writes pods in the scheduling queue to the scheduler logs.
|
||||||
func (d *CacheDumper) dumpSchedulingQueue() {
|
func (d *CacheDumper) dumpSchedulingQueue() {
|
||||||
pendingPods := d.podQueue.PendingPods()
|
pendingPods, s := d.podQueue.PendingPods()
|
||||||
var podData strings.Builder
|
var podData strings.Builder
|
||||||
for _, p := range pendingPods {
|
for _, p := range pendingPods {
|
||||||
podData.WriteString(printPod(p))
|
podData.WriteString(printPod(p))
|
||||||
}
|
}
|
||||||
klog.InfoS("Dump of scheduling queue", "pods", podData.String())
|
klog.InfoS("Dump of scheduling queue", "summary", s, "pods", podData.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// printNodeInfo writes parts of NodeInfo to a string.
|
// printNodeInfo writes parts of NodeInfo to a string.
|
||||||
|
@ -102,7 +102,7 @@ type SchedulingQueue interface {
|
|||||||
MoveAllToActiveOrBackoffQueue(event framework.ClusterEvent, preCheck PreEnqueueCheck)
|
MoveAllToActiveOrBackoffQueue(event framework.ClusterEvent, preCheck PreEnqueueCheck)
|
||||||
AssignedPodAdded(pod *v1.Pod)
|
AssignedPodAdded(pod *v1.Pod)
|
||||||
AssignedPodUpdated(pod *v1.Pod)
|
AssignedPodUpdated(pod *v1.Pod)
|
||||||
PendingPods() []*v1.Pod
|
PendingPods() ([]*v1.Pod, string)
|
||||||
// Close closes the SchedulingQueue so that the goroutine which is
|
// Close closes the SchedulingQueue so that the goroutine which is
|
||||||
// waiting to pop items can exit gracefully.
|
// waiting to pop items can exit gracefully.
|
||||||
Close()
|
Close()
|
||||||
@ -678,9 +678,12 @@ func (p *PriorityQueue) getUnschedulablePodsWithMatchingAffinityTerm(pod *v1.Pod
|
|||||||
return podsToMove
|
return podsToMove
|
||||||
}
|
}
|
||||||
|
|
||||||
// PendingPods returns all the pending pods in the queue. This function is
|
var pendingPodsSummary = "activeQ:%v; backoffQ:%v; unschedulablePods:%v"
|
||||||
// used for debugging purposes in the scheduler cache dumper and comparer.
|
|
||||||
func (p *PriorityQueue) PendingPods() []*v1.Pod {
|
// PendingPods returns all the pending pods in the queue; accompanied by a debugging string
|
||||||
|
// recording showing the number of pods in each queue respectively.
|
||||||
|
// This function is used for debugging purposes in the scheduler cache dumper and comparer.
|
||||||
|
func (p *PriorityQueue) PendingPods() ([]*v1.Pod, string) {
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
var result []*v1.Pod
|
var result []*v1.Pod
|
||||||
@ -693,7 +696,7 @@ func (p *PriorityQueue) PendingPods() []*v1.Pod {
|
|||||||
for _, pInfo := range p.unschedulablePods.podInfoMap {
|
for _, pInfo := range p.unschedulablePods.podInfoMap {
|
||||||
result = append(result, pInfo.Pod)
|
result = append(result, pInfo.Pod)
|
||||||
}
|
}
|
||||||
return result
|
return result, fmt.Sprintf(pendingPodsSummary, p.activeQ.Len(), p.podBackoffQ.Len(), len(p.unschedulablePods.podInfoMap))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes the priority queue.
|
// Close closes the priority queue.
|
||||||
|
@ -745,13 +745,21 @@ func TestPriorityQueue_PendingPods(t *testing.T) {
|
|||||||
q.AddUnschedulableIfNotPresent(q.newQueuedPodInfo(highPriorityPodInfo.Pod), q.SchedulingCycle())
|
q.AddUnschedulableIfNotPresent(q.newQueuedPodInfo(highPriorityPodInfo.Pod), q.SchedulingCycle())
|
||||||
|
|
||||||
expectedSet := makeSet([]*v1.Pod{medPriorityPodInfo.Pod, unschedulablePodInfo.Pod, highPriorityPodInfo.Pod})
|
expectedSet := makeSet([]*v1.Pod{medPriorityPodInfo.Pod, unschedulablePodInfo.Pod, highPriorityPodInfo.Pod})
|
||||||
if !reflect.DeepEqual(expectedSet, makeSet(q.PendingPods())) {
|
gotPods, gotSummary := q.PendingPods()
|
||||||
|
if !reflect.DeepEqual(expectedSet, makeSet(gotPods)) {
|
||||||
t.Error("Unexpected list of pending Pods.")
|
t.Error("Unexpected list of pending Pods.")
|
||||||
}
|
}
|
||||||
|
if wantSummary := fmt.Sprintf(pendingPodsSummary, 1, 0, 2); wantSummary != gotSummary {
|
||||||
|
t.Errorf("Unexpected pending pods summary: want %v, but got %v.", wantSummary, gotSummary)
|
||||||
|
}
|
||||||
// Move all to active queue. We should still see the same set of pods.
|
// Move all to active queue. We should still see the same set of pods.
|
||||||
q.MoveAllToActiveOrBackoffQueue(TestEvent, nil)
|
q.MoveAllToActiveOrBackoffQueue(TestEvent, nil)
|
||||||
if !reflect.DeepEqual(expectedSet, makeSet(q.PendingPods())) {
|
gotPods, gotSummary = q.PendingPods()
|
||||||
t.Error("Unexpected list of pending Pods...")
|
if !reflect.DeepEqual(expectedSet, makeSet(gotPods)) {
|
||||||
|
t.Error("Unexpected list of pending Pods.")
|
||||||
|
}
|
||||||
|
if wantSummary := fmt.Sprintf(pendingPodsSummary, 1, 2, 0); wantSummary != gotSummary {
|
||||||
|
t.Errorf("Unexpected pending pods summary: want %v, but got %v.", wantSummary, gotSummary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,7 +418,7 @@ func TestFailureHandler_PodAlreadyBound(t *testing.T) {
|
|||||||
// getPodFromPriorityQueue is the function used in the TestDefaultErrorFunc test to get
|
// getPodFromPriorityQueue is the function used in the TestDefaultErrorFunc test to get
|
||||||
// the specific pod from the given priority queue. It returns the found pod in the priority queue.
|
// the specific pod from the given priority queue. It returns the found pod in the priority queue.
|
||||||
func getPodFromPriorityQueue(queue *internalqueue.PriorityQueue, pod *v1.Pod) *v1.Pod {
|
func getPodFromPriorityQueue(queue *internalqueue.PriorityQueue, pod *v1.Pod) *v1.Pod {
|
||||||
podList := queue.PendingPods()
|
podList, _ := queue.PendingPods()
|
||||||
if len(podList) == 0 {
|
if len(podList) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1713,9 +1713,9 @@ func TestUnschedulablePodBecomesSchedulable(t *testing.T) {
|
|||||||
t.Errorf("Pod %v was not scheduled: %v", pod.Name, err)
|
t.Errorf("Pod %v was not scheduled: %v", pod.Name, err)
|
||||||
}
|
}
|
||||||
// Make sure pending queue is empty.
|
// Make sure pending queue is empty.
|
||||||
pendingPods := len(testCtx.Scheduler.SchedulingQueue.PendingPods())
|
pendingPods, s := testCtx.Scheduler.SchedulingQueue.PendingPods()
|
||||||
if pendingPods != 0 {
|
if len(pendingPods) != 0 {
|
||||||
t.Errorf("pending pods queue is not empty, size is: %d", pendingPods)
|
t.Errorf("pending pods queue is not empty, size is: %d, summary is: %s", len(pendingPods), s)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,8 @@ func TestCoreResourceEnqueue(t *testing.T) {
|
|||||||
|
|
||||||
// Wait for the three pods to be present in the scheduling queue.
|
// Wait for the three pods to be present in the scheduling queue.
|
||||||
if err := wait.Poll(time.Millisecond*200, wait.ForeverTestTimeout, func() (bool, error) {
|
if err := wait.Poll(time.Millisecond*200, wait.ForeverTestTimeout, func() (bool, error) {
|
||||||
return len(testCtx.Scheduler.SchedulingQueue.PendingPods()) == 3, nil
|
pendingPods, _ := testCtx.Scheduler.SchedulingQueue.PendingPods()
|
||||||
|
return len(pendingPods) == 3, nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -263,7 +264,8 @@ func TestCustomResourceEnqueue(t *testing.T) {
|
|||||||
|
|
||||||
// Wait for the testing Pod to be present in the scheduling queue.
|
// Wait for the testing Pod to be present in the scheduling queue.
|
||||||
if err := wait.Poll(time.Millisecond*200, wait.ForeverTestTimeout, func() (bool, error) {
|
if err := wait.Poll(time.Millisecond*200, wait.ForeverTestTimeout, func() (bool, error) {
|
||||||
return len(testCtx.Scheduler.SchedulingQueue.PendingPods()) == 1, nil
|
pendingPods, _ := testCtx.Scheduler.SchedulingQueue.PendingPods()
|
||||||
|
return len(pendingPods) == 1, nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user