From f21ff43368df6db8daa813ee2928451dc208bf43 Mon Sep 17 00:00:00 2001 From: yarntime Date: Thu, 13 Oct 2016 17:01:58 +0800 Subject: [PATCH] add podAntiAffinity test cases --- .../algorithm/predicates/predicates_test.go | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go b/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go index 47a1ea714b0..66685c9c60f 100755 --- a/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go +++ b/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go @@ -2507,6 +2507,78 @@ func TestInterPodAffinityWithMultipleNodes(t *testing.T) { test: "The affinity rule is to schedule all of the pods of this collection to the same zone. The first pod of the collection " + "should not be blocked from being scheduled onto any node, even there's no existing pod that match the rule anywhere.", }, + { + pod: &api.Pod{ + ObjectMeta: api.ObjectMeta{ + Annotations: map[string]string{ + api.AffinityAnnotationKey: ` + { + "podAntiAffinity": { + "requiredDuringSchedulingIgnoredDuringExecution": [{ + "labelSelector": { + "matchExpressions": [{ + "key": "foo", + "operator": "In", + "values": ["abc"] + }] + }, + "topologyKey": "region" + }] + } + }`, + }, + }, + }, + pods: []*api.Pod{ + {Spec: api.PodSpec{NodeName: "nodeA"}, ObjectMeta: api.ObjectMeta{Labels: map[string]string{"foo": "abc"}}}, + }, + nodes: []api.Node{ + {ObjectMeta: api.ObjectMeta{Name: "nodeA", Labels: map[string]string{"region": "r1", "hostname": "nodeA"}}}, + {ObjectMeta: api.ObjectMeta{Name: "nodeB", Labels: map[string]string{"region": "r1", "hostname": "nodeB"}}}, + }, + fits: map[string]bool{ + "nodeA": false, + "nodeB": false, + }, + test: "NodeA and nodeB have same topologyKey and label value. NodeA has an existing pod that match the inter pod affinity rule. The pod can not be scheduled onto nodeA and nodeB.", + }, + { + pod: &api.Pod{ + ObjectMeta: api.ObjectMeta{ + Annotations: map[string]string{ + api.AffinityAnnotationKey: ` + { + "podAntiAffinity": { + "requiredDuringSchedulingIgnoredDuringExecution": [{ + "labelSelector": { + "matchExpressions": [{ + "key": "foo", + "operator": "In", + "values": ["abc"] + }] + }, + "topologyKey": "region" + }] + } + }`, + }, + }, + }, + pods: []*api.Pod{ + {Spec: api.PodSpec{NodeName: "nodeA"}, ObjectMeta: api.ObjectMeta{Labels: map[string]string{"foo": "abc"}}}, + }, + nodes: []api.Node{ + {ObjectMeta: api.ObjectMeta{Name: "nodeA", Labels: labelRgChina}}, + {ObjectMeta: api.ObjectMeta{Name: "nodeB", Labels: labelRgChinaAzAz1}}, + {ObjectMeta: api.ObjectMeta{Name: "nodeC", Labels: labelRgIndia}}, + }, + fits: map[string]bool{ + "nodeA": false, + "nodeB": false, + "nodeC": true, + }, + test: "NodeA and nodeB have same topologyKey and label value. NodeA has an existing pod that match the inter pod affinity rule. The pod can not be scheduled onto nodeA and nodeB but can be schedulerd onto nodeC", + }, } affinityExpectedFailureReasons := []algorithm.PredicateFailureReason{ErrPodAffinityNotMatch} selectorExpectedFailureReasons := []algorithm.PredicateFailureReason{ErrNodeSelectorNotMatch}