Skip to content

Commit 1fcd02c

Browse files
authored
Merge pull request kubernetes#95812 from Huang-Wei/fix-pts-node-miss-label
Fix a bug that Pods with topologySpreadConstraints get scheduled to nodes without required labels
2 parents ec453ff + f7a93ea commit 1fcd02c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pkg/scheduler/framework/plugins/podtopologyspread/filtering.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func (pl *PodTopologySpread) Filter(ctx context.Context, cycleState *framework.C
285285
}
286286

287287
// However, "empty" preFilterState is legit which tolerates every toSchedule Pod.
288-
if len(s.TpPairToMatchNum) == 0 || len(s.Constraints) == 0 {
288+
if len(s.Constraints) == 0 {
289289
return nil
290290
}
291291

pkg/scheduler/framework/plugins/podtopologyspread/filtering_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,20 @@ func TestSingleConstraint(t *testing.T) {
12611261
"node-y": framework.Unschedulable,
12621262
},
12631263
},
1264+
{
1265+
name: "pod cannot be scheduled as all nodes don't have label 'rack'",
1266+
pod: st.MakePod().Name("p").Label("foo", "").SpreadConstraint(
1267+
1, "rack", v1.DoNotSchedule, st.MakeLabelSelector().Exists("foo").Obj(),
1268+
).Obj(),
1269+
nodes: []*v1.Node{
1270+
st.MakeNode().Name("node-a").Label("zone", "zone1").Label("node", "node-a").Obj(),
1271+
st.MakeNode().Name("node-x").Label("zone", "zone2").Label("node", "node-x").Obj(),
1272+
},
1273+
wantStatusCode: map[string]framework.Code{
1274+
"node-a": framework.UnschedulableAndUnresolvable,
1275+
"node-x": framework.UnschedulableAndUnresolvable,
1276+
},
1277+
},
12641278
{
12651279
name: "pods spread across nodes as 2/1/0/3, only node-x fits",
12661280
pod: st.MakePod().Name("p").Label("foo", "").SpreadConstraint(

0 commit comments

Comments
 (0)