insufficient resource error: details of failure in failedPredicateMap

This commit is contained in:
Hongchao Deng
2016-01-21 21:40:13 -08:00
parent faf10632fe
commit 8e1bfad490
4 changed files with 45 additions and 25 deletions

View File

@@ -18,23 +18,32 @@ package predicates
import "fmt"
var (
ErrExceededMaxPodNumber = newInsufficientResourceError("PodCount")
ErrInsufficientFreeCPU = newInsufficientResourceError("CPU")
ErrInsufficientFreeMemory = newInsufficientResourceError("Memory")
const (
podCountResourceName string = "PodCount"
cpuResourceName string = "CPU"
memoryResoureceName string = "Memory"
)
// InsufficientResourceError is an error type that indicates what kind of resource limit is
// hit and caused the unfitting failure.
type InsufficientResourceError struct {
// ResourceName tells the name of the resource that is insufficient
ResourceName string
// resourceName is the name of the resource that is insufficient
resourceName string
requested int64
used int64
capacity int64
}
func newInsufficientResourceError(resourceName string) *InsufficientResourceError {
return &InsufficientResourceError{resourceName}
func newInsufficientResourceError(resourceName string, requested, used, capacity int64) *InsufficientResourceError {
return &InsufficientResourceError{
resourceName: resourceName,
requested: requested,
used: used,
capacity: capacity,
}
}
func (e *InsufficientResourceError) Error() string {
return fmt.Sprintf("Node didn't have enough resource: %s", e.ResourceName)
return fmt.Sprintf("Node didn't have enough resource: %s, requested: %d, used: %d, capacity: %d",
e.resourceName, e.requested, e.used, e.capacity)
}