From 70a2bccfd6c14a9cc1e1e83d073de640783efe2e Mon Sep 17 00:00:00 2001 From: Abdullah Gharaibeh Date: Thu, 12 Dec 2019 18:54:52 -0500 Subject: [PATCH] deprecate scheduler's FailureReason --- pkg/kubelet/lifecycle/predicate.go | 4 -- pkg/scheduler/algorithm/predicates/error.go | 66 ++++++++------------- pkg/scheduler/core/generic_scheduler.go | 2 +- 3 files changed, 27 insertions(+), 45 deletions(-) diff --git a/pkg/kubelet/lifecycle/predicate.go b/pkg/kubelet/lifecycle/predicate.go index 04eab48ffb2..f6cc98ae782 100644 --- a/pkg/kubelet/lifecycle/predicate.go +++ b/pkg/kubelet/lifecycle/predicate.go @@ -134,10 +134,6 @@ func (w *predicateAdmitHandler) Admit(attrs *PodAdmitAttributes) PodAdmitResult reason = fmt.Sprintf("OutOf%s", re.ResourceName) message = re.Error() klog.V(2).Infof("Predicate failed on Pod: %v, for reason: %v", format.Pod(admitPod), message) - case *predicates.FailureReason: - reason = re.GetReason() - message = fmt.Sprintf("Failure: %s", re.GetReason()) - klog.V(2).Infof("Predicate failed on Pod: %v, for reason: %v", format.Pod(admitPod), message) default: reason = "UnexpectedPredicateFailureType" message = fmt.Sprintf("GeneralPredicates failed due to %v, which is unexpected.", r) diff --git a/pkg/scheduler/algorithm/predicates/error.go b/pkg/scheduler/algorithm/predicates/error.go index 4784139e347..f6fd6ad7ca4 100644 --- a/pkg/scheduler/algorithm/predicates/error.go +++ b/pkg/scheduler/algorithm/predicates/error.go @@ -32,54 +32,54 @@ var ( // failure error in nodesWherePreemptionMightHelp() in scheduler/core/generic_scheduler.go // ErrDiskConflict is used for NoDiskConflict predicate error. - ErrDiskConflict = newPredicateFailureError("NoDiskConflict", "node(s) had no available disk") + ErrDiskConflict = NewPredicateFailureError("NoDiskConflict", "node(s) had no available disk") // ErrVolumeZoneConflict is used for NoVolumeZoneConflict predicate error. - ErrVolumeZoneConflict = newPredicateFailureError("NoVolumeZoneConflict", "node(s) had no available volume zone") + ErrVolumeZoneConflict = NewPredicateFailureError("NoVolumeZoneConflict", "node(s) had no available volume zone") // ErrNodeSelectorNotMatch is used for MatchNodeSelector predicate error. - ErrNodeSelectorNotMatch = newPredicateFailureError("MatchNodeSelector", "node(s) didn't match node selector") + ErrNodeSelectorNotMatch = NewPredicateFailureError("MatchNodeSelector", "node(s) didn't match node selector") // ErrPodAffinityNotMatch is used for MatchInterPodAffinity predicate error. - ErrPodAffinityNotMatch = newPredicateFailureError("MatchInterPodAffinity", "node(s) didn't match pod affinity/anti-affinity") + ErrPodAffinityNotMatch = NewPredicateFailureError("MatchInterPodAffinity", "node(s) didn't match pod affinity/anti-affinity") // ErrPodAffinityRulesNotMatch is used for PodAffinityRulesNotMatch predicate error. - ErrPodAffinityRulesNotMatch = newPredicateFailureError("PodAffinityRulesNotMatch", "node(s) didn't match pod affinity rules") + ErrPodAffinityRulesNotMatch = NewPredicateFailureError("PodAffinityRulesNotMatch", "node(s) didn't match pod affinity rules") // ErrPodAntiAffinityRulesNotMatch is used for PodAntiAffinityRulesNotMatch predicate error. - ErrPodAntiAffinityRulesNotMatch = newPredicateFailureError("PodAntiAffinityRulesNotMatch", "node(s) didn't match pod anti-affinity rules") + ErrPodAntiAffinityRulesNotMatch = NewPredicateFailureError("PodAntiAffinityRulesNotMatch", "node(s) didn't match pod anti-affinity rules") // ErrExistingPodsAntiAffinityRulesNotMatch is used for ExistingPodsAntiAffinityRulesNotMatch predicate error. - ErrExistingPodsAntiAffinityRulesNotMatch = newPredicateFailureError("ExistingPodsAntiAffinityRulesNotMatch", "node(s) didn't satisfy existing pods anti-affinity rules") + ErrExistingPodsAntiAffinityRulesNotMatch = NewPredicateFailureError("ExistingPodsAntiAffinityRulesNotMatch", "node(s) didn't satisfy existing pods anti-affinity rules") // ErrTaintsTolerationsNotMatch is used for PodToleratesNodeTaints predicate error. - ErrTaintsTolerationsNotMatch = newPredicateFailureError("PodToleratesNodeTaints", "node(s) had taints that the pod didn't tolerate") + ErrTaintsTolerationsNotMatch = NewPredicateFailureError("PodToleratesNodeTaints", "node(s) had taints that the pod didn't tolerate") // ErrPodNotMatchHostName is used for HostName predicate error. - ErrPodNotMatchHostName = newPredicateFailureError("HostName", "node(s) didn't match the requested hostname") + ErrPodNotMatchHostName = NewPredicateFailureError("HostName", "node(s) didn't match the requested hostname") // ErrPodNotFitsHostPorts is used for PodFitsHostPorts predicate error. - ErrPodNotFitsHostPorts = newPredicateFailureError("PodFitsHostPorts", "node(s) didn't have free ports for the requested pod ports") + ErrPodNotFitsHostPorts = NewPredicateFailureError("PodFitsHostPorts", "node(s) didn't have free ports for the requested pod ports") // ErrNodeLabelPresenceViolated is used for CheckNodeLabelPresence predicate error. - ErrNodeLabelPresenceViolated = newPredicateFailureError("CheckNodeLabelPresence", "node(s) didn't have the requested labels") + ErrNodeLabelPresenceViolated = NewPredicateFailureError("CheckNodeLabelPresence", "node(s) didn't have the requested labels") // ErrServiceAffinityViolated is used for CheckServiceAffinity predicate error. - ErrServiceAffinityViolated = newPredicateFailureError("CheckServiceAffinity", "node(s) didn't match service affinity") + ErrServiceAffinityViolated = NewPredicateFailureError("CheckServiceAffinity", "node(s) didn't match service affinity") // ErrMaxVolumeCountExceeded is used for MaxVolumeCount predicate error. - ErrMaxVolumeCountExceeded = newPredicateFailureError("MaxVolumeCount", "node(s) exceed max volume count") + ErrMaxVolumeCountExceeded = NewPredicateFailureError("MaxVolumeCount", "node(s) exceed max volume count") // ErrNodeUnderMemoryPressure is used for NodeUnderMemoryPressure predicate error. - ErrNodeUnderMemoryPressure = newPredicateFailureError("NodeUnderMemoryPressure", "node(s) had memory pressure") + ErrNodeUnderMemoryPressure = NewPredicateFailureError("NodeUnderMemoryPressure", "node(s) had memory pressure") // ErrNodeUnderDiskPressure is used for NodeUnderDiskPressure predicate error. - ErrNodeUnderDiskPressure = newPredicateFailureError("NodeUnderDiskPressure", "node(s) had disk pressure") + ErrNodeUnderDiskPressure = NewPredicateFailureError("NodeUnderDiskPressure", "node(s) had disk pressure") // ErrNodeUnderPIDPressure is used for NodeUnderPIDPressure predicate error. - ErrNodeUnderPIDPressure = newPredicateFailureError("NodeUnderPIDPressure", "node(s) had pid pressure") + ErrNodeUnderPIDPressure = NewPredicateFailureError("NodeUnderPIDPressure", "node(s) had pid pressure") // ErrNodeNotReady is used for NodeNotReady predicate error. - ErrNodeNotReady = newPredicateFailureError("NodeNotReady", "node(s) were not ready") + ErrNodeNotReady = NewPredicateFailureError("NodeNotReady", "node(s) were not ready") // ErrNodeNetworkUnavailable is used for NodeNetworkUnavailable predicate error. - ErrNodeNetworkUnavailable = newPredicateFailureError("NodeNetworkUnavailable", "node(s) had unavailable network") + ErrNodeNetworkUnavailable = NewPredicateFailureError("NodeNetworkUnavailable", "node(s) had unavailable network") // ErrNodeUnschedulable is used for NodeUnschedulable predicate error. - ErrNodeUnschedulable = newPredicateFailureError("NodeUnschedulable", "node(s) were unschedulable") + ErrNodeUnschedulable = NewPredicateFailureError("NodeUnschedulable", "node(s) were unschedulable") // ErrNodeUnknownCondition is used for NodeUnknownCondition predicate error. - ErrNodeUnknownCondition = newPredicateFailureError("NodeUnknownCondition", "node(s) had unknown conditions") + ErrNodeUnknownCondition = NewPredicateFailureError("NodeUnknownCondition", "node(s) had unknown conditions") // ErrVolumeNodeConflict is used for VolumeNodeAffinityConflict predicate error. - ErrVolumeNodeConflict = newPredicateFailureError("VolumeNodeAffinityConflict", "node(s) had volume node affinity conflict") + ErrVolumeNodeConflict = NewPredicateFailureError("VolumeNodeAffinityConflict", "node(s) had volume node affinity conflict") // ErrVolumeBindConflict is used for VolumeBindingNoMatch predicate error. - ErrVolumeBindConflict = newPredicateFailureError("VolumeBindingNoMatch", "node(s) didn't find available persistent volumes to bind") + ErrVolumeBindConflict = NewPredicateFailureError("VolumeBindingNoMatch", "node(s) didn't find available persistent volumes to bind") // ErrTopologySpreadConstraintsNotMatch is used for EvenPodsSpread predicate error. - ErrTopologySpreadConstraintsNotMatch = newPredicateFailureError("EvenPodsSpreadNotMatch", "node(s) didn't match pod topology spread constraints") + ErrTopologySpreadConstraintsNotMatch = NewPredicateFailureError("EvenPodsSpreadNotMatch", "node(s) didn't match pod topology spread constraints") // ErrFakePredicate is used for test only. The fake predicates returning false also returns error // as ErrFakePredicate. - ErrFakePredicate = newPredicateFailureError("FakePredicateError", "Nodes failed the fake predicate") + ErrFakePredicate = NewPredicateFailureError("FakePredicateError", "Nodes failed the fake predicate") ) var unresolvablePredicateFailureErrors = map[PredicateFailureReason]struct{}{ @@ -154,7 +154,8 @@ type PredicateFailureError struct { PredicateDesc string } -func newPredicateFailureError(predicateName, predicateDesc string) *PredicateFailureError { +// NewPredicateFailureError creates a PredicateFailureError with message. +func NewPredicateFailureError(predicateName, predicateDesc string) *PredicateFailureError { return &PredicateFailureError{PredicateName: predicateName, PredicateDesc: predicateDesc} } @@ -171,18 +172,3 @@ func (e *PredicateFailureError) GetReason() string { type PredicateFailureReason interface { GetReason() string } - -// FailureReason describes a failure reason. -type FailureReason struct { - reason string -} - -// NewFailureReason creates a FailureReason with message. -func NewFailureReason(msg string) *FailureReason { - return &FailureReason{reason: msg} -} - -// GetReason returns the reason of the FailureReason. -func (e *FailureReason) GetReason() string { - return e.reason -} diff --git a/pkg/scheduler/core/generic_scheduler.go b/pkg/scheduler/core/generic_scheduler.go index 89b438808f4..0bbdaba73b1 100644 --- a/pkg/scheduler/core/generic_scheduler.go +++ b/pkg/scheduler/core/generic_scheduler.go @@ -570,7 +570,7 @@ func (g *genericScheduler) findNodesThatFit(ctx context.Context, state *framewor if _, found := failedPredicateMap[failedNodeName]; !found { failedPredicateMap[failedNodeName] = []predicates.PredicateFailureReason{} } - failedPredicateMap[failedNodeName] = append(failedPredicateMap[failedNodeName], predicates.NewFailureReason(failedMsg)) + failedPredicateMap[failedNodeName] = append(failedPredicateMap[failedNodeName], predicates.NewPredicateFailureError(extender.Name(), failedMsg)) } filtered = filteredList if len(filtered) == 0 {