Merge pull request #86836 from haosdent/clean-filter-deps-interpodaffinity

Break interpodaffinity Filter plugins dependency on predicates package
This commit is contained in:
Kubernetes Prow Robot 2020-01-08 19:11:53 -08:00 committed by GitHub
commit 4d95d40a41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 121 additions and 112 deletions

View File

@ -33,14 +33,6 @@ var (
// ErrNodeSelectorNotMatch is used for MatchNodeSelector predicate error. // 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")
// ErrPodAffinityRulesNotMatch is used for PodAffinityRulesNotMatch predicate error.
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")
// ErrExistingPodsAntiAffinityRulesNotMatch is used for ExistingPodsAntiAffinityRulesNotMatch predicate error.
ErrExistingPodsAntiAffinityRulesNotMatch = NewPredicateFailureError("ExistingPodsAntiAffinityRulesNotMatch", "node(s) didn't satisfy existing pods anti-affinity rules")
// ErrTaintsTolerationsNotMatch is used for PodToleratesNodeTaints predicate error. // 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 is used for HostName predicate error.
@ -72,7 +64,6 @@ var (
var unresolvablePredicateFailureErrors = map[PredicateFailureReason]struct{}{ var unresolvablePredicateFailureErrors = map[PredicateFailureReason]struct{}{
ErrNodeSelectorNotMatch: {}, ErrNodeSelectorNotMatch: {},
ErrPodAffinityRulesNotMatch: {},
ErrPodNotMatchHostName: {}, ErrPodNotMatchHostName: {},
ErrTaintsTolerationsNotMatch: {}, ErrTaintsTolerationsNotMatch: {},
// Node conditions won't change when scheduler simulates removal of preemption victims. // Node conditions won't change when scheduler simulates removal of preemption victims.

View File

@ -1875,9 +1875,9 @@ func TestNodesWherePreemptionMightHelp(t *testing.T) {
expected: map[string]bool{}, expected: map[string]bool{},
}, },
{ {
name: "ErrPodAffinityNotMatch should be tried as it indicates that the pod is unschedulable due to inter-pod affinity or anti-affinity", name: "ErrReasonAffinityNotMatch should be tried as it indicates that the pod is unschedulable due to inter-pod affinity or anti-affinity",
nodesStatuses: framework.NodeToStatusMap{ nodesStatuses: framework.NodeToStatusMap{
"machine1": framework.NewStatus(framework.Unschedulable, algorithmpredicates.ErrPodAffinityNotMatch.GetReason()), "machine1": framework.NewStatus(framework.Unschedulable, interpodaffinity.ErrReasonAffinityNotMatch),
"machine2": framework.NewStatus(framework.UnschedulableAndUnresolvable, algorithmpredicates.ErrPodNotMatchHostName.GetReason()), "machine2": framework.NewStatus(framework.UnschedulableAndUnresolvable, algorithmpredicates.ErrPodNotMatchHostName.GetReason()),
"machine3": framework.NewStatus(framework.UnschedulableAndUnresolvable, algorithmpredicates.ErrNodeUnschedulable.GetReason()), "machine3": framework.NewStatus(framework.UnschedulableAndUnresolvable, algorithmpredicates.ErrNodeUnschedulable.GetReason()),
}, },
@ -1886,16 +1886,16 @@ func TestNodesWherePreemptionMightHelp(t *testing.T) {
{ {
name: "pod with both pod affinity and anti-affinity should be tried", name: "pod with both pod affinity and anti-affinity should be tried",
nodesStatuses: framework.NodeToStatusMap{ nodesStatuses: framework.NodeToStatusMap{
"machine1": framework.NewStatus(framework.Unschedulable, algorithmpredicates.ErrPodAffinityNotMatch.GetReason()), "machine1": framework.NewStatus(framework.Unschedulable, interpodaffinity.ErrReasonAffinityNotMatch),
"machine2": framework.NewStatus(framework.UnschedulableAndUnresolvable, algorithmpredicates.ErrPodNotMatchHostName.GetReason()), "machine2": framework.NewStatus(framework.UnschedulableAndUnresolvable, algorithmpredicates.ErrPodNotMatchHostName.GetReason()),
}, },
expected: map[string]bool{"machine1": true, "machine3": true, "machine4": true}, expected: map[string]bool{"machine1": true, "machine3": true, "machine4": true},
}, },
{ {
name: "ErrPodAffinityRulesNotMatch should not be tried as it indicates that the pod is unschedulable due to inter-pod affinity, but ErrPodAffinityNotMatch should be tried as it indicates that the pod is unschedulable due to inter-pod affinity or anti-affinity", name: "ErrReasonAffinityRulesNotMatch should not be tried as it indicates that the pod is unschedulable due to inter-pod affinity, but ErrReasonAffinityNotMatch should be tried as it indicates that the pod is unschedulable due to inter-pod affinity or anti-affinity",
nodesStatuses: framework.NodeToStatusMap{ nodesStatuses: framework.NodeToStatusMap{
"machine1": framework.NewStatus(framework.UnschedulableAndUnresolvable, algorithmpredicates.ErrPodAffinityRulesNotMatch.GetReason()), "machine1": framework.NewStatus(framework.UnschedulableAndUnresolvable, interpodaffinity.ErrReasonAffinityRulesNotMatch),
"machine2": framework.NewStatus(framework.Unschedulable, algorithmpredicates.ErrPodAffinityNotMatch.GetReason()), "machine2": framework.NewStatus(framework.Unschedulable, interpodaffinity.ErrReasonAffinityNotMatch),
}, },
expected: map[string]bool{"machine2": true, "machine3": true, "machine4": true}, expected: map[string]bool{"machine2": true, "machine3": true, "machine4": true},
}, },

View File

@ -10,9 +10,7 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity", importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
deps = [ deps = [
"//pkg/scheduler/algorithm/predicates:go_default_library",
"//pkg/scheduler/algorithm/priorities/util:go_default_library", "//pkg/scheduler/algorithm/priorities/util:go_default_library",
"//pkg/scheduler/framework/plugins/migration:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/listers:go_default_library", "//pkg/scheduler/listers:go_default_library",
"//pkg/scheduler/nodeinfo:go_default_library", "//pkg/scheduler/nodeinfo:go_default_library",
@ -35,7 +33,6 @@ go_test(
], ],
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ deps = [
"//pkg/scheduler/algorithm/predicates:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/nodeinfo/snapshot:go_default_library", "//pkg/scheduler/nodeinfo/snapshot:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library",

View File

@ -27,17 +27,26 @@ import (
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/util/workqueue" "k8s.io/client-go/util/workqueue"
"k8s.io/klog" "k8s.io/klog"
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
priorityutil "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities/util" priorityutil "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities/util"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/migration"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/nodeinfo" "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
schedutil "k8s.io/kubernetes/pkg/scheduler/util" schedutil "k8s.io/kubernetes/pkg/scheduler/util"
) )
// preFilterStateKey is the key in CycleState to InterPodAffinity pre-computed data for Filtering. const (
// Using the name of the plugin will likely help us avoid collisions with other plugins. // preFilterStateKey is the key in CycleState to InterPodAffinity pre-computed data for Filtering.
const preFilterStateKey = "PreFilter" + Name // Using the name of the plugin will likely help us avoid collisions with other plugins.
preFilterStateKey = "PreFilter" + Name
// ErrReasonExistingAntiAffinityRulesNotMatch is used for ExistingPodsAntiAffinityRulesNotMatch predicate error.
ErrReasonExistingAntiAffinityRulesNotMatch = "node(s) didn't satisfy existing pods anti-affinity rules"
// ErrReasonAffinityNotMatch is used for MatchInterPodAffinity predicate error.
ErrReasonAffinityNotMatch = "node(s) didn't match pod affinity/anti-affinity"
// ErrReasonAffinityRulesNotMatch is used for PodAffinityRulesNotMatch predicate error.
ErrReasonAffinityRulesNotMatch = "node(s) didn't match pod affinity rules"
// ErrReasonAntiAffinityRulesNotMatch is used for PodAntiAffinityRulesNotMatch predicate error.
ErrReasonAntiAffinityRulesNotMatch = "node(s) didn't match pod anti-affinity rules"
)
// preFilterState computed at PreFilter and used at Filter. // preFilterState computed at PreFilter and used at Filter.
type preFilterState struct { type preFilterState struct {
@ -530,12 +539,14 @@ func (pl *InterPodAffinity) getMatchingAntiAffinityTopologyPairsOfPods(pod *v1.P
} }
// satisfiesPodsAffinityAntiAffinity checks if scheduling the pod onto this node would break any term of this pod. // satisfiesPodsAffinityAntiAffinity checks if scheduling the pod onto this node would break any term of this pod.
// This function returns two boolean flags. The first boolean flag indicates whether the pod matches affinity rules
// or not. The second boolean flag indicates if the pod matches anti-affinity rules.
func (pl *InterPodAffinity) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod, func (pl *InterPodAffinity) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod,
state *preFilterState, nodeInfo *nodeinfo.NodeInfo, state *preFilterState, nodeInfo *nodeinfo.NodeInfo,
affinity *v1.Affinity) (predicates.PredicateFailureReason, error) { affinity *v1.Affinity) (bool, bool, error) {
node := nodeInfo.Node() node := nodeInfo.Node()
if node == nil { if node == nil {
return predicates.ErrPodAffinityRulesNotMatch, fmt.Errorf("node not found") return false, false, fmt.Errorf("node not found")
} }
if state != nil { if state != nil {
// Check all affinity terms. // Check all affinity terms.
@ -548,7 +559,7 @@ func (pl *InterPodAffinity) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod,
// in the cluster matches the namespace and selector of this pod and the pod matches // in the cluster matches the namespace and selector of this pod and the pod matches
// its own terms, then we allow the pod to pass the affinity check. // its own terms, then we allow the pod to pass the affinity check.
if len(topologyToMatchedAffinityTerms) != 0 || !targetPodMatchesAffinityOfPod(pod, pod) { if len(topologyToMatchedAffinityTerms) != 0 || !targetPodMatchesAffinityOfPod(pod, pod) {
return predicates.ErrPodAffinityRulesNotMatch, nil return false, false, nil
} }
} }
} }
@ -558,13 +569,13 @@ func (pl *InterPodAffinity) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod,
if antiAffinityTerms := schedutil.GetPodAntiAffinityTerms(affinity.PodAntiAffinity); len(antiAffinityTerms) > 0 { if antiAffinityTerms := schedutil.GetPodAntiAffinityTerms(affinity.PodAntiAffinity); len(antiAffinityTerms) > 0 {
matchExists := nodeMatchesAnyTopologyTerm(pod, topologyToMatchedAntiAffinityTerms, nodeInfo, antiAffinityTerms) matchExists := nodeMatchesAnyTopologyTerm(pod, topologyToMatchedAntiAffinityTerms, nodeInfo, antiAffinityTerms)
if matchExists { if matchExists {
return predicates.ErrPodAntiAffinityRulesNotMatch, nil return true, false, nil
} }
} }
} else { // We don't have precomputed preFilterState. We have to follow a slow path to check affinity terms. } else { // We don't have precomputed preFilterState. We have to follow a slow path to check affinity terms.
filteredPods, err := pl.sharedLister.Pods().FilteredList(nodeInfo.Filter, labels.Everything()) filteredPods, err := pl.sharedLister.Pods().FilteredList(nodeInfo.Filter, labels.Everything())
if err != nil { if err != nil {
return predicates.ErrPodAffinityRulesNotMatch, err return false, false, err
} }
affinityTerms := schedutil.GetPodAffinityTerms(affinity.PodAffinity) affinityTerms := schedutil.GetPodAffinityTerms(affinity.PodAffinity)
@ -575,7 +586,7 @@ func (pl *InterPodAffinity) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod,
if !matchFound && len(affinityTerms) > 0 { if !matchFound && len(affinityTerms) > 0 {
affTermsMatch, termsSelectorMatch, err := pl.podMatchesPodAffinityTerms(pod, targetPod, nodeInfo, affinityTerms) affTermsMatch, termsSelectorMatch, err := pl.podMatchesPodAffinityTerms(pod, targetPod, nodeInfo, affinityTerms)
if err != nil { if err != nil {
return predicates.ErrPodAffinityRulesNotMatch, err return false, false, err
} }
if termsSelectorMatch { if termsSelectorMatch {
termsSelectorMatchFound = true termsSelectorMatchFound = true
@ -589,7 +600,7 @@ func (pl *InterPodAffinity) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod,
if len(antiAffinityTerms) > 0 { if len(antiAffinityTerms) > 0 {
antiAffTermsMatch, _, err := pl.podMatchesPodAffinityTerms(pod, targetPod, nodeInfo, antiAffinityTerms) antiAffTermsMatch, _, err := pl.podMatchesPodAffinityTerms(pod, targetPod, nodeInfo, antiAffinityTerms)
if err != nil || antiAffTermsMatch { if err != nil || antiAffTermsMatch {
return predicates.ErrPodAntiAffinityRulesNotMatch, err return true, false, err
} }
} }
} }
@ -601,16 +612,16 @@ func (pl *InterPodAffinity) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod,
// in the cluster matches the namespace and selector of this pod and the pod matches // in the cluster matches the namespace and selector of this pod and the pod matches
// its own terms, then we allow the pod to pass the affinity check. // its own terms, then we allow the pod to pass the affinity check.
if termsSelectorMatchFound { if termsSelectorMatchFound {
return predicates.ErrPodAffinityRulesNotMatch, nil return false, false, nil
} }
// Check if pod matches its own affinity terms (namespace and label selector). // Check if pod matches its own affinity terms (namespace and label selector).
if !targetPodMatchesAffinityOfPod(pod, pod) { if !targetPodMatchesAffinityOfPod(pod, pod) {
return predicates.ErrPodAffinityRulesNotMatch, nil return false, false, nil
} }
} }
} }
return nil, nil return true, true, nil
} }
// Filter invoked at the filter extension point. // Filter invoked at the filter extension point.
@ -622,7 +633,10 @@ func (pl *InterPodAffinity) Filter(ctx context.Context, cycleState *framework.Cy
} }
if s, err := pl.satisfiesExistingPodsAntiAffinity(pod, state, nodeInfo); !s || err != nil { if s, err := pl.satisfiesExistingPodsAntiAffinity(pod, state, nodeInfo); !s || err != nil {
return migration.PredicateResultToFrameworkStatus([]predicates.PredicateFailureReason{predicates.ErrPodAffinityNotMatch, predicates.ErrExistingPodsAntiAffinityRulesNotMatch}, err) if err != nil {
return framework.NewStatus(framework.Error, err.Error())
}
return framework.NewStatus(framework.Unschedulable, ErrReasonAffinityNotMatch, ErrReasonExistingAntiAffinityRulesNotMatch)
} }
// Now check if <pod> requirements will be satisfied on this node. // Now check if <pod> requirements will be satisfied on this node.
@ -630,8 +644,16 @@ func (pl *InterPodAffinity) Filter(ctx context.Context, cycleState *framework.Cy
if affinity == nil || (affinity.PodAffinity == nil && affinity.PodAntiAffinity == nil) { if affinity == nil || (affinity.PodAffinity == nil && affinity.PodAntiAffinity == nil) {
return nil return nil
} }
if status, err := pl.satisfiesPodsAffinityAntiAffinity(pod, state, nodeInfo, affinity); err != nil || status != nil { if satisfiesAffinity, satisfiesAntiAffinity, err := pl.satisfiesPodsAffinityAntiAffinity(pod, state, nodeInfo, affinity); err != nil || !satisfiesAffinity || !satisfiesAntiAffinity {
return migration.PredicateResultToFrameworkStatus([]predicates.PredicateFailureReason{predicates.ErrPodAffinityNotMatch, status}, err) if err != nil {
return framework.NewStatus(framework.Error, err.Error())
}
if !satisfiesAffinity {
return framework.NewStatus(framework.UnschedulableAndUnresolvable, ErrReasonAffinityNotMatch, ErrReasonAffinityRulesNotMatch)
}
return framework.NewStatus(framework.Unschedulable, ErrReasonAffinityNotMatch, ErrReasonAntiAffinityRulesNotMatch)
} }
return nil return nil

View File

@ -23,7 +23,6 @@ import (
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
nodeinfosnapshot "k8s.io/kubernetes/pkg/scheduler/nodeinfo/snapshot" nodeinfosnapshot "k8s.io/kubernetes/pkg/scheduler/nodeinfo/snapshot"
) )
@ -134,8 +133,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
name: "Does not satisfy the PodAffinity with labelSelector because of diff Namespace", name: "Does not satisfy the PodAffinity with labelSelector because of diff Namespace",
wantStatus: framework.NewStatus( wantStatus: framework.NewStatus(
framework.UnschedulableAndUnresolvable, framework.UnschedulableAndUnresolvable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAffinityRulesNotMatch.GetReason(), ErrReasonAffinityRulesNotMatch,
), ),
}, },
{ {
@ -158,8 +157,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
name: "Doesn't satisfy the PodAffinity because of unmatching labelSelector with the existing pod", name: "Doesn't satisfy the PodAffinity because of unmatching labelSelector with the existing pod",
wantStatus: framework.NewStatus( wantStatus: framework.NewStatus(
framework.UnschedulableAndUnresolvable, framework.UnschedulableAndUnresolvable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAffinityRulesNotMatch.GetReason(), ErrReasonAffinityRulesNotMatch,
), ),
}, },
{ {
@ -237,8 +236,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
name: "The labelSelector requirements(items of matchExpressions) are ANDed, the pod cannot schedule onto the node because one of the matchExpression item don't match.", name: "The labelSelector requirements(items of matchExpressions) are ANDed, the pod cannot schedule onto the node because one of the matchExpression item don't match.",
wantStatus: framework.NewStatus( wantStatus: framework.NewStatus(
framework.UnschedulableAndUnresolvable, framework.UnschedulableAndUnresolvable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAffinityRulesNotMatch.GetReason(), ErrReasonAffinityRulesNotMatch,
), ),
}, },
{ {
@ -360,8 +359,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
name: "satisfies the PodAffinity but doesn't satisfy the PodAntiAffinity with the existing pod", name: "satisfies the PodAffinity but doesn't satisfy the PodAntiAffinity with the existing pod",
wantStatus: framework.NewStatus( wantStatus: framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
}, },
{ {
@ -415,8 +414,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
name: "satisfies the PodAffinity and PodAntiAffinity but doesn't satisfy PodAntiAffinity symmetry with the existing pod", name: "satisfies the PodAffinity and PodAntiAffinity but doesn't satisfy PodAntiAffinity symmetry with the existing pod",
wantStatus: framework.NewStatus( wantStatus: framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(), ErrReasonExistingAntiAffinityRulesNotMatch,
), ),
}, },
{ {
@ -440,8 +439,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
name: "pod matches its own Label in PodAffinity and that matches the existing pod Labels", name: "pod matches its own Label in PodAffinity and that matches the existing pod Labels",
wantStatus: framework.NewStatus( wantStatus: framework.NewStatus(
framework.UnschedulableAndUnresolvable, framework.UnschedulableAndUnresolvable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAffinityRulesNotMatch.GetReason(), ErrReasonAffinityRulesNotMatch,
), ),
}, },
{ {
@ -471,8 +470,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
name: "verify that PodAntiAffinity from existing pod is respected when pod has no AntiAffinity constraints. doesn't satisfy PodAntiAffinity symmetry with the existing pod", name: "verify that PodAntiAffinity from existing pod is respected when pod has no AntiAffinity constraints. doesn't satisfy PodAntiAffinity symmetry with the existing pod",
wantStatus: framework.NewStatus( wantStatus: framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(), ErrReasonExistingAntiAffinityRulesNotMatch,
), ),
}, },
{ {
@ -547,8 +546,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
name: "satisfies the PodAntiAffinity with existing pod but doesn't satisfy PodAntiAffinity symmetry with incoming pod", name: "satisfies the PodAntiAffinity with existing pod but doesn't satisfy PodAntiAffinity symmetry with incoming pod",
wantStatus: framework.NewStatus( wantStatus: framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
}, },
{ {
@ -596,8 +595,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
node: &node1, node: &node1,
wantStatus: framework.NewStatus( wantStatus: framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
name: "PodAntiAffinity symmetry check a1: incoming pod and existing pod partially match each other on AffinityTerms", name: "PodAntiAffinity symmetry check a1: incoming pod and existing pod partially match each other on AffinityTerms",
}, },
@ -646,8 +645,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
node: &node1, node: &node1,
wantStatus: framework.NewStatus( wantStatus: framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(), ErrReasonExistingAntiAffinityRulesNotMatch,
), ),
name: "PodAntiAffinity symmetry check a2: incoming pod and existing pod partially match each other on AffinityTerms", name: "PodAntiAffinity symmetry check a2: incoming pod and existing pod partially match each other on AffinityTerms",
}, },
@ -707,8 +706,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
node: &node1, node: &node1,
wantStatus: framework.NewStatus( wantStatus: framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(), ErrReasonExistingAntiAffinityRulesNotMatch,
), ),
name: "PodAntiAffinity symmetry check b1: incoming pod and existing pod partially match each other on AffinityTerms", name: "PodAntiAffinity symmetry check b1: incoming pod and existing pod partially match each other on AffinityTerms",
}, },
@ -768,8 +767,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
node: &node1, node: &node1,
wantStatus: framework.NewStatus( wantStatus: framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(), ErrReasonExistingAntiAffinityRulesNotMatch,
), ),
name: "PodAntiAffinity symmetry check b2: incoming pod and existing pod partially match each other on AffinityTerms", name: "PodAntiAffinity symmetry check b2: incoming pod and existing pod partially match each other on AffinityTerms",
}, },
@ -845,8 +844,8 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
nil, nil,
framework.NewStatus( framework.NewStatus(
framework.UnschedulableAndUnresolvable, framework.UnschedulableAndUnresolvable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAffinityRulesNotMatch.GetReason(), ErrReasonAffinityRulesNotMatch,
), ),
}, },
name: "A pod can be scheduled onto all the nodes that have the same topology key & label value with one of them has an existing pod that matches the affinity rules", name: "A pod can be scheduled onto all the nodes that have the same topology key & label value with one of them has an existing pod that matches the affinity rules",
@ -914,13 +913,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
wantStatuses: []*framework.Status{ wantStatuses: []*framework.Status{
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
}, },
name: "NodeA and nodeB have same topologyKey and label value. NodeA has an existing pod that matches the inter pod affinity rule. The pod can not be scheduled onto nodeA and nodeB.", name: "NodeA and nodeB have same topologyKey and label value. NodeA has an existing pod that matches the inter pod affinity rule. The pod can not be scheduled onto nodeA and nodeB.",
@ -963,13 +962,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
wantStatuses: []*framework.Status{ wantStatuses: []*framework.Status{
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
}, },
name: "This test ensures that anti-affinity matches a pod when any term of the anti-affinity rule matches a pod.", name: "This test ensures that anti-affinity matches a pod when any term of the anti-affinity rule matches a pod.",
@ -1001,13 +1000,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
wantStatuses: []*framework.Status{ wantStatuses: []*framework.Status{
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
nil, nil,
}, },
@ -1061,13 +1060,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
wantStatuses: []*framework.Status{ wantStatuses: []*framework.Status{
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
nil, nil,
}, },
@ -1171,13 +1170,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
wantStatuses: []*framework.Status{ wantStatuses: []*framework.Status{
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(), ErrReasonExistingAntiAffinityRulesNotMatch,
), ),
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(), ErrReasonExistingAntiAffinityRulesNotMatch,
), ),
}, },
name: "Test existing pod's anti-affinity: incoming pod wouldn't considered as a fit as it violates each existingPod's terms on all nodes", name: "Test existing pod's anti-affinity: incoming pod wouldn't considered as a fit as it violates each existingPod's terms on all nodes",
@ -1229,13 +1228,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
wantStatuses: []*framework.Status{ wantStatuses: []*framework.Status{
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
}, },
name: "Test incoming pod's anti-affinity: incoming pod wouldn't considered as a fit as it at least violates one anti-affinity rule of existingPod", name: "Test incoming pod's anti-affinity: incoming pod wouldn't considered as a fit as it at least violates one anti-affinity rule of existingPod",
@ -1278,8 +1277,8 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
wantStatuses: []*framework.Status{ wantStatuses: []*framework.Status{
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(), ErrReasonExistingAntiAffinityRulesNotMatch,
), ),
nil, nil,
}, },
@ -1326,8 +1325,8 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
wantStatuses: []*framework.Status{ wantStatuses: []*framework.Status{
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
nil, nil,
}, },
@ -1371,13 +1370,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
wantStatuses: []*framework.Status{ wantStatuses: []*framework.Status{
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(), ErrReasonExistingAntiAffinityRulesNotMatch,
), ),
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(), ErrReasonExistingAntiAffinityRulesNotMatch,
), ),
}, },
name: "Test existing pod's anti-affinity: only when labelSelector and topologyKey both match, it's counted as a single term match - case when all terms have valid topologyKey", name: "Test existing pod's anti-affinity: only when labelSelector and topologyKey both match, it's counted as a single term match - case when all terms have valid topologyKey",
@ -1423,13 +1422,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
wantStatuses: []*framework.Status{ wantStatuses: []*framework.Status{
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(), ErrReasonAntiAffinityRulesNotMatch,
), ),
}, },
name: "Test incoming pod's anti-affinity: only when labelSelector and topologyKey both match, it's counted as a single term match - case when all terms have valid topologyKey", name: "Test incoming pod's anti-affinity: only when labelSelector and topologyKey both match, it's counted as a single term match - case when all terms have valid topologyKey",
@ -1498,13 +1497,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
wantStatuses: []*framework.Status{ wantStatuses: []*framework.Status{
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(), ErrReasonExistingAntiAffinityRulesNotMatch,
), ),
framework.NewStatus( framework.NewStatus(
framework.Unschedulable, framework.Unschedulable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(), ErrReasonExistingAntiAffinityRulesNotMatch,
), ),
nil, nil,
}, },
@ -1598,13 +1597,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
wantStatuses: []*framework.Status{ wantStatuses: []*framework.Status{
framework.NewStatus( framework.NewStatus(
framework.UnschedulableAndUnresolvable, framework.UnschedulableAndUnresolvable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAffinityRulesNotMatch.GetReason(), ErrReasonAffinityRulesNotMatch,
), ),
framework.NewStatus( framework.NewStatus(
framework.UnschedulableAndUnresolvable, framework.UnschedulableAndUnresolvable,
predicates.ErrPodAffinityNotMatch.GetReason(), ErrReasonAffinityNotMatch,
predicates.ErrPodAffinityRulesNotMatch.GetReason(), ErrReasonAffinityRulesNotMatch,
), ),
}, },
name: "Test incoming pod's affinity: firstly check if all affinityTerms match, and then check if all topologyKeys match, and the match logic should be satisfied on the same pod", name: "Test incoming pod's affinity: firstly check if all affinityTerms match, and then check if all topologyKeys match, and the match logic should be satisfied on the same pod",

View File

@ -43,18 +43,18 @@ func TestPredicateResultToFrameworkStatus(t *testing.T) {
{ {
name: "Error with reason", name: "Error with reason",
err: errors.New("Failed with error"), err: errors.New("Failed with error"),
reasons: []predicates.PredicateFailureReason{predicates.ErrTaintsTolerationsNotMatch}, reasons: []predicates.PredicateFailureReason{predicates.ErrPodNotFitsHostPorts},
wantStatus: framework.NewStatus(framework.Error, "Failed with error"), wantStatus: framework.NewStatus(framework.Error, "Failed with error"),
}, },
{ {
name: "Unschedulable", name: "Unschedulable",
reasons: []predicates.PredicateFailureReason{predicates.ErrExistingPodsAntiAffinityRulesNotMatch}, reasons: []predicates.PredicateFailureReason{predicates.ErrPodNotFitsHostPorts},
wantStatus: framework.NewStatus(framework.Unschedulable, "node(s) didn't satisfy existing pods anti-affinity rules"), wantStatus: framework.NewStatus(framework.Unschedulable, "node(s) didn't have free ports for the requested pod ports"),
}, },
{ {
name: "Unschedulable and Unresolvable", name: "Unschedulable and Unresolvable",
reasons: []predicates.PredicateFailureReason{predicates.ErrTaintsTolerationsNotMatch, predicates.ErrNodeSelectorNotMatch}, reasons: []predicates.PredicateFailureReason{predicates.ErrPodNotFitsHostPorts, predicates.ErrNodeSelectorNotMatch},
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, "node(s) had taints that the pod didn't tolerate", "node(s) didn't match node selector"), wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, "node(s) didn't have free ports for the requested pod ports", "node(s) didn't match node selector"),
}, },
} }
for _, tt := range tests { for _, tt := range tests {