From c870d33759dd548696501345d4a324a8ef947463 Mon Sep 17 00:00:00 2001 From: michaelawyu Date: Tue, 18 Jul 2023 00:09:24 +0800 Subject: [PATCH] Minor fixes --- pkg/scheduler/framework/cyclestate_test.go | 2 +- .../topologyspreadconstraints/plugin.go | 2 +- .../topologyspreadconstraints/utils.go | 21 +++++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pkg/scheduler/framework/cyclestate_test.go b/pkg/scheduler/framework/cyclestate_test.go index 5cf8be9c5..3a748daba 100644 --- a/pkg/scheduler/framework/cyclestate_test.go +++ b/pkg/scheduler/framework/cyclestate_test.go @@ -98,6 +98,6 @@ func TestPrepareScheduledOrBoundMap(t *testing.T) { scheduleOrBoundMap := prepareScheduledOrBoundMap(scheduled, bound) if diff := cmp.Diff(scheduleOrBoundMap, want); diff != "" { - t.Errorf("scheduledOrBoundMap diff (-got, +want): %s", diff) + t.Errorf("preparedScheduledOrBoundMap() scheduledOrBoundMap diff (-got, +want): %s", diff) } } diff --git a/pkg/scheduler/framework/plugins/topologyspreadconstraints/plugin.go b/pkg/scheduler/framework/plugins/topologyspreadconstraints/plugin.go index 93d62177f..bb1bb06a3 100644 --- a/pkg/scheduler/framework/plugins/topologyspreadconstraints/plugin.go +++ b/pkg/scheduler/framework/plugins/topologyspreadconstraints/plugin.go @@ -32,7 +32,7 @@ const ( ) var ( - doNotScheduleConstraintViolationReasonTemplate = "violated topology spread constraint %q (max skew %d)" + doNotScheduleConstraintViolationReasonTemplate = "violated doNotSchedule topology spread constraint %q (max skew %d)" ) // Plugin is the scheduler plugin that enforces the diff --git a/pkg/scheduler/framework/plugins/topologyspreadconstraints/utils.go b/pkg/scheduler/framework/plugins/topologyspreadconstraints/utils.go index 00700193e..da4fca2ce 100644 --- a/pkg/scheduler/framework/plugins/topologyspreadconstraints/utils.go +++ b/pkg/scheduler/framework/plugins/topologyspreadconstraints/utils.go @@ -19,8 +19,9 @@ func countByDomain(_ []fleetv1beta1.MemberCluster, _ framework.CycleStatePluginR return &bindingCounterByDomain{} } -// willViolatereturns whether producing one more binding in a domain would lead -// to violations; it will also return the skew change caused by the provisional placement. +// willViolate returns whether producing one more binding in a domain would lead +// to violations; it will also return the skew change (the delta between the max skew after setting +// up a placement and the one before) caused by the provisional placement. func willViolate(_ bindingCounter, _ domainName, _ int) (violated bool, skewChange int, err error) { // Not yet implemented. return false, 0, nil @@ -91,7 +92,13 @@ func evaluateAllConstraints( // The cluster under inspection is part of the spread. // Verify if the placement will violate the constraint. - violated, skewChange, err := willViolate(domainCounter, domainName(val), int(*constraint.MaxSkew)) + + // The default value for maxSkew is 1. + maxSkew := 1 + if constraint.MaxSkew != nil { + maxSkew = int(*constraint.MaxSkew) + } + violated, skewChange, err := willViolate(domainCounter, domainName(val), maxSkew) if err != nil { return nil, nil, fmt.Errorf("failed to evaluate DoNotSchedule topology spread constraints: %w", err) } @@ -133,7 +140,13 @@ func evaluateAllConstraints( // The cluster under inspection is part of the spread. // Verify if the placement will violate the constraint. - violated, skewChange, err := willViolate(domainCounter, domainName(val), int(*constraint.MaxSkew)) + + // The default value for maxSkew is 1. + maxSkew := 1 + if constraint.MaxSkew != nil { + maxSkew = int(*constraint.MaxSkew) + } + violated, skewChange, err := willViolate(domainCounter, domainName(val), maxSkew) if err != nil { return nil, nil, fmt.Errorf("failed to evaluate ScheduleAnyway topology spread constraints: %w", err) }