Skip to content

Commit

Permalink
fix When EnableEmptyWorkloadPropagation flag is false zero deployment…
Browse files Browse the repository at this point in the history
… still can be propagated to member cluster

Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
  • Loading branch information
chaunceyjiang committed May 6, 2023
1 parent 0e10088 commit aff506f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
16 changes: 16 additions & 0 deletions pkg/scheduler/core/division_algorithm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ func Test_dispenser_takeByWeight(t *testing.T) {
},
done: true,
},
{
name: "remove zero replicas",
numReplicas: 2,
result: []workv1alpha2.TargetCluster{},
weightList: []utilhelper.ClusterWeightInfo{
{ClusterName: "A", Weight: 1},
{ClusterName: "B", Weight: 1},
{ClusterName: "C", Weight: 1},
{ClusterName: "D", Weight: 1},
},
desired: []workv1alpha2.TargetCluster{
{Name: "A", Replicas: 1},
{Name: "B", Replicas: 1},
},
done: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
18 changes: 12 additions & 6 deletions pkg/util/helper/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,20 @@ func (a *Dispenser) TakeByWeight(w ClusterWeightInfoList) {
remain -= replicas
}
// TODO(Garrybest): take rest replicas by fraction part
for i := range result {
if remain == 0 {
break
for i, removed, resultLen := 0, 0, len(result); i < resultLen; i++ {
j := i - removed
if remain != 0 {
result[j].Replicas++
remain--
continue
}
// when the replicas of a scheduling result is zero,
// it should not be propagated to member cluster.
if result[j].Replicas == 0 {
result = append(result[:j], result[j+1:]...)
removed++
}
result[i].Replicas++
remain--
}

a.NumReplicas = remain
a.Result = util.MergeTargetClusters(a.Result, result)
}
Expand Down

0 comments on commit aff506f

Please sign in to comment.