Skip to content

Commit

Permalink
Merge pull request #120557 from pohly/automated-cherry-pick-of-#12033…
Browse files Browse the repository at this point in the history
…4-origin-release-1.26

Automated cherry pick of #120334: scheduler: start scheduling attempt with clean
  • Loading branch information
k8s-ci-robot committed Sep 21, 2023
2 parents 3f4f421 + ad177b6 commit 9bbb813
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/scheduler/internal/queue/scheduling_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ func (p *PriorityQueue) Pop() (*framework.QueuedPodInfo, error) {
pInfo := obj.(*framework.QueuedPodInfo)
pInfo.Attempts++
p.schedulingCycle++

// Reset the set of unschedulable plugins for the next attempt.
pInfo.UnschedulablePlugins = sets.NewString()

return pInfo, nil
}

Expand Down
44 changes: 44 additions & 0 deletions pkg/scheduler/internal/queue/scheduling_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/component-base/metrics/testutil"
"k8s.io/klog/v2/ktesting"
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
"k8s.io/kubernetes/pkg/scheduler/framework"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort"
Expand Down Expand Up @@ -155,6 +156,49 @@ func TestPriorityQueue_AddWithReversePriorityLessFunc(t *testing.T) {
}
}

func popPod(t *testing.T, q *PriorityQueue, pod *v1.Pod) *framework.QueuedPodInfo {
p, err := q.Pop()
if err != nil {
t.Fatalf("Pop failed: %v", err)
}
if p.Pod.UID != pod.UID {
t.Errorf("Unexpected popped pod: %v", p)
}
return p
}

func TestPop(t *testing.T) {
pod := st.MakePod().Name("targetpod").UID("pod1").Obj()
plugin := "fooPlugin1"
m := map[framework.ClusterEvent]sets.String{PvAdd: sets.NewString(plugin)}
_, ctx := ktesting.NewTestContext(t)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
q := NewTestQueueWithObjects(ctx, newDefaultQueueSort(), []runtime.Object{pod}, WithClusterEventMap(m))

// Disable backoff. Otherwise MoveAllToActiveOrBackoffQueue below will pick the backoff queue
// when running this test quickly.
q.podInitialBackoffDuration = 0

q.Add(pod)

// Simulate failed attempt that makes the pod unschedulable.
poppedPod := popPod(t, q, pod)
poppedPod.UnschedulablePlugins = sets.NewString(plugin)
if err := q.AddUnschedulableIfNotPresent(poppedPod, q.SchedulingCycle()); err != nil {
t.Errorf("Unexpected error from AddUnschedulableIfNotPresent: %v", err)
}

// Activate it again.
q.MoveAllToActiveOrBackoffQueue(PvAdd, nil)

// Now check result of Pop.
poppedPod = popPod(t, q, pod)
if len(poppedPod.UnschedulablePlugins) > 0 {
t.Errorf("QueuedPodInfo from Pop should have empty UnschedulablePlugins, got instead: %+v", poppedPod)
}
}

func TestPriorityQueue_AddUnschedulableIfNotPresent(t *testing.T) {
objs := []runtime.Object{highPriNominatedPodInfo.Pod, unschedulablePodInfo.Pod}
ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit 9bbb813

Please sign in to comment.