diff --git a/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity.go b/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity.go index 841da141b58..d966e53d1d1 100644 --- a/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity.go +++ b/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity.go @@ -127,14 +127,13 @@ func (pl *NodeAffinity) PreFilter(ctx context.Context, cycleState *framework.Cyc // then all nodes are eligible because the terms are ORed. return nil, nil } - // If the set is empty, it means the terms had affinity to different - // sets of nodes, and since they are ANDed, then the pod will not match any node. - if len(termNodeNames) == 0 { - return nil, framework.NewStatus(framework.UnschedulableAndUnresolvable, errReasonConflict) - } nodeNames = nodeNames.Union(termNodeNames) } - if nodeNames != nil { + // If nodeNames is not nil, but length is 0, it means each term have conflicting affinity to node.Name; + // therefore, pod will not match any node. + if nodeNames != nil && len(nodeNames) == 0 { + return nil, framework.NewStatus(framework.UnschedulableAndUnresolvable, errReasonConflict) + } else if len(nodeNames) > 0 { return &framework.PreFilterResult{NodeNames: nodeNames}, nil } return nil, nil diff --git a/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go b/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go index 2911e106f24..c01117a1fd9 100644 --- a/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go +++ b/pkg/scheduler/framework/plugins/nodeaffinity/node_affinity_test.go @@ -537,6 +537,11 @@ func TestNodeAffinity(t *testing.T) { Operator: v1.NodeSelectorOpIn, Values: []string{"node1"}, }, + { + Key: metav1.ObjectNameField, + Operator: v1.NodeSelectorOpIn, + Values: []string{"node2"}, + }, }, }, {