mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
impl 'IsWait' functions
Co-authored-by: Alex Wang <453102040@qq.com>
This commit is contained in:
parent
621c4aa599
commit
22984402ab
@ -193,16 +193,21 @@ func (s *Status) IsSuccess() bool {
|
|||||||
return s.Code() == Success
|
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).
|
// IsUnschedulable returns true if "Status" is Unschedulable (Unschedulable or UnschedulableAndUnresolvable).
|
||||||
func (s *Status) IsUnschedulable() bool {
|
func (s *Status) IsUnschedulable() bool {
|
||||||
code := s.Code()
|
code := s.Code()
|
||||||
return code == Unschedulable || code == UnschedulableAndUnresolvable
|
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.
|
// with a concatenated message on reasons of the Status.
|
||||||
func (s *Status) AsError() error {
|
func (s *Status) AsError() error {
|
||||||
if s.IsSuccess() {
|
if s.IsSuccess() || s.IsWait() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if s.err != nil {
|
if s.err != nil {
|
||||||
|
@ -34,6 +34,7 @@ func TestStatus(t *testing.T) {
|
|||||||
expectedCode Code
|
expectedCode Code
|
||||||
expectedMessage string
|
expectedMessage string
|
||||||
expectedIsSuccess bool
|
expectedIsSuccess bool
|
||||||
|
expectedIsWait bool
|
||||||
expectedAsError error
|
expectedAsError error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -42,6 +43,16 @@ func TestStatus(t *testing.T) {
|
|||||||
expectedCode: Success,
|
expectedCode: Success,
|
||||||
expectedMessage: "",
|
expectedMessage: "",
|
||||||
expectedIsSuccess: true,
|
expectedIsSuccess: true,
|
||||||
|
expectedIsWait: false,
|
||||||
|
expectedAsError: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "wait status",
|
||||||
|
status: NewStatus(Wait, ""),
|
||||||
|
expectedCode: Wait,
|
||||||
|
expectedMessage: "",
|
||||||
|
expectedIsSuccess: false,
|
||||||
|
expectedIsWait: true,
|
||||||
expectedAsError: nil,
|
expectedAsError: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -50,6 +61,7 @@ func TestStatus(t *testing.T) {
|
|||||||
expectedCode: Error,
|
expectedCode: Error,
|
||||||
expectedMessage: "unknown error",
|
expectedMessage: "unknown error",
|
||||||
expectedIsSuccess: false,
|
expectedIsSuccess: false,
|
||||||
|
expectedIsWait: false,
|
||||||
expectedAsError: errors.New("unknown error"),
|
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())
|
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 {
|
if test.status.AsError() == test.expectedAsError {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1158,7 +1158,7 @@ func (f *frameworkImpl) RunPermitPlugins(ctx context.Context, state *framework.C
|
|||||||
status.SetFailedPlugin(pl.Name())
|
status.SetFailedPlugin(pl.Name())
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
if status.Code() == framework.Wait {
|
if status.IsWait() {
|
||||||
// Not allowed to be greater than maxTimeout.
|
// Not allowed to be greater than maxTimeout.
|
||||||
if timeout > maxTimeout {
|
if timeout > maxTimeout {
|
||||||
timeout = maxTimeout
|
timeout = maxTimeout
|
||||||
|
@ -164,7 +164,7 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) {
|
|||||||
|
|
||||||
// Run "permit" plugins.
|
// Run "permit" plugins.
|
||||||
runPermitStatus := fwk.RunPermitPlugins(schedulingCycleCtx, state, assumedPod, scheduleResult.SuggestedHost)
|
runPermitStatus := fwk.RunPermitPlugins(schedulingCycleCtx, state, assumedPod, scheduleResult.SuggestedHost)
|
||||||
if runPermitStatus.Code() != framework.Wait && !runPermitStatus.IsSuccess() {
|
if !runPermitStatus.IsWait() && !runPermitStatus.IsSuccess() {
|
||||||
var reason string
|
var reason string
|
||||||
if runPermitStatus.IsUnschedulable() {
|
if runPermitStatus.IsUnschedulable() {
|
||||||
metrics.PodUnschedulable(fwk.ProfileName(), metrics.SinceInSeconds(start))
|
metrics.PodUnschedulable(fwk.ProfileName(), metrics.SinceInSeconds(start))
|
||||||
|
Loading…
Reference in New Issue
Block a user