mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-10-12 18:18:51 +00:00
move predicates into library (address #12744)
DONE: 1. refactor all predicates: predicates return fitOrNot(bool) and error(Error) in which the latter is of type PredicateFailureError or InsufficientResourceError. (For violation of either MaxEBSVolumeCount or MaxGCEPDVolumeCount, returns one same error type as ErrMaxVolumeCountExceeded) 2. GeneralPredicates() is a predicate function, which includes serveral other predicate functions (PodFitsResource, PodFitsHost, PodFitsHostPort). It is registered as one of the predicates in DefaultAlgorithmProvider, and is also called in canAdmitPod() in Kubelet and should be called by other components (like rescheduler, etc) if necessary. See discussion in issue #12744 3. remove podNumber check from GeneralPredicates 4. HostName is now verified in Kubelet's canAdminPod(). add TestHostNameConflicts in kubelet_test.go 5. add getNodeAnyWay() method in Kubelet to get node information in standaloneMode TODO: 1. determine which predicates should be included in GeneralPredicates() 2. separate GeneralPredicates() into: a. GeneralPredicatesEvictPod() and b. GeneralPredicatesNotEvictPod() 3. DaemonSet should use GeneralPredicates()
This commit is contained in:
@@ -24,11 +24,27 @@ const (
|
||||
memoryResoureceName string = "Memory"
|
||||
)
|
||||
|
||||
var (
|
||||
// The predicateName tries to be consistent as the predicate name used in DefaultAlgorithmProvider defined in
|
||||
// defaults.go (which tend to be stable for backward compatibility)
|
||||
ErrDiskConflict = newPredicateFailureError("NoDiskConflict")
|
||||
ErrVolumeZoneConflict = newPredicateFailureError("NoVolumeZoneConflict")
|
||||
ErrNodeSelectorNotMatch = newPredicateFailureError("MatchNodeSelector")
|
||||
ErrPodNotMatchHostName = newPredicateFailureError("HostName")
|
||||
ErrPodNotFitsHostPorts = newPredicateFailureError("PodFitsHostPorts")
|
||||
ErrNodeLabelPresenceViolated = newPredicateFailureError("CheckNodeLabelPresence")
|
||||
ErrServiceAffinityViolated = newPredicateFailureError("CheckServiceAffinity")
|
||||
ErrMaxVolumeCountExceeded = newPredicateFailureError("MaxVolumeCount")
|
||||
// ErrFakePredicateError is used for test only. The fake predicates returning false also returns error
|
||||
// as ErrFakePredicateError.
|
||||
ErrFakePredicateError = newPredicateFailureError("false")
|
||||
)
|
||||
|
||||
// InsufficientResourceError is an error type that indicates what kind of resource limit is
|
||||
// hit and caused the unfitting failure.
|
||||
type InsufficientResourceError struct {
|
||||
// resourceName is the name of the resource that is insufficient
|
||||
resourceName string
|
||||
ResourceName string
|
||||
requested int64
|
||||
used int64
|
||||
capacity int64
|
||||
@@ -36,7 +52,7 @@ type InsufficientResourceError struct {
|
||||
|
||||
func newInsufficientResourceError(resourceName string, requested, used, capacity int64) *InsufficientResourceError {
|
||||
return &InsufficientResourceError{
|
||||
resourceName: resourceName,
|
||||
ResourceName: resourceName,
|
||||
requested: requested,
|
||||
used: used,
|
||||
capacity: capacity,
|
||||
@@ -45,5 +61,17 @@ func newInsufficientResourceError(resourceName string, requested, used, capacity
|
||||
|
||||
func (e *InsufficientResourceError) Error() string {
|
||||
return fmt.Sprintf("Node didn't have enough resource: %s, requested: %d, used: %d, capacity: %d",
|
||||
e.resourceName, e.requested, e.used, e.capacity)
|
||||
e.ResourceName, e.requested, e.used, e.capacity)
|
||||
}
|
||||
|
||||
type PredicateFailureError struct {
|
||||
PredicateName string
|
||||
}
|
||||
|
||||
func newPredicateFailureError(predicateName string) *PredicateFailureError {
|
||||
return &PredicateFailureError{predicateName}
|
||||
}
|
||||
|
||||
func (e *PredicateFailureError) Error() string {
|
||||
return fmt.Sprintf("Predicate %s failed", e.PredicateName)
|
||||
}
|
||||
|
Reference in New Issue
Block a user