diff --git a/pkg/scheduler/core/spreadconstraint/group_builder.go b/pkg/scheduler/core/spreadconstraint/group_builder.go index c115b8d0a6f2..f45fc8e369cb 100644 --- a/pkg/scheduler/core/spreadconstraint/group_builder.go +++ b/pkg/scheduler/core/spreadconstraint/group_builder.go @@ -115,18 +115,16 @@ func born(parent *groupNode, constraints []policyv1alpha1.SpreadConstraint, inde children := make(map[string]*groupNode) for _, desc := range parent.Clusters { names := getGroup(desc.Cluster, constraint) - if names != nil { - for _, name := range names { - if name != "" { - child, ok := children[name] - if !ok { - child = &groupNode{} - child.Name = name - children[name] = child - parent.Groups = append(parent.Groups, child) - } - child.Clusters = append(child.Clusters, desc) + for _, name := range names { + if name != "" { + child, ok := children[name] + if !ok { + child = &groupNode{} + child.Name = name + children[name] = child + parent.Groups = append(parent.Groups, child) } + child.Clusters = append(child.Clusters, desc) } } } diff --git a/pkg/scheduler/core/spreadconstraint/group_builder_test.go b/pkg/scheduler/core/spreadconstraint/group_builder_test.go index ec81dcd2637c..32c18cb647c7 100644 --- a/pkg/scheduler/core/spreadconstraint/group_builder_test.go +++ b/pkg/scheduler/core/spreadconstraint/group_builder_test.go @@ -111,7 +111,6 @@ func (want *want) match(group *groupNode) error { } func Test_GroupClusters(t *testing.T) { - replicasFunc := func(clusters []*clusterv1alpha1.Cluster, _ *workv1alpha2.ResourceBindingSpec) []workv1alpha2.TargetCluster { availableTargetClusters := make([]workv1alpha2.TargetCluster, len(clusters)) diff --git a/pkg/scheduler/core/spreadconstraint/group_election.go b/pkg/scheduler/core/spreadconstraint/group_election.go index 7b9d03874b43..fdce2d4667b6 100644 --- a/pkg/scheduler/core/spreadconstraint/group_election.go +++ b/pkg/scheduler/core/spreadconstraint/group_election.go @@ -29,30 +29,28 @@ func (root *groupRoot) Elect() ([]*clusterV1alpha1.Cluster, error) { _, err := root.selectCluster(root.Replicas, selects) if err != nil { return nil, err - } else { - var clusters []*clusterDesc - for _, cluster := range selects { - clusters = append(clusters, cluster) - } - sort.Slice(clusters, func(i, j int) bool { - return clusters[i].Score > clusters[j].Score - }) + } + var clusters []*clusterDesc + for _, cluster := range selects { + clusters = append(clusters, cluster) + } + sort.Slice(clusters, func(i, j int) bool { + return clusters[i].Score > clusters[j].Score + }) - var result []*clusterV1alpha1.Cluster - for _, cluster := range clusters { - result = append(result, cluster.Cluster) - } - return result, nil + var result []*clusterV1alpha1.Cluster + for _, cluster := range clusters { + result = append(result, cluster.Cluster) } + return result, nil } // selectCluster method to select clusters based on the required replicas func (node *groupNode) selectCluster(replicas int32, selects map[string]*clusterDesc) (int32, error) { if node.Leaf { return node.selectByClusters(replicas, selects) - } else { - return node.selectByGroups(replicas, selects) } + return node.selectByGroups(replicas, selects) } // selectByClusters selects clusters from the current group's Clusters list @@ -93,17 +91,16 @@ func (node *groupNode) selectByGroups(replicas int32, selects map[string]*cluste return adds, nil } else if maxGroups == groups { return 0, errors.New("not enough replicas in the groups") - } else { - left := make(map[string]*clusterDesc) - for i := maxGroups; i < groups; i++ { - _, _ = node.Groups[i].selectByClusters(InvalidReplicas, left) - } - i, err := node.supplement(selects, left, remain) - if err != nil { - return 0, err - } - return adds + i, nil } + left := make(map[string]*clusterDesc) + for i := maxGroups; i < groups; i++ { + _, _ = node.Groups[i].selectByClusters(InvalidReplicas, left) + } + i, err := node.supplement(selects, left, remain) + if err != nil { + return 0, err + } + return adds + i, nil } } diff --git a/pkg/scheduler/core/spreadconstraint/select_clusters_test.go b/pkg/scheduler/core/spreadconstraint/select_clusters_test.go index 1c64675b6c87..c9768184f636 100644 --- a/pkg/scheduler/core/spreadconstraint/select_clusters_test.go +++ b/pkg/scheduler/core/spreadconstraint/select_clusters_test.go @@ -79,7 +79,7 @@ func TestSelectBestClusters(t *testing.T) { clusterScores = append(clusterScores, sc) replicas[sc.Cluster.Name] = score.replicas } - replicasFunc := func(clusters []*clusterv1alpha1.Cluster, spec *workv1alpha2.ResourceBindingSpec) []workv1alpha2.TargetCluster { + replicasFunc := func(clusters []*clusterv1alpha1.Cluster, _ *workv1alpha2.ResourceBindingSpec) []workv1alpha2.TargetCluster { var result []workv1alpha2.TargetCluster for _, c := range clusters { result = append(result, workv1alpha2.TargetCluster{