Merge pull request #95812 from Huang-Wei/fix-pts-node-miss-label

Fix a bug that Pods with topologySpreadConstraints get scheduled to nodes without required labels
This commit is contained in:
Kubernetes Prow Robot 2020-10-23 09:55:57 -07:00 committed by GitHub
commit 1fcd02cc2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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(