Skip to content

Commit

Permalink
Change the error message.
Browse files Browse the repository at this point in the history
when pod is unscheduled, make the error message similar  to kube-scheduler。
  • Loading branch information
gj199575 committed Apr 12, 2023
1 parent bed4a04 commit aee5781
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/scheduler/api/resource_info.go
Expand Up @@ -389,6 +389,37 @@ func (r *Resource) LessEqual(rr *Resource, defaultValue DimensionDefaultValue) b
return true
}

// LessEqualResource returns "" only on condition that all dimensions of resources in r are less than or equal with that of rr,
// Otherwise returns err string ,which show which resource is insufficient.
// @param defaultValue "default value for resource dimension not defined in ScalarResources. Its value can only be one of 'Zero' and 'Infinity'"
func (r *Resource) LessEqualResource(rr *Resource, defaultValue DimensionDefaultValue) string {
lessEqualFunc := func(l, r, diff float64) bool {
if l < r || math.Abs(l-r) < diff {
return true
}
return false
}

if !lessEqualFunc(r.MilliCPU, rr.MilliCPU, minResource) {
return Insufficient + "cpu"
}
if !lessEqualFunc(r.Memory, rr.Memory, minResource) {
return Insufficient + "memory"
}

for resourceName, leftValue := range r.ScalarResources {
rightValue, ok := rr.ScalarResources[resourceName]
if !ok && defaultValue == Infinity {
continue
}

if !lessEqualFunc(leftValue, rightValue, minResource) {
return Insufficient + string(resourceName)
}
}
return ""
}

// LessPartly returns true if there exists any dimension whose resource amount in r is less than that in rr.
// Otherwise returns false.
// @param defaultValue "default value for resource dimension not defined in ScalarResources. Its value can only be one of 'Zero' and 'Infinity'"
Expand Down
3 changes: 3 additions & 0 deletions pkg/scheduler/api/unschedule_info.go
Expand Up @@ -14,6 +14,9 @@ const (

// AllNodeUnavailableMsg is the default error message
AllNodeUnavailableMsg = "all nodes are unavailable"

// Insufficient mean less resource than request
Insufficient = "Insufficient "
)

// These are reasons for a pod's transition to a condition.
Expand Down

0 comments on commit aee5781

Please sign in to comment.