Skip to content

Commit

Permalink
fix: some lint problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ipsum-0320 committed Sep 20, 2024
1 parent 17a92a9 commit 1eefa74
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 18 additions & 10 deletions pkg/scheduler/core/spreadconstraint/group_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ limitations under the License.
package spreadconstraint

import (
"k8s.io/utils/ptr"
"math"
"sort"

"k8s.io/utils/ptr"

clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
Expand Down Expand Up @@ -133,6 +134,20 @@ func groupClustersIgnoringTopology(
return groupClustersInfo
}

func checkIfDuplicate(rbSpec *workv1alpha2.ResourceBindingSpec) bool {
return rbSpec.Placement == nil ||
rbSpec.Placement.ReplicaScheduling == nil ||
rbSpec.Placement.ReplicaScheduling.ReplicaSchedulingType == policyv1alpha1.ReplicaSchedulingTypeDuplicated
}

func checkIfStaticWeight(rbSpec *workv1alpha2.ResourceBindingSpec) bool {
return rbSpec.Placement != nil && rbSpec.Placement.ReplicaScheduling != nil &&
rbSpec.Placement.ReplicaScheduling.ReplicaSchedulingType == policyv1alpha1.ReplicaSchedulingTypeDivided &&
rbSpec.Placement.ReplicaScheduling.ReplicaDivisionPreference == policyv1alpha1.ReplicaDivisionPreferenceWeighted &&
(rbSpec.Placement.ReplicaScheduling.WeightPreference == nil ||
len(rbSpec.Placement.ReplicaScheduling.WeightPreference.StaticWeightList) != 0 && rbSpec.Placement.ReplicaScheduling.WeightPreference.DynamicWeight == "")
}

func (info *GroupClustersInfo) calcGroupScore(clusters []ClusterDetailInfo, rbSpec *workv1alpha2.ResourceBindingSpec) int64 {
// sort clusters by Score, from high score to low score.
sort.Slice(clusters, func(i, j int) bool {
Expand All @@ -154,12 +169,9 @@ func (info *GroupClustersInfo) calcGroupScore(clusters []ClusterDetailInfo, rbSp
}
var baseScore, bonusScore int64
baseScore = highScoreSum/selectedNum - (clusters[0].Score - clusters[len(clusters)-1].Score)
bonusScore = 0

// if duplicate =>
if rbSpec.Placement == nil ||
rbSpec.Placement.ReplicaScheduling == nil ||
rbSpec.Placement.ReplicaScheduling.ReplicaSchedulingType == policyv1alpha1.ReplicaSchedulingTypeDuplicated {
if checkIfDuplicate(rbSpec) {
var goodNum int
for _, cluster := range clusters {
if cluster.AvailableReplicas >= int64(rbSpec.Replicas) {
Expand All @@ -172,11 +184,7 @@ func (info *GroupClustersInfo) calcGroupScore(clusters []ClusterDetailInfo, rbSp
}

// if static weight =>
if rbSpec.Placement != nil && rbSpec.Placement.ReplicaScheduling != nil &&
rbSpec.Placement.ReplicaScheduling.ReplicaSchedulingType == policyv1alpha1.ReplicaSchedulingTypeDivided &&
rbSpec.Placement.ReplicaScheduling.ReplicaDivisionPreference == policyv1alpha1.ReplicaDivisionPreferenceWeighted &&
(rbSpec.Placement.ReplicaScheduling.WeightPreference == nil ||
len(rbSpec.Placement.ReplicaScheduling.WeightPreference.StaticWeightList) != 0 && rbSpec.Placement.ReplicaScheduling.WeightPreference.DynamicWeight == "") {
if checkIfStaticWeight(rbSpec) {
return baseScore
}

Expand Down
1 change: 0 additions & 1 deletion pkg/scheduler/core/spreadconstraint/group_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ func generateClusterScores() [][]ClusterDetailInfo {
}

func Test_CalcGroupScore(t *testing.T) {

rbSpecs := generateRbSpec()
scores := generateClusterScores()

Expand Down

0 comments on commit 1eefa74

Please sign in to comment.