mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Fix a bug that Pods with topologySpreadConstraints get scheduled to nodes without required labels
This commit is contained in:
parent
ededd08ba1
commit
f7a93ea915
@ -285,7 +285,7 @@ func (pl *PodTopologySpread) Filter(ctx context.Context, cycleState *framework.C
|
|||||||
}
|
}
|
||||||
|
|
||||||
// However, "empty" preFilterState is legit which tolerates every toSchedule Pod.
|
// 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1261,6 +1261,20 @@ func TestSingleConstraint(t *testing.T) {
|
|||||||
"node-y": framework.Unschedulable,
|
"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",
|
name: "pods spread across nodes as 2/1/0/3, only node-x fits",
|
||||||
pod: st.MakePod().Name("p").Label("foo", "").SpreadConstraint(
|
pod: st.MakePod().Name("p").Label("foo", "").SpreadConstraint(
|
||||||
|
Loading…
Reference in New Issue
Block a user