Merge pull request #39601 from mqliang/upstream-tolerates-taints-bugfix

Automatic merge from submit-queue (batch tested with PRs 39945, 39601)

bugfix for PodToleratesNodeTaints

`PodToleratesNodeTaints`predicate func should return true if pod has no toleration annotations and node's taint effect is `PreferNoSchedule`
This commit is contained in:
Kubernetes Submit Queue 2017-01-17 04:08:47 -08:00 committed by GitHub
commit b1506004cc
2 changed files with 26 additions and 6 deletions

View File

@ -1170,11 +1170,6 @@ func tolerationsToleratesTaints(tolerations []v1.Toleration, taints []v1.Taint)
return true return true
} }
// The taint list isn't nil/empty, a nil/empty toleration list can't tolerate them.
if len(tolerations) == 0 {
return false
}
for i := range taints { for i := range taints {
taint := &taints[i] taint := &taints[i]
// skip taints that have effect PreferNoSchedule, since it is for priorities // skip taints that have effect PreferNoSchedule, since it is for priorities
@ -1182,7 +1177,7 @@ func tolerationsToleratesTaints(tolerations []v1.Toleration, taints []v1.Taint)
continue continue
} }
if !v1.TaintToleratedByTolerations(taint, tolerations) { if len(tolerations) == 0 || !v1.TaintToleratedByTolerations(taint, tolerations) {
return false return false
} }
} }

View File

@ -3212,6 +3212,31 @@ func TestPodToleratesTaints(t *testing.T) {
test: "The pod has a toleration that key and value don't match the taint on the node, " + test: "The pod has a toleration that key and value don't match the taint on the node, " +
"but the effect of taint on node is PreferNochedule. Pod can be scheduled onto the node", "but the effect of taint on node is PreferNochedule. Pod can be scheduled onto the node",
}, },
{
pod: &v1.Pod{
ObjectMeta: v1.ObjectMeta{
Name: "pod2",
},
Spec: v1.PodSpec{
Containers: []v1.Container{{Image: "pod2:V1"}},
},
},
node: v1.Node{
ObjectMeta: v1.ObjectMeta{
Annotations: map[string]string{
v1.TaintsAnnotationKey: `
[{
"key": "dedicated",
"value": "user1",
"effect": "PreferNoSchedule"
}]`,
},
},
},
fits: true,
test: "The pod has no toleration, " +
"but the effect of taint on node is PreferNochedule. Pod can be scheduled onto the node",
},
} }
expectedFailureReasons := []algorithm.PredicateFailureReason{ErrTaintsTolerationsNotMatch} expectedFailureReasons := []algorithm.PredicateFailureReason{ErrTaintsTolerationsNotMatch}