Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix the issue that when max weight is 100000000, and the replicas> 20, the trafficWeightToReplicas will return negative value. #3474

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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