From 627e83c841f894138a819acda3ac374186295ecd Mon Sep 17 00:00:00 2001 From: Sharath P J Date: Fri, 24 Jan 2025 19:47:02 +0530 Subject: [PATCH 1/2] Passed context for Wait methods in integration test utils --- .../eventhandler/eventhandler_test.go | 2 +- .../scheduler/filters/filters_test.go | 2 +- .../scheduler/plugins/plugins_test.go | 50 +++++++++---------- .../scheduler/preemption/preemption_test.go | 45 ++++++++--------- .../scheduler/rescheduling_test.go | 2 +- test/integration/scheduler/scheduler_test.go | 22 ++++---- .../integration/scheduler/taint/taint_test.go | 2 +- test/integration/util/util.go | 12 ++--- 8 files changed, 68 insertions(+), 69 deletions(-) diff --git a/test/integration/scheduler/eventhandler/eventhandler_test.go b/test/integration/scheduler/eventhandler/eventhandler_test.go index 495d357d6f9..a1b4de21e72 100644 --- a/test/integration/scheduler/eventhandler/eventhandler_test.go +++ b/test/integration/scheduler/eventhandler/eventhandler_test.go @@ -131,7 +131,7 @@ func TestUpdateNodeEvent(t *testing.T) { t.Fatalf("Error updating the node: %v", err) } - if err := testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err := testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Pod %v was not scheduled: %v", pod.Name, err) } } diff --git a/test/integration/scheduler/filters/filters_test.go b/test/integration/scheduler/filters/filters_test.go index e4ff24dfd10..76db9056ca3 100644 --- a/test/integration/scheduler/filters/filters_test.go +++ b/test/integration/scheduler/filters/filters_test.go @@ -2165,7 +2165,7 @@ func TestUnschedulablePodBecomesSchedulable(t *testing.T) { if err := tt.update(testCtx.ClientSet, testCtx.NS.Name); err != nil { t.Fatal(err) } - if err := testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err := testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Pod %v was not scheduled: %v", pod.Name, err) } // Make sure pending queue is empty. diff --git a/test/integration/scheduler/plugins/plugins_test.go b/test/integration/scheduler/plugins/plugins_test.go index 71e4b68d1cc..a7776781374 100644 --- a/test/integration/scheduler/plugins/plugins_test.go +++ b/test/integration/scheduler/plugins/plugins_test.go @@ -693,7 +693,7 @@ func TestPreFilterPlugin(t *testing.T) { t.Errorf("Expected a scheduling error, but got: %v", err) } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } } @@ -873,7 +873,7 @@ func TestPostFilterPlugin(t *testing.T) { t.Errorf("Expected the score plugin to be called at least %v times, but got %v.", tt.expectScoreNumCalled, numScoreCalled) } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } if numFilterCalled := filterPlugin.deepCopy().numFilterCalled; numFilterCalled != tt.expectFilterNumCalled { @@ -935,7 +935,7 @@ func TestScorePlugin(t *testing.T) { t.Errorf("Expected a scheduling error, but got: %v", err) } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } else { p, err := testutils.GetPod(testCtx.ClientSet, pod.Name, pod.Namespace) @@ -971,7 +971,7 @@ func TestNormalizeScorePlugin(t *testing.T) { t.Fatalf("Error while creating a test pod: %v", err) } - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } @@ -1027,7 +1027,7 @@ func TestReservePluginReserve(t *testing.T) { t.Errorf("Didn't expect the pod to be scheduled. error: %v", err) } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } } @@ -1147,7 +1147,7 @@ func TestPrebindPlugin(t *testing.T) { if test.fail { if test.succeedOnRetry { - if err = testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, pod, 10*time.Second); err != nil { + if err = testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, pod, 10*time.Second); err != nil { t.Errorf("Expected the pod to be schedulable on retry, but got an error: %v", err) } } else if err = wait.PollUntilContextTimeout(testCtx.Ctx, 10*time.Millisecond, 30*time.Second, false, @@ -1158,7 +1158,7 @@ func TestPrebindPlugin(t *testing.T) { if err = testutils.WaitForPodUnschedulable(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be unschedulable") } - } else if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + } else if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } @@ -1314,7 +1314,7 @@ func TestUnReserveReservePlugins(t *testing.T) { } } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } @@ -1396,7 +1396,7 @@ func TestUnReservePermitPlugins(t *testing.T) { t.Errorf("Reserve Plugin %s numUnreserveCalled = %d, want 1.", reservePlugin.name, reservePlugin.numUnreserveCalled) } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } @@ -1468,7 +1468,7 @@ func TestUnReservePreBindPlugins(t *testing.T) { t.Errorf("Reserve Plugin %s numUnreserveCalled = %d, want 1.", reservePlugin.name, reservePlugin.numUnreserveCalled) } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } @@ -1540,7 +1540,7 @@ func TestUnReserveBindPlugins(t *testing.T) { t.Errorf("Reserve Plugin %s numUnreserveCalled = %d, want 1.", reservePlugin.name, reservePlugin.numUnreserveCalled) } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } @@ -1688,7 +1688,7 @@ func TestBindPlugin(t *testing.T) { if test.expectBoundByScheduler || test.expectBoundByPlugin { // bind plugins skipped to bind the pod - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Fatalf("Expected the pod to be scheduled. error: %v", err) } pod, err = testCtx.ClientSet.CoreV1().Pods(pod.Namespace).Get(testCtx.Ctx, pod.Name, metav1.GetOptions{}) @@ -1810,7 +1810,7 @@ func TestPostBindPlugin(t *testing.T) { t.Errorf("Didn't expect the postbind plugin to be called %d times.", postBindPlugin.numPostBindCalled) } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } select { @@ -1909,7 +1909,7 @@ func TestPermitPlugin(t *testing.T) { t.Errorf("Didn't expect the pod to be scheduled. error: %v", err) } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } } @@ -1966,7 +1966,7 @@ func TestMultiplePermitPlugins(t *testing.T) { } perPlugin2.allowAllPods() - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } @@ -2083,10 +2083,10 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) { permitPlugin.waitingPod, permitPlugin.rejectingPod) } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, podA); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, podA); err != nil { t.Errorf("Expected the first pod to be scheduled. error: %v", err) } - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, podB); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, podB); err != nil { t.Errorf("Expected the second pod to be scheduled. error: %v", err) } if !((permitPlugin.waitingPod == podA.Name && permitPlugin.allowingPod == podB.Name) || @@ -2150,7 +2150,7 @@ func TestFilterPlugin(t *testing.T) { t.Errorf("Expected the filter plugin to be called at least 1 time, but got %v.", filterPlugin.numFilterCalled) } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } if filterPlugin.numFilterCalled != 1 { @@ -2204,7 +2204,7 @@ func TestPreScorePlugin(t *testing.T) { t.Errorf("Expected a scheduling error, but got: %v", err) } } else { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) } } @@ -2258,7 +2258,7 @@ func TestPreEnqueuePlugin(t *testing.T) { } if tt.admitEnqueue { - if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, pod, 10*time.Second); err != nil { + if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, pod, 10*time.Second); err != nil { t.Errorf("Expected the pod to be schedulable, but got: %v", err) } // Also verify enqueuePlugin is called. @@ -2396,7 +2396,7 @@ func TestPreemptWithPermitPlugin(t *testing.T) { t.Fatalf("Error while creating the running pod: %v", err) } // Wait until the pod to be scheduled. - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, r); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, r); err != nil { t.Fatalf("The running pod is expected to be scheduled: %v", err) } } @@ -2425,7 +2425,7 @@ func TestPreemptWithPermitPlugin(t *testing.T) { t.Fatalf("Error while deleting the waiting pod: %v", err) } } - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, p); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, p); err != nil { t.Fatalf("Expected the preemptor pod to be scheduled. error: %v", err) } } @@ -2592,7 +2592,7 @@ func TestActivatePods(t *testing.T) { // Verify all pods to be scheduled. for _, pod := range pods { - if err := testutils.WaitForPodToScheduleWithTimeout(cs, pod, wait.ForeverTestTimeout); err != nil { + if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, cs, pod, wait.ForeverTestTimeout); err != nil { t.Fatalf("Failed to wait for Pod %v to be schedulable: %v", pod.Name, err) } } @@ -2768,7 +2768,7 @@ func TestPreEnqueuePluginEventsToRegister(t *testing.T) { } // Wait for the pod schedulabled. - if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, pausePod, 10*time.Second); err != nil { + if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, pausePod, 10*time.Second); err != nil { t.Errorf("Expected the pod to be schedulable, but got: %v", err) return } @@ -2810,7 +2810,7 @@ func TestPreEnqueuePluginEventsToRegister(t *testing.T) { } if expectedScheduled { - if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, gatedPod, 10*time.Second); err != nil { + if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, gatedPod, 10*time.Second); err != nil { t.Errorf("Expected the pod to be schedulable, but got: %v", err) } return diff --git a/test/integration/scheduler/preemption/preemption_test.go b/test/integration/scheduler/preemption/preemption_test.go index e633267a515..6e1c864e4c6 100644 --- a/test/integration/scheduler/preemption/preemption_test.go +++ b/test/integration/scheduler/preemption/preemption_test.go @@ -85,8 +85,8 @@ const filterPluginName = "filter-plugin" var lowPriority, mediumPriority, highPriority = int32(100), int32(200), int32(300) -func waitForNominatedNodeNameWithTimeout(cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error { - if err := wait.PollUntilContextTimeout(context.TODO(), 100*time.Millisecond, timeout, false, func(ctx context.Context) (bool, error) { +func waitForNominatedNodeNameWithTimeout(ctx context.Context, cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error { + if err := wait.PollUntilContextTimeout(ctx, 100*time.Millisecond, timeout, false, func(ctx context.Context) (bool, error) { pod, err := cs.CoreV1().Pods(pod.Namespace).Get(ctx, pod.Name, metav1.GetOptions{}) if err != nil { return false, err @@ -101,8 +101,8 @@ func waitForNominatedNodeNameWithTimeout(cs clientset.Interface, pod *v1.Pod, ti return nil } -func waitForNominatedNodeName(cs clientset.Interface, pod *v1.Pod) error { - return waitForNominatedNodeNameWithTimeout(cs, pod, wait.ForeverTestTimeout) +func waitForNominatedNodeName(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error { + return waitForNominatedNodeNameWithTimeout(ctx, cs, pod, wait.ForeverTestTimeout) } const tokenFilterName = "token-filter" @@ -505,7 +505,7 @@ func TestPreemption(t *testing.T) { } // Also check that the preemptor pod gets the NominatedNodeName field set. if len(test.preemptedPodIndexes) > 0 { - if err := waitForNominatedNodeName(cs, preemptor); err != nil { + if err := waitForNominatedNodeName(testCtx.Ctx, cs, preemptor); err != nil { t.Errorf("NominatedNodeName field was not set for pod %v: %v", preemptor.Name, err) } } @@ -1078,7 +1078,7 @@ func TestNonPreemption(t *testing.T) { if err != nil { t.Fatalf("Error while creating victim: %v", err) } - if err := waitForPodToScheduleWithTimeout(cs, victimPod, 5*time.Second); err != nil { + if err := waitForPodToScheduleWithTimeout(testCtx.Ctx, cs, victimPod, 5*time.Second); err != nil { t.Fatalf("victim %v should be become scheduled", victimPod.Name) } @@ -1087,7 +1087,7 @@ func TestNonPreemption(t *testing.T) { t.Fatalf("Error while creating preemptor: %v", err) } - err = waitForNominatedNodeNameWithTimeout(cs, preemptorPod, 5*time.Second) + err = waitForNominatedNodeNameWithTimeout(testCtx.Ctx, cs, preemptorPod, 5*time.Second) // test.PreemptionPolicy == nil means we expect the preemptor to be nominated. expect := test.PreemptionPolicy == nil // err == nil indicates the preemptor is indeed nominated. @@ -1169,7 +1169,7 @@ func TestDisablePreemption(t *testing.T) { } // Ensure preemptor should not be nominated. - if err := waitForNominatedNodeNameWithTimeout(cs, preemptor, 5*time.Second); err == nil { + if err := waitForNominatedNodeNameWithTimeout(testCtx.Ctx, cs, preemptor, 5*time.Second); err == nil { t.Errorf("Preemptor %v should not be nominated", preemptor.Name) } @@ -1358,7 +1358,7 @@ func TestPreemptionStarvation(t *testing.T) { } // make sure that runningPods are all scheduled. for _, p := range runningPods { - if err := testutils.WaitForPodToSchedule(cs, p); err != nil { + if err := testutils.WaitForPodToSchedule(testCtx.Ctx, cs, p); err != nil { t.Fatalf("Pod %v/%v didn't get scheduled: %v", p.Namespace, p.Name, err) } } @@ -1382,11 +1382,11 @@ func TestPreemptionStarvation(t *testing.T) { t.Errorf("Error while creating the preempting pod: %v", err) } // Check if .status.nominatedNodeName of the preemptor pod gets set. - if err := waitForNominatedNodeName(cs, preemptor); err != nil { + if err := waitForNominatedNodeName(testCtx.Ctx, cs, preemptor); err != nil { t.Errorf(".status.nominatedNodeName was not set for pod %v/%v: %v", preemptor.Namespace, preemptor.Name, err) } // Make sure that preemptor is scheduled after preemptions. - if err := testutils.WaitForPodToScheduleWithTimeout(cs, preemptor, 60*time.Second); err != nil { + if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, cs, preemptor, 60*time.Second); err != nil { t.Errorf("Preemptor pod %v didn't get scheduled: %v", preemptor.Name, err) } // Cleanup @@ -1463,7 +1463,7 @@ func TestPreemptionRaces(t *testing.T) { } // make sure that initial Pods are all scheduled. for _, p := range initialPods { - if err := testutils.WaitForPodToSchedule(cs, p); err != nil { + if err := testutils.WaitForPodToSchedule(testCtx.Ctx, cs, p); err != nil { t.Fatalf("Pod %v/%v didn't get scheduled: %v", p.Namespace, p.Name, err) } } @@ -1482,11 +1482,11 @@ func TestPreemptionRaces(t *testing.T) { } } // Check that the preemptor pod gets nominated node name. - if err := waitForNominatedNodeName(cs, preemptor); err != nil { + if err := waitForNominatedNodeName(testCtx.Ctx, cs, preemptor); err != nil { t.Errorf(".status.nominatedNodeName was not set for pod %v/%v: %v", preemptor.Namespace, preemptor.Name, err) } // Make sure that preemptor is scheduled after preemptions. - if err := testutils.WaitForPodToScheduleWithTimeout(cs, preemptor, 60*time.Second); err != nil { + if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, cs, preemptor, 60*time.Second); err != nil { t.Errorf("Preemptor pod %v didn't get scheduled: %v", preemptor.Name, err) } @@ -1549,7 +1549,7 @@ func TestNominatedNodeCleanUp(t *testing.T) { // A slice of pods to be created in batch. podsToCreate [][]*v1.Pod // Each postCheck function is run after each batch of pods' creation. - postChecks []func(cs clientset.Interface, pod *v1.Pod) error + postChecks []func(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error // Delete the fake node or not. Optional. deleteNode bool // Pods to be deleted. Optional. @@ -1576,7 +1576,7 @@ func TestNominatedNodeCleanUp(t *testing.T) { st.MakePod().Name("high").Priority(highPriority).Req(map[v1.ResourceName]string{v1.ResourceCPU: "3"}).Obj(), }, }, - postChecks: []func(cs clientset.Interface, pod *v1.Pod) error{ + postChecks: []func(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error{ testutils.WaitForPodToSchedule, waitForNominatedNodeName, waitForNominatedNodeName, @@ -1596,8 +1596,7 @@ func TestNominatedNodeCleanUp(t *testing.T) { st.MakePod().Name("high").Priority(highPriority).Req(map[v1.ResourceName]string{v1.ResourceCPU: "1"}).Obj(), }, }, - postChecks: []func(cs clientset.Interface, pod *v1.Pod) error{ - testutils.WaitForPodToSchedule, + postChecks: []func(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error{ waitForNominatedNodeName, testutils.WaitForPodToSchedule, }, @@ -1614,7 +1613,7 @@ func TestNominatedNodeCleanUp(t *testing.T) { st.MakePod().Name("medium").Priority(mediumPriority).Req(map[v1.ResourceName]string{v1.ResourceCPU: "1"}).Obj(), }, }, - postChecks: []func(cs clientset.Interface, pod *v1.Pod) error{ + postChecks: []func(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error{ testutils.WaitForPodToSchedule, waitForNominatedNodeName, }, @@ -1633,7 +1632,7 @@ func TestNominatedNodeCleanUp(t *testing.T) { st.MakePod().Name("medium").Priority(mediumPriority).Req(map[v1.ResourceName]string{v1.ResourceCPU: "1"}).Obj(), }, }, - postChecks: []func(cs clientset.Interface, pod *v1.Pod) error{ + postChecks: []func(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error{ testutils.WaitForPodToSchedule, waitForNominatedNodeName, }, @@ -1683,7 +1682,7 @@ func TestNominatedNodeCleanUp(t *testing.T) { // If necessary, run the post check function. if len(tt.postChecks) > i && tt.postChecks[i] != nil { for _, p := range pods { - if err := tt.postChecks[i](cs, p); err != nil { + if err := tt.postChecks[i](testCtx.Ctx, cs, p); err != nil { t.Fatalf("Pod %v didn't pass the postChecks[%v]: %v", p.Name, i, err) } } @@ -1991,7 +1990,7 @@ func TestPDBInPreemption(t *testing.T) { } // Also check if .status.nominatedNodeName of the preemptor pod gets set. if len(test.preemptedPodIndexes) > 0 { - if err := waitForNominatedNodeName(cs, preemptor); err != nil { + if err := waitForNominatedNodeName(testCtx.Ctx, cs, preemptor); err != nil { t.Errorf("Test [%v]: .status.nominatedNodeName was not set for pod %v/%v: %v", test.name, preemptor.Namespace, preemptor.Name, err) } } @@ -2484,7 +2483,7 @@ func TestReadWriteOncePodPreemption(t *testing.T) { } // Also check that the preemptor pod gets the NominatedNodeName field set. if len(test.preemptedPodIndexes) > 0 { - if err := waitForNominatedNodeName(cs, preemptor); err != nil { + if err := waitForNominatedNodeName(testCtx.Ctx, cs, preemptor); err != nil { t.Errorf("NominatedNodeName field was not set for pod %v: %v", preemptor.Name, err) } } diff --git a/test/integration/scheduler/rescheduling_test.go b/test/integration/scheduler/rescheduling_test.go index be09574293e..8b6aae8aacf 100644 --- a/test/integration/scheduler/rescheduling_test.go +++ b/test/integration/scheduler/rescheduling_test.go @@ -235,7 +235,7 @@ func TestReScheduling(t *testing.T) { } if test.wantScheduled { - if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { + if err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, pod); err != nil { t.Errorf("Didn't expect the pod to be unschedulable. error: %v", err) } } else if test.wantError { diff --git a/test/integration/scheduler/scheduler_test.go b/test/integration/scheduler/scheduler_test.go index 6bf07b477e1..12daf32a022 100644 --- a/test/integration/scheduler/scheduler_test.go +++ b/test/integration/scheduler/scheduler_test.go @@ -141,7 +141,7 @@ func TestUnschedulableNodes(t *testing.T) { } // There are no schedulable nodes - the pod shouldn't be scheduled. - err = testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, myPod, 2*time.Second) + err = testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, myPod, 2*time.Second) if err == nil { t.Errorf("Test %d: Pod scheduled successfully on unschedulable nodes", i) } @@ -159,7 +159,7 @@ func TestUnschedulableNodes(t *testing.T) { mod.makeSchedulable(t, schedNode, nodeLister, testCtx.ClientSet) // Wait until the pod is scheduled. - if err := testutils.WaitForPodToSchedule(testCtx.ClientSet, myPod); err != nil { + if err := testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, myPod); err != nil { t.Errorf("Test %d: failed to schedule a pod: %v", i, err) } else { t.Logf("Test %d: Pod got scheduled on a schedulable node", i) @@ -227,19 +227,19 @@ func TestMultipleSchedulers(t *testing.T) { // - testPod, testPodFitsDefault should be scheduled // - testPodFitsFoo should NOT be scheduled t.Logf("wait for pods scheduled") - if err := testutils.WaitForPodToSchedule(testCtx.ClientSet, testPod); err != nil { + if err := testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, testPod); err != nil { t.Errorf("Test MultiScheduler: %s Pod not scheduled: %v", testPod.Name, err) } else { t.Logf("Test MultiScheduler: %s Pod scheduled", testPod.Name) } - if err := testutils.WaitForPodToSchedule(testCtx.ClientSet, testPodFitsDefault); err != nil { + if err := testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, testPodFitsDefault); err != nil { t.Errorf("Test MultiScheduler: %s Pod not scheduled: %v", testPodFitsDefault.Name, err) } else { t.Logf("Test MultiScheduler: %s Pod scheduled", testPodFitsDefault.Name) } - if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, testPodFitsFoo, time.Second*5); err == nil { + if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, testPodFitsFoo, time.Second*5); err == nil { t.Errorf("Test MultiScheduler: %s Pod got scheduled, %v", testPodFitsFoo.Name, err) } else { t.Logf("Test MultiScheduler: %s Pod not scheduled", testPodFitsFoo.Name) @@ -267,7 +267,7 @@ func TestMultipleSchedulers(t *testing.T) { // 6. **check point-2**: // - testPodWithAnnotationFitsFoo should be scheduled - err = testutils.WaitForPodToSchedule(testCtx.ClientSet, testPodFitsFoo) + err = testutils.WaitForPodToSchedule(testCtx.Ctx, testCtx.ClientSet, testPodFitsFoo) if err != nil { t.Errorf("Test MultiScheduler: %s Pod not scheduled, %v", testPodFitsFoo.Name, err) } else { @@ -371,7 +371,7 @@ func TestAllocatable(t *testing.T) { } // 4. Test: this test pod should be scheduled since api-server will use Capacity as Allocatable - err = testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, testAllocPod, time.Second*5) + err = testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, testAllocPod, time.Second*5) if err != nil { t.Errorf("Test allocatable unawareness: %s Pod not scheduled: %v", testAllocPod.Name, err) } else { @@ -408,7 +408,7 @@ func TestAllocatable(t *testing.T) { } // 7. Test: this test pod should not be scheduled since it request more than Allocatable - if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, testAllocPod2, time.Second*5); err == nil { + if err := testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, testAllocPod2, time.Second*5); err == nil { t.Errorf("Test allocatable awareness: %s Pod got scheduled unexpectedly, %v", testAllocPod2.Name, err) } else { t.Logf("Test allocatable awareness: %s Pod not scheduled as expected", testAllocPod2.Name) @@ -575,7 +575,7 @@ func TestNodeEvents(t *testing.T) { } // 1.3 verify pod1 is scheduled - err = testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, pod1, time.Second*5) + err = testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, pod1, time.Second*5) if err != nil { t.Errorf("Pod %s didn't schedule: %v", pod1.Name, err) } @@ -615,7 +615,7 @@ func TestNodeEvents(t *testing.T) { if err != nil { t.Fatalf("Failed to create pod %v: %v", plugPod.Name, err) } - err = testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, plugPod, time.Second*5) + err = testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, plugPod, time.Second*5) if err != nil { t.Errorf("Pod %s didn't schedule: %v", plugPod.Name, err) } @@ -632,7 +632,7 @@ func TestNodeEvents(t *testing.T) { t.Fatalf("Failed to update %s: %v", node2.Name, err) } - err = testutils.WaitForPodToScheduleWithTimeout(testCtx.ClientSet, pod2, time.Second*5) + err = testutils.WaitForPodToScheduleWithTimeout(testCtx.Ctx, testCtx.ClientSet, pod2, time.Second*5) if err != nil { t.Errorf("Pod %s didn't schedule: %v", pod2.Name, err) } diff --git a/test/integration/scheduler/taint/taint_test.go b/test/integration/scheduler/taint/taint_test.go index 720d9f79828..0777a7e140a 100644 --- a/test/integration/scheduler/taint/taint_test.go +++ b/test/integration/scheduler/taint/taint_test.go @@ -545,7 +545,7 @@ func TestTaintNodeByCondition(t *testing.T) { pods = append(pods, createdPod) if p.fits { - if err := testutils.WaitForPodToSchedule(cs, createdPod); err != nil { + if err := testutils.WaitForPodToSchedule(testCtx.Ctx, cs, createdPod); err != nil { t.Errorf("Failed to schedule pod %s/%s on the node, err: %v", pod.Namespace, pod.Name, err) } diff --git a/test/integration/util/util.go b/test/integration/util/util.go index 989271c6383..7eeb288771f 100644 --- a/test/integration/util/util.go +++ b/test/integration/util/util.go @@ -631,14 +631,14 @@ func InitTestSchedulerWithOptions( // WaitForPodToScheduleWithTimeout waits for a pod to get scheduled and returns // an error if it does not scheduled within the given timeout. -func WaitForPodToScheduleWithTimeout(cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error { - return wait.PollUntilContextTimeout(context.TODO(), 100*time.Millisecond, timeout, false, PodScheduled(cs, pod.Namespace, pod.Name)) +func WaitForPodToScheduleWithTimeout(ctx context.Context, cs clientset.Interface, pod *v1.Pod, timeout time.Duration) error { + return wait.PollUntilContextTimeout(ctx, 100*time.Millisecond, timeout, false, PodScheduled(cs, pod.Namespace, pod.Name)) } // WaitForPodToSchedule waits for a pod to get scheduled and returns an error if // it does not get scheduled within the timeout duration (30 seconds). -func WaitForPodToSchedule(cs clientset.Interface, pod *v1.Pod) error { - return WaitForPodToScheduleWithTimeout(cs, pod, 30*time.Second) +func WaitForPodToSchedule(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error { + return WaitForPodToScheduleWithTimeout(ctx, cs, pod, 30*time.Second) } // PodScheduled checks if the pod has been scheduled @@ -904,7 +904,7 @@ func RunPausePod(cs clientset.Interface, pod *v1.Pod) (*v1.Pod, error) { if err != nil { return nil, fmt.Errorf("failed to create pause pod: %v", err) } - if err = WaitForPodToSchedule(cs, pod); err != nil { + if err = WaitForPodToSchedule(context.TODO(), cs, pod); err != nil { return pod, fmt.Errorf("Pod %v/%v didn't schedule successfully. Error: %v", pod.Namespace, pod.Name, err) } if pod, err = cs.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{}); err != nil { @@ -941,7 +941,7 @@ func RunPodWithContainers(cs clientset.Interface, pod *v1.Pod) (*v1.Pod, error) if err != nil { return nil, fmt.Errorf("failed to create pod-with-containers: %v", err) } - if err = WaitForPodToSchedule(cs, pod); err != nil { + if err = WaitForPodToSchedule(context.TODO(), cs, pod); err != nil { return pod, fmt.Errorf("Pod %v didn't schedule successfully. Error: %v", pod.Name, err) } if pod, err = cs.CoreV1().Pods(pod.Namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{}); err != nil { From 44ca3b365455b0a20f5820487ac3743045914ff8 Mon Sep 17 00:00:00 2001 From: Sharath P J Date: Fri, 24 Jan 2025 19:47:02 +0530 Subject: [PATCH 2/2] Passed context for Wait methods in integration test utils --- test/integration/scheduler/preemption/preemption_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/scheduler/preemption/preemption_test.go b/test/integration/scheduler/preemption/preemption_test.go index 6e1c864e4c6..98798ff06af 100644 --- a/test/integration/scheduler/preemption/preemption_test.go +++ b/test/integration/scheduler/preemption/preemption_test.go @@ -1597,6 +1597,7 @@ func TestNominatedNodeCleanUp(t *testing.T) { }, }, postChecks: []func(ctx context.Context, cs clientset.Interface, pod *v1.Pod) error{ + testutils.WaitForPodToSchedule, waitForNominatedNodeName, testutils.WaitForPodToSchedule, },