add podAntiAffinity test cases

pull/6/head
yarntime 2016-10-13 17:01:58 +08:00
parent 7746cb9182
commit f21ff43368
1 changed files with 72 additions and 0 deletions

View File

@ -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}