mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Break interpodaffinity Filter plugins dependency on predicates package
This commit is contained in:
parent
110da204f6
commit
a1053e4835
@ -33,14 +33,6 @@ var (
|
||||
|
||||
// ErrNodeSelectorNotMatch is used for MatchNodeSelector predicate error.
|
||||
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 = NewPredicateFailureError("PodToleratesNodeTaints", "node(s) had taints that the pod didn't tolerate")
|
||||
// ErrPodNotMatchHostName is used for HostName predicate error.
|
||||
@ -72,7 +64,6 @@ var (
|
||||
|
||||
var unresolvablePredicateFailureErrors = map[PredicateFailureReason]struct{}{
|
||||
ErrNodeSelectorNotMatch: {},
|
||||
ErrPodAffinityRulesNotMatch: {},
|
||||
ErrPodNotMatchHostName: {},
|
||||
ErrTaintsTolerationsNotMatch: {},
|
||||
// Node conditions won't change when scheduler simulates removal of preemption victims.
|
||||
|
@ -1879,9 +1879,9 @@ func TestNodesWherePreemptionMightHelp(t *testing.T) {
|
||||
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{
|
||||
"machine1": framework.NewStatus(framework.Unschedulable, algorithmpredicates.ErrPodAffinityNotMatch.GetReason()),
|
||||
"machine1": framework.NewStatus(framework.Unschedulable, interpodaffinity.ErrReasonAffinityNotMatch),
|
||||
"machine2": framework.NewStatus(framework.UnschedulableAndUnresolvable, algorithmpredicates.ErrPodNotMatchHostName.GetReason()),
|
||||
"machine3": framework.NewStatus(framework.UnschedulableAndUnresolvable, algorithmpredicates.ErrNodeUnschedulable.GetReason()),
|
||||
},
|
||||
@ -1890,16 +1890,16 @@ func TestNodesWherePreemptionMightHelp(t *testing.T) {
|
||||
{
|
||||
name: "pod with both pod affinity and anti-affinity should be tried",
|
||||
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()),
|
||||
},
|
||||
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{
|
||||
"machine1": framework.NewStatus(framework.UnschedulableAndUnresolvable, algorithmpredicates.ErrPodAffinityRulesNotMatch.GetReason()),
|
||||
"machine2": framework.NewStatus(framework.Unschedulable, algorithmpredicates.ErrPodAffinityNotMatch.GetReason()),
|
||||
"machine1": framework.NewStatus(framework.UnschedulableAndUnresolvable, interpodaffinity.ErrReasonAffinityRulesNotMatch),
|
||||
"machine2": framework.NewStatus(framework.Unschedulable, interpodaffinity.ErrReasonAffinityNotMatch),
|
||||
},
|
||||
expected: map[string]bool{"machine2": true, "machine3": true, "machine4": true},
|
||||
},
|
||||
|
@ -10,9 +10,7 @@ go_library(
|
||||
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//pkg/scheduler/algorithm/predicates: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/listers:go_default_library",
|
||||
"//pkg/scheduler/nodeinfo:go_default_library",
|
||||
@ -35,7 +33,6 @@ go_test(
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//pkg/scheduler/algorithm/predicates:go_default_library",
|
||||
"//pkg/scheduler/framework/v1alpha1:go_default_library",
|
||||
"//pkg/scheduler/nodeinfo/snapshot:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
|
@ -27,17 +27,26 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/client-go/util/workqueue"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
||||
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"
|
||||
"k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||
schedutil "k8s.io/kubernetes/pkg/scheduler/util"
|
||||
)
|
||||
|
||||
// preFilterStateKey is the key in CycleState to InterPodAffinity pre-computed data for Filtering.
|
||||
// Using the name of the plugin will likely help us avoid collisions with other plugins.
|
||||
const preFilterStateKey = "PreFilter" + Name
|
||||
const (
|
||||
// preFilterStateKey is the key in CycleState to InterPodAffinity pre-computed data for Filtering.
|
||||
// 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.
|
||||
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.
|
||||
// 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,
|
||||
state *preFilterState, nodeInfo *nodeinfo.NodeInfo,
|
||||
affinity *v1.Affinity) (predicates.PredicateFailureReason, error) {
|
||||
affinity *v1.Affinity) (bool, bool, error) {
|
||||
node := nodeInfo.Node()
|
||||
if node == nil {
|
||||
return predicates.ErrPodAffinityRulesNotMatch, fmt.Errorf("node not found")
|
||||
return false, false, fmt.Errorf("node not found")
|
||||
}
|
||||
if state != nil {
|
||||
// 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
|
||||
// its own terms, then we allow the pod to pass the affinity check.
|
||||
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 {
|
||||
matchExists := nodeMatchesAnyTopologyTerm(pod, topologyToMatchedAntiAffinityTerms, nodeInfo, antiAffinityTerms)
|
||||
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.
|
||||
filteredPods, err := pl.sharedLister.Pods().FilteredList(nodeInfo.Filter, labels.Everything())
|
||||
if err != nil {
|
||||
return predicates.ErrPodAffinityRulesNotMatch, err
|
||||
return false, false, err
|
||||
}
|
||||
|
||||
affinityTerms := schedutil.GetPodAffinityTerms(affinity.PodAffinity)
|
||||
@ -575,7 +586,7 @@ func (pl *InterPodAffinity) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod,
|
||||
if !matchFound && len(affinityTerms) > 0 {
|
||||
affTermsMatch, termsSelectorMatch, err := pl.podMatchesPodAffinityTerms(pod, targetPod, nodeInfo, affinityTerms)
|
||||
if err != nil {
|
||||
return predicates.ErrPodAffinityRulesNotMatch, err
|
||||
return false, false, err
|
||||
}
|
||||
if termsSelectorMatch {
|
||||
termsSelectorMatchFound = true
|
||||
@ -589,7 +600,7 @@ func (pl *InterPodAffinity) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod,
|
||||
if len(antiAffinityTerms) > 0 {
|
||||
antiAffTermsMatch, _, err := pl.podMatchesPodAffinityTerms(pod, targetPod, nodeInfo, antiAffinityTerms)
|
||||
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
|
||||
// its own terms, then we allow the pod to pass the affinity check.
|
||||
if termsSelectorMatchFound {
|
||||
return predicates.ErrPodAffinityRulesNotMatch, nil
|
||||
return false, false, nil
|
||||
}
|
||||
// Check if pod matches its own affinity terms (namespace and label selector).
|
||||
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.
|
||||
@ -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 {
|
||||
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.
|
||||
@ -630,8 +644,16 @@ func (pl *InterPodAffinity) Filter(ctx context.Context, cycleState *framework.Cy
|
||||
if affinity == nil || (affinity.PodAffinity == nil && affinity.PodAntiAffinity == nil) {
|
||||
return nil
|
||||
}
|
||||
if status, err := pl.satisfiesPodsAffinityAntiAffinity(pod, state, nodeInfo, affinity); err != nil || status != nil {
|
||||
return migration.PredicateResultToFrameworkStatus([]predicates.PredicateFailureReason{predicates.ErrPodAffinityNotMatch, status}, err)
|
||||
if satisfiesAffinity, satisfiesAntiAffinity, err := pl.satisfiesPodsAffinityAntiAffinity(pod, state, nodeInfo, affinity); err != nil || !satisfiesAffinity || !satisfiesAntiAffinity {
|
||||
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
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||
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",
|
||||
wantStatus: framework.NewStatus(
|
||||
framework.UnschedulableAndUnresolvable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAffinityRulesNotMatch,
|
||||
),
|
||||
},
|
||||
{
|
||||
@ -158,8 +157,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
|
||||
name: "Doesn't satisfy the PodAffinity because of unmatching labelSelector with the existing pod",
|
||||
wantStatus: framework.NewStatus(
|
||||
framework.UnschedulableAndUnresolvable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
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.",
|
||||
wantStatus: framework.NewStatus(
|
||||
framework.UnschedulableAndUnresolvable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAffinityRulesNotMatch,
|
||||
),
|
||||
},
|
||||
{
|
||||
@ -360,8 +359,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
|
||||
name: "satisfies the PodAffinity but doesn't satisfy the PodAntiAffinity with the existing pod",
|
||||
wantStatus: framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
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",
|
||||
wantStatus: framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
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",
|
||||
wantStatus: framework.NewStatus(
|
||||
framework.UnschedulableAndUnresolvable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
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",
|
||||
wantStatus: framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
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",
|
||||
wantStatus: framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAntiAffinityRulesNotMatch,
|
||||
),
|
||||
},
|
||||
{
|
||||
@ -596,8 +595,8 @@ func TestRequiredAffinitySingleNode(t *testing.T) {
|
||||
node: &node1,
|
||||
wantStatus: framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAntiAffinityRulesNotMatch,
|
||||
),
|
||||
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,
|
||||
wantStatus: framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonExistingAntiAffinityRulesNotMatch,
|
||||
),
|
||||
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,
|
||||
wantStatus: framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonExistingAntiAffinityRulesNotMatch,
|
||||
),
|
||||
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,
|
||||
wantStatus: framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonExistingAntiAffinityRulesNotMatch,
|
||||
),
|
||||
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,
|
||||
framework.NewStatus(
|
||||
framework.UnschedulableAndUnresolvable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
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",
|
||||
@ -914,13 +913,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
|
||||
wantStatuses: []*framework.Status{
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAntiAffinityRulesNotMatch,
|
||||
),
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
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.",
|
||||
@ -963,13 +962,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
|
||||
wantStatuses: []*framework.Status{
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAntiAffinityRulesNotMatch,
|
||||
),
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAntiAffinityRulesNotMatch,
|
||||
),
|
||||
},
|
||||
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{
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAntiAffinityRulesNotMatch,
|
||||
),
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAntiAffinityRulesNotMatch,
|
||||
),
|
||||
nil,
|
||||
},
|
||||
@ -1061,13 +1060,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
|
||||
wantStatuses: []*framework.Status{
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAntiAffinityRulesNotMatch,
|
||||
),
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAntiAffinityRulesNotMatch,
|
||||
),
|
||||
nil,
|
||||
},
|
||||
@ -1171,13 +1170,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
|
||||
wantStatuses: []*framework.Status{
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonExistingAntiAffinityRulesNotMatch,
|
||||
),
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
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",
|
||||
@ -1229,13 +1228,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
|
||||
wantStatuses: []*framework.Status{
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAntiAffinityRulesNotMatch,
|
||||
),
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
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",
|
||||
@ -1278,8 +1277,8 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
|
||||
wantStatuses: []*framework.Status{
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonExistingAntiAffinityRulesNotMatch,
|
||||
),
|
||||
nil,
|
||||
},
|
||||
@ -1326,8 +1325,8 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
|
||||
wantStatuses: []*framework.Status{
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAntiAffinityRulesNotMatch,
|
||||
),
|
||||
nil,
|
||||
},
|
||||
@ -1371,13 +1370,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
|
||||
wantStatuses: []*framework.Status{
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonExistingAntiAffinityRulesNotMatch,
|
||||
),
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
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",
|
||||
@ -1423,13 +1422,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
|
||||
wantStatuses: []*framework.Status{
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAntiAffinityRulesNotMatch,
|
||||
),
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
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",
|
||||
@ -1498,13 +1497,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
|
||||
wantStatuses: []*framework.Status{
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonExistingAntiAffinityRulesNotMatch,
|
||||
),
|
||||
framework.NewStatus(
|
||||
framework.Unschedulable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrExistingPodsAntiAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonExistingAntiAffinityRulesNotMatch,
|
||||
),
|
||||
nil,
|
||||
},
|
||||
@ -1598,13 +1597,13 @@ func TestRequiredAffinityMultipleNodes(t *testing.T) {
|
||||
wantStatuses: []*framework.Status{
|
||||
framework.NewStatus(
|
||||
framework.UnschedulableAndUnresolvable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
ErrReasonAffinityRulesNotMatch,
|
||||
),
|
||||
framework.NewStatus(
|
||||
framework.UnschedulableAndUnresolvable,
|
||||
predicates.ErrPodAffinityNotMatch.GetReason(),
|
||||
predicates.ErrPodAffinityRulesNotMatch.GetReason(),
|
||||
ErrReasonAffinityNotMatch,
|
||||
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",
|
||||
|
@ -43,18 +43,18 @@ func TestPredicateResultToFrameworkStatus(t *testing.T) {
|
||||
{
|
||||
name: "Error with reason",
|
||||
err: errors.New("Failed with error"),
|
||||
reasons: []predicates.PredicateFailureReason{predicates.ErrTaintsTolerationsNotMatch},
|
||||
reasons: []predicates.PredicateFailureReason{predicates.ErrPodNotFitsHostPorts},
|
||||
wantStatus: framework.NewStatus(framework.Error, "Failed with error"),
|
||||
},
|
||||
{
|
||||
name: "Unschedulable",
|
||||
reasons: []predicates.PredicateFailureReason{predicates.ErrExistingPodsAntiAffinityRulesNotMatch},
|
||||
wantStatus: framework.NewStatus(framework.Unschedulable, "node(s) didn't satisfy existing pods anti-affinity rules"),
|
||||
reasons: []predicates.PredicateFailureReason{predicates.ErrPodNotFitsHostPorts},
|
||||
wantStatus: framework.NewStatus(framework.Unschedulable, "node(s) didn't have free ports for the requested pod ports"),
|
||||
},
|
||||
{
|
||||
name: "Unschedulable and Unresolvable",
|
||||
reasons: []predicates.PredicateFailureReason{predicates.ErrTaintsTolerationsNotMatch, predicates.ErrNodeSelectorNotMatch},
|
||||
wantStatus: framework.NewStatus(framework.UnschedulableAndUnresolvable, "node(s) had taints that the pod didn't tolerate", "node(s) didn't match node selector"),
|
||||
reasons: []predicates.PredicateFailureReason{predicates.ErrPodNotFitsHostPorts, predicates.ErrNodeSelectorNotMatch},
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user