Fix a bug that Pods with topologySpreadConstraints get scheduled to nodes without required labels

This commit is contained in:
Wei Huang 2020-10-22 15:56:16 -07:00
parent ededd08ba1
commit f7a93ea915
No known key found for this signature in database
GPG Key ID: BE5E9752F8B6E005
2 changed files with 15 additions and 1 deletions

View File

@ -285,7 +285,7 @@ func (pl *PodTopologySpread) Filter(ctx context.Context, cycleState *framework.C
}
// However, "empty" preFilterState is legit which tolerates every toSchedule Pod.
if len(s.TpPairToMatchNum) == 0 || len(s.Constraints) == 0 {
if len(s.Constraints) == 0 {
return nil
}

View File

@ -1261,6 +1261,20 @@ func TestSingleConstraint(t *testing.T) {
"node-y": framework.Unschedulable,
},
},
{
name: "pod cannot be scheduled as all nodes don't have label 'rack'",
pod: st.MakePod().Name("p").Label("foo", "").SpreadConstraint(
1, "rack", v1.DoNotSchedule, st.MakeLabelSelector().Exists("foo").Obj(),
).Obj(),
nodes: []*v1.Node{
st.MakeNode().Name("node-a").Label("zone", "zone1").Label("node", "node-a").Obj(),
st.MakeNode().Name("node-x").Label("zone", "zone2").Label("node", "node-x").Obj(),
},
wantStatusCode: map[string]framework.Code{
"node-a": framework.UnschedulableAndUnresolvable,
"node-x": framework.UnschedulableAndUnresolvable,
},
},
{
name: "pods spread across nodes as 2/1/0/3, only node-x fits",
pod: st.MakePod().Name("p").Label("foo", "").SpreadConstraint(