mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
Merge pull request #109478 from shintard/added-status-functions
Implementation of a function that returns the wait state of the scheduler
This commit is contained in:
commit
78faab2c7b
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user