diff --git a/pkg/scheduler/framework/interface.go b/pkg/scheduler/framework/interface.go index 5f14fe03110..16b84c7716e 100644 --- a/pkg/scheduler/framework/interface.go +++ b/pkg/scheduler/framework/interface.go @@ -193,16 +193,21 @@ func (s *Status) IsSuccess() bool { return s.Code() == Success } +// IsWait returns true if and only if "Status" is non-nil and its Code is "Wait". +func (s *Status) IsWait() bool { + return s.Code() == Wait +} + // IsUnschedulable returns true if "Status" is Unschedulable (Unschedulable or UnschedulableAndUnresolvable). func (s *Status) IsUnschedulable() bool { code := s.Code() return code == Unschedulable || code == UnschedulableAndUnresolvable } -// AsError returns nil if the status is a success; otherwise returns an "error" object +// AsError returns nil if the status is a success or a wait; otherwise returns an "error" object // with a concatenated message on reasons of the Status. func (s *Status) AsError() error { - if s.IsSuccess() { + if s.IsSuccess() || s.IsWait() { return nil } if s.err != nil { diff --git a/pkg/scheduler/framework/interface_test.go b/pkg/scheduler/framework/interface_test.go index c299d6928ec..8a521506aed 100644 --- a/pkg/scheduler/framework/interface_test.go +++ b/pkg/scheduler/framework/interface_test.go @@ -34,6 +34,7 @@ func TestStatus(t *testing.T) { expectedCode Code expectedMessage string expectedIsSuccess bool + expectedIsWait bool expectedAsError error }{ { @@ -42,6 +43,16 @@ func TestStatus(t *testing.T) { expectedCode: Success, expectedMessage: "", expectedIsSuccess: true, + expectedIsWait: false, + expectedAsError: nil, + }, + { + name: "wait status", + status: NewStatus(Wait, ""), + expectedCode: Wait, + expectedMessage: "", + expectedIsSuccess: false, + expectedIsWait: true, expectedAsError: nil, }, { @@ -50,6 +61,7 @@ func TestStatus(t *testing.T) { expectedCode: Error, expectedMessage: "unknown error", expectedIsSuccess: false, + expectedIsWait: false, expectedAsError: errors.New("unknown error"), }, { @@ -76,6 +88,10 @@ func TestStatus(t *testing.T) { t.Errorf("expect status.IsSuccess() returns %v, but %v", test.expectedIsSuccess, test.status.IsSuccess()) } + if test.status.IsWait() != test.expectedIsWait { + t.Errorf("status.IsWait() returns %v, but want %v", test.status.IsWait(), test.expectedIsWait) + } + if test.status.AsError() == test.expectedAsError { return } diff --git a/pkg/scheduler/framework/runtime/framework.go b/pkg/scheduler/framework/runtime/framework.go index 1c4793dd28d..67578508d86 100644 --- a/pkg/scheduler/framework/runtime/framework.go +++ b/pkg/scheduler/framework/runtime/framework.go @@ -1158,7 +1158,7 @@ func (f *frameworkImpl) RunPermitPlugins(ctx context.Context, state *framework.C status.SetFailedPlugin(pl.Name()) return status } - if status.Code() == framework.Wait { + if status.IsWait() { // Not allowed to be greater than maxTimeout. if timeout > maxTimeout { timeout = maxTimeout diff --git a/pkg/scheduler/schedule_one.go b/pkg/scheduler/schedule_one.go index cdbdff3ffb0..584c31a8f76 100644 --- a/pkg/scheduler/schedule_one.go +++ b/pkg/scheduler/schedule_one.go @@ -164,7 +164,7 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) { // Run "permit" plugins. runPermitStatus := fwk.RunPermitPlugins(schedulingCycleCtx, state, assumedPod, scheduleResult.SuggestedHost) - if runPermitStatus.Code() != framework.Wait && !runPermitStatus.IsSuccess() { + if !runPermitStatus.IsWait() && !runPermitStatus.IsSuccess() { var reason string if runPermitStatus.IsUnschedulable() { metrics.PodUnschedulable(fwk.ProfileName(), metrics.SinceInSeconds(start))