From eeb6e791d9ebb71cda766c71e995b2688de2463c Mon Sep 17 00:00:00 2001 From: kerthcet Date: Wed, 24 Aug 2022 16:02:21 +0800 Subject: [PATCH 1/3] fix error type Signed-off-by: kerthcet --- pkg/scheduler/schedule_one.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/scheduler/schedule_one.go b/pkg/scheduler/schedule_one.go index 233ea311a1b..52ce257bc6a 100644 --- a/pkg/scheduler/schedule_one.go +++ b/pkg/scheduler/schedule_one.go @@ -122,6 +122,7 @@ func (sched *Scheduler) schedulingCycle(ctx context.Context, state *framework.Cy // will fit due to the preemption. It is also possible that a different pod will schedule // into the resources that were preempted, but this is harmless. var nominatingInfo *framework.NominatingInfo + reason := v1.PodReasonUnschedulable if fitError, ok := err.(*framework.FitError); ok { if !fwk.HasPostFilterPlugins() { klog.V(3).InfoS("No PostFilter plugins are registered, so no preemption will be performed") @@ -150,8 +151,9 @@ func (sched *Scheduler) schedulingCycle(ctx context.Context, state *framework.Cy nominatingInfo = clearNominatedNode klog.ErrorS(err, "Error selecting node for pod", "pod", klog.KObj(pod)) metrics.PodScheduleError(fwk.ProfileName(), metrics.SinceInSeconds(start)) + reason = SchedulerError } - sched.FailureHandler(ctx, fwk, podInfo, err, v1.PodReasonUnschedulable, nominatingInfo) + sched.FailureHandler(ctx, fwk, podInfo, err, reason, nominatingInfo) return ScheduleResult{}, nil } metrics.SchedulingAlgorithmLatency.Observe(metrics.SinceInSeconds(start)) From dd4fb3cd37d3f122a8d5cf2d9c9dcc1545d17ed3 Mon Sep 17 00:00:00 2001 From: kerthcet Date: Thu, 25 Aug 2022 13:29:09 +0800 Subject: [PATCH 2/3] fix test error Signed-off-by: kerthcet --- test/integration/scheduler/plugins/plugins_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/integration/scheduler/plugins/plugins_test.go b/test/integration/scheduler/plugins/plugins_test.go index 44b191b4802..2e881595c72 100644 --- a/test/integration/scheduler/plugins/plugins_test.go +++ b/test/integration/scheduler/plugins/plugins_test.go @@ -581,10 +581,14 @@ func TestPreFilterPlugin(t *testing.T) { t.Errorf("Error while creating a test pod: %v", err) } - if test.reject || test.fail { + if test.reject { if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil { t.Errorf("Didn't expect the pod to be scheduled. error: %v", err) } + } else if test.fail { + if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil { + t.Errorf("Expected a scheduling error, but got: %v", err) + } } else { if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { t.Errorf("Expected the pod to be scheduled. error: %v", err) From e61c16cc958f3a832be9071fdc0455c2bc9d9ecf Mon Sep 17 00:00:00 2001 From: kerthcet Date: Thu, 25 Aug 2022 15:33:10 +0800 Subject: [PATCH 3/3] fix tests Signed-off-by: kerthcet --- test/integration/scheduler/plugins/plugins_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/integration/scheduler/plugins/plugins_test.go b/test/integration/scheduler/plugins/plugins_test.go index 2e881595c72..e0fbd31b8d1 100644 --- a/test/integration/scheduler/plugins/plugins_test.go +++ b/test/integration/scheduler/plugins/plugins_test.go @@ -794,8 +794,8 @@ func TestScorePlugin(t *testing.T) { } if test.fail { - if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil { - t.Errorf("Didn't expect the pod to be scheduled. error: %v", err) + if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil { + t.Errorf("Expected a scheduling error, but got: %v", err) } } else { if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil { @@ -2014,8 +2014,8 @@ func TestFilterPlugin(t *testing.T) { } if test.fail { - if err = wait.Poll(10*time.Millisecond, 30*time.Second, podUnschedulable(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil { - t.Errorf("Didn't expect the pod to be scheduled.") + if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil { + t.Errorf("Expected a scheduling error, but got: %v", err) } if filterPlugin.numFilterCalled < 1 { t.Errorf("Expected the filter plugin to be called at least 1 time, but got %v.", filterPlugin.numFilterCalled) @@ -2072,8 +2072,8 @@ func TestPreScorePlugin(t *testing.T) { } if test.fail { - if err = waitForPodUnschedulable(testCtx.ClientSet, pod); err != nil { - t.Errorf("Didn't expect the pod to be scheduled. error: %v", err) + if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(testCtx.ClientSet, pod.Namespace, pod.Name)); err != nil { + t.Errorf("Expected a scheduling error, but got: %v", err) } } else { if err = testutils.WaitForPodToSchedule(testCtx.ClientSet, pod); err != nil {