diff --git a/plugin/pkg/scheduler/algorithm/predicates/predicates.go b/plugin/pkg/scheduler/algorithm/predicates/predicates.go index 2e5b6d934b8..f42d8172e38 100644 --- a/plugin/pkg/scheduler/algorithm/predicates/predicates.go +++ b/plugin/pkg/scheduler/algorithm/predicates/predicates.go @@ -1180,11 +1180,6 @@ func tolerationsToleratesTaints(tolerations []v1.Toleration, taints []v1.Taint) 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 { taint := &taints[i] // skip taints that have effect PreferNoSchedule, since it is for priorities @@ -1192,7 +1187,7 @@ func tolerationsToleratesTaints(tolerations []v1.Toleration, taints []v1.Taint) continue } - if !v1.TaintToleratedByTolerations(taint, tolerations) { + if len(tolerations) == 0 || !v1.TaintToleratedByTolerations(taint, tolerations) { return false } } diff --git a/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go b/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go index 7f60b773640..62163d15647 100644 --- a/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go +++ b/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go @@ -3060,6 +3060,31 @@ func TestPodToleratesTaints(t *testing.T) { 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", }, + { + 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}