Skip to content

Commit

Permalink
Update by lint check
Browse files Browse the repository at this point in the history
  • Loading branch information
hexiaofeng committed Aug 13, 2024
1 parent 68f8d45 commit d5a9d64
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 38 deletions.
20 changes: 9 additions & 11 deletions pkg/scheduler/core/spreadconstraint/group_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion pkg/scheduler/core/spreadconstraint/group_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
47 changes: 22 additions & 25 deletions pkg/scheduler/core/spreadconstraint/group_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit d5a9d64

Please sign in to comment.