Skip to content

Commit 3dccf54

Browse files
authored
Merge pull request kubernetes#87566 from skilxn-go/Speard
Skip default spreading scoring plugin for pods that define TopologySpreadConstraints
2 parents 17936ff + a4d1624 commit 3dccf54

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,19 @@ func (s *postFilterState) Clone() framework.StateData {
6767
return s
6868
}
6969

70+
// skipDefaultPodTopologySpread returns true if the pod's TopologySpreadConstraints are specified.
71+
func skipDefaultPodTopologySpread(pod *v1.Pod) bool {
72+
return len(pod.Spec.TopologySpreadConstraints) != 0
73+
}
74+
7075
// Score invoked at the Score extension point.
7176
// The "score" returned in this function is the matching number of pods on the `nodeName`,
7277
// it is normalized later.
7378
func (pl *DefaultPodTopologySpread) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) {
79+
if skipDefaultPodTopologySpread(pod) {
80+
return 0, nil
81+
}
82+
7483
c, err := state.Read(postFilterStateKey)
7584
if err != nil {
7685
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("Error reading %q from cycleState: %v", postFilterStateKey, err))
@@ -96,6 +105,10 @@ func (pl *DefaultPodTopologySpread) Score(ctx context.Context, state *framework.
96105
// where zone information is included on the nodes, it favors nodes
97106
// in zones with fewer existing matching pods.
98107
func (pl *DefaultPodTopologySpread) NormalizeScore(ctx context.Context, state *framework.CycleState, pod *v1.Pod, scores framework.NodeScoreList) *framework.Status {
108+
if skipDefaultPodTopologySpread(pod) {
109+
return nil
110+
}
111+
99112
countsByZone := make(map[string]int64, 10)
100113
maxCountByZone := int64(0)
101114
maxCountByNodeName := int64(0)

pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,32 @@ func TestDefaultPodTopologySpreadScore(t *testing.T) {
338338
expectedList: []framework.NodeScore{{Name: "machine1", Score: 0}, {Name: "machine2", Score: 50}},
339339
name: "Another stateful set with partial pod label matches",
340340
},
341+
{
342+
pod: &v1.Pod{
343+
ObjectMeta: metav1.ObjectMeta{
344+
Labels: labels1,
345+
OwnerReferences: controllerRef("StatefulSet", "name", "abc123"),
346+
},
347+
Spec: v1.PodSpec{
348+
TopologySpreadConstraints: []v1.TopologySpreadConstraint{
349+
{
350+
MaxSkew: 1,
351+
TopologyKey: "foo",
352+
WhenUnsatisfiable: v1.DoNotSchedule,
353+
},
354+
},
355+
},
356+
},
357+
pods: []*v1.Pod{
358+
{Spec: zone1Spec, ObjectMeta: metav1.ObjectMeta{Labels: labels2, OwnerReferences: controllerRef("StatefulSet", "name", "abc123")}},
359+
{Spec: zone1Spec, ObjectMeta: metav1.ObjectMeta{Labels: labels1, OwnerReferences: controllerRef("StatefulSet", "name", "abc123")}},
360+
{Spec: zone2Spec, ObjectMeta: metav1.ObjectMeta{Labels: labels1, OwnerReferences: controllerRef("StatefulSet", "name", "abc123")}},
361+
},
362+
nodes: []string{"machine1", "machine2"},
363+
sss: []*apps.StatefulSet{{Spec: apps.StatefulSetSpec{Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"baz": "blah"}}}}},
364+
expectedList: []framework.NodeScore{{Name: "machine1", Score: 0}, {Name: "machine2", Score: 0}},
365+
name: "Another stateful set with TopologySpreadConstraints set in pod",
366+
},
341367
}
342368

343369
for _, test := range tests {

0 commit comments

Comments
 (0)