Skip to content

fix: reject maxTrafficWeight below 1 - #4924

Open
semx wants to merge 1 commit into
argoproj:masterfrom
semx:fix/max-traffic-weight-zero
Open

fix: reject maxTrafficWeight below 1#4924
semx wants to merge 1 commit into
argoproj:masterfrom
semx:fix/max-traffic-weight-zero

Conversation

@semx

@semx semx commented Jul 27, 2026

Copy link
Copy Markdown

maxTrafficWeight is used as a divisor, but nothing stops it from being zero.

The problem

The CRD puts no bound on the field:

maxTrafficWeight:
  description: MaxTrafficWeight The total weight of traffic. If unspecified, it defaults to 100
  format: int32
  type: integer

Validation checks that each setWeight is between 0 and maxTrafficWeight, but never checks maxTrafficWeight itself. With maxTrafficWeight: 0 a setWeight: 0 step still passes, and checkReplicasAvailable divides by it:

desiredReplicas := (desiredWeight * totalReplicas) / weightutil.MaxTrafficWeight(c.rollout)

which panics:

panic: runtime error: integer divide by zero
    github.com/argoproj/argo-rollouts/rollout.(*rolloutContext).checkReplicasAvailable

The panic is recovered by the workqueue, but the reconcile for that rollout fails each time it is retried.

The fix

Reject values below 1 during validation, next to the existing maxTrafficWeight check, so the user gets an InvalidSpec condition explaining the problem. getRolloutValidationErrors runs before the reconcile touches the traffic weights, so the division is no longer reachable with a zero total weight.

Negative values are rejected too — they produce negative replica counts rather than a panic.

Test

Added a case to TestValidateRolloutStrategyCanary covering 0 and -1. It fails without the check and passes with it.

The CRD accepts any int32 for maxTrafficWeight, and the value is used as
a divisor when replica counts are derived from traffic weights. Setting
it to 0 makes checkReplicasAvailable panic with an integer divide by
zero, which fails the reconcile for that rollout.

Reject it during validation, next to the existing maxTrafficWeight
check, so the user gets an InvalidSpec condition instead.

Signed-off-by: semx <7532921+semx@users.noreply.github.com>
@semx
semx requested a review from a team as a code owner July 27, 2026 08:28
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Published E2E Test Results

  4 files    4 suites   4h 3m 8s ⏱️
123 tests 111 ✅  7 💤  5 ❌
508 runs  465 ✅ 28 💤 15 ❌

For more details on these failures, see this check.

Results for commit b46c354.

@github-actions

Copy link
Copy Markdown
Contributor

Published Unit Test Results

2 580 tests   2 580 ✅  3m 26s ⏱️
  130 suites      0 💤
    1 files        0 ❌

Results for commit b46c354.

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.06%. Comparing base (d1dd467) to head (b46c354).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4924      +/-   ##
==========================================
- Coverage   85.12%   85.06%   -0.06%     
==========================================
  Files         166      166              
  Lines       19238    19240       +2     
==========================================
- Hits        16376    16367       -9     
- Misses       2019     2024       +5     
- Partials      843      849       +6     
Flag Coverage Δ
e2e 52.52% <0.00%> (+0.01%) ⬆️
unit-tests 81.56% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant