Skip to content

Commit

Permalink
fix: when max weight is 100000000, the replicas can be negative.
Browse files Browse the repository at this point in the history
Signed-off-by: Liming Liu <andyliuliming@outlook.com>
  • Loading branch information
andyliuliming committed Mar 26, 2024
1 parent 4b1cc3b commit 47cfdea
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion utils/replicaset/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func CalculateReplicaCountsForTrafficRoutedCanary(rollout *v1alpha1.Rollout, wei
// trafficWeightToReplicas returns the appropriate replicas given the full spec.replicas and a weight
// Rounds up if not evenly divisible.
func trafficWeightToReplicas(replicas, weight, maxWeight int32) int32 {
return int32(math.Ceil(float64(weight*replicas) / float64(maxWeight)))
return int32(math.Ceil(float64(weight) * float64(replicas) / float64(maxWeight)))
}

func max(left, right int32) int32 {
Expand Down
1 change: 1 addition & 0 deletions utils/replicaset/canary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ func TestTrafficWeightToReplicas(t *testing.T) {
assert.Equal(t, int32(4), trafficWeightToReplicas(10, 33, 100))
assert.Equal(t, int32(10), trafficWeightToReplicas(10, 99, 100))
assert.Equal(t, int32(10), trafficWeightToReplicas(10, 100, 100))
assert.Equal(t, int32(23), trafficWeightToReplicas(23, 100000000, 100000000))
}

func TestGetOtherRSs(t *testing.T) {
Expand Down

0 comments on commit 47cfdea

Please sign in to comment.