argoproj / argo-rollouts

Progressive Delivery for Kubernetes
https://argo-rollouts.readthedocs.io/
Apache License 2.0
2.79k stars 873 forks source link

Panic due to division by zero in CalculateDesiredWeightOnAbortOrStableRollback #3814

Open FredrikAugust opened 3 months ago

FredrikAugust commented 3 months ago

https://github.com/argoproj/argo-rollouts/blob/bfef7f0d2bb71b085398c35ec95c1b2aacd07187/rollout/trafficrouting.go#L314

Logs:

│ time="2024-08-29T14:26:36Z" level=error msg="Recovered from panic: runtime error: integer divide by zero\ngoroutine 489 [running]:\nruntime/debug.Stack()\n\t/usr/local/go/src/runtime/debug/stack.go:24 +0x5e\ngithub.com/argoproj/argo-rollouts/utils/controller.processNext │
│ WorkItem.func1.1.1()\n\t/go/src/github.com/argoproj/argo-rollouts/utils/controller/controller.go:151 +0x49\npanic({0x2c65f20?, 0x5358650?})\n\t/usr/local/go/src/runtime/panic.go:914 +0x21f\ngithub.com/argoproj/argo-rollouts/rollout.(*rolloutContext).calculateDesiredWeig │
│ htOnAbortOrStableRollback(0xc001e06000?)\n\t/go/src/github.com/argoproj/argo-rollouts/rollout/trafficrouting.go:314 +0xb1\ngithub.com/argoproj/argo-rollouts/rollout.(*rolloutContext).reconcileTrafficRouting(0xc001e16000)\n\t/go/src/github.com/argoproj/argo-rollouts/roll │
│ out/trafficrouting.go:181 +0x425\ngithub.com/argoproj/argo-rollouts/rollout.(*rolloutContext).rolloutCanary(0xc001e16000)\n\t/go/src/github.com/argoproj/argo-rollouts/rollout/canary.go:57 +0x1d3\ngithub.com/argoproj/argo-rollouts/rollout.(*rolloutContext).reconcile(0xc0 │
│ 01e16000)\n\t/go/src/github.com/argoproj/argo-rollouts/rollout/context.go:86 +0xd4\ngithub.com/argoproj/argo-rollouts/rollout.(*Controller).syncHandler(0xc0007d8e00, {0x3944730, 0xc0007efb30}, {0xc0015f0fd8, 0x12})\n\t/go/src/github.com/argoproj/argo-rollouts/rollout/co │
│ ntroller.go:437 +0x4d3\ngithub.com/argoproj/argo-rollouts/utils/controller.processNextWorkItem.func1.1()\n\t/go/src/github.com/argoproj/argo-rollouts/utils/controller/controller.go:155 +0x7d\ngithub.com/argoproj/argo-rollouts/utils/controller.processNextWorkItem.func1({ │
│ 0x39574b0?, 0xc00069e420}, {0x31bf658, 0x7}, 0xc001449e70, {0x3944730?, 0xc0007efb30}, 0xc00062dc20?, {0x2a9bfa0, 0xc000de27b0})\n\t/go/src/github.com/argoproj/argo-rollouts/utils/controller/controller.go:159 +0x3ed\ngithub.com/argoproj/argo-rollouts/utils/controller.pr │
│ ocessNextWorkItem({0x3944730, 0xc0007efb30}, {0x39574b0, 0xc00069e420}, {0x31bf658, 0x7}, 0x0?, 0xc0017ca490?)\n\t/go/src/github.com/argoproj/argo-rollouts/utils/controller/controller.go:178 +0xb5\ngithub.com/argoproj/argo-rollouts/utils/controller.RunWorker(...)\n\t/go │
│ /src/github.com/argoproj/argo-rollouts/utils/controller/controller.go:106\ngithub.com/argoproj/argo-rollouts/rollout.(*Controller).Run.func1()\n\t/go/src/github.com/argoproj/argo-rollouts/rollout/controller.go:358 +0xb2\nk8s.io/apimachinery/pkg/util/wait.BackoffUntil.fu │
│ nc1(0x30?)\n\t/go/pkg/mod/k8s.io/apimachinery@v0.29.3/pkg/util/wait/backoff.go:226 +0x33\nk8s.io/apimachinery/pkg/util/wait.BackoffUntil(0x0?, {0x3912c00, 0xc0010e0f60}, 0x1, 0xc000dc4180)\n\t/go/pkg/mod/k8s.io/apimachinery@v0.29.3/pkg/util/wait/backoff.go:227 +0xaf\nk8 │
│ s.io/apimachinery/pkg/util/wait.JitterUntil(0x0?, 0x3b9aca00, 0x0, 0x0?, 0x0?)\n\t/go/pkg/mod/k8s.io/apimachinery@v0.29.3/pkg/util/wait/backoff.go:204 +0x7f\nk8s.io/apimachinery/pkg/util/wait.Until(0x0?, 0x0?, 0x0?)\n\t/go/pkg/mod/k8s.io/apimachinery@v0.29.3/pkg/util/wa │
│ it/backoff.go:161 +0x1e\ncreated by github.com/argoproj/argo-rollouts/rollout.(*Controller).Run in goroutine 439\n\t/go/src/github.com/argoproj/argo-rollouts/rollout/controller.go:357 +0xa7\n" namespace=init rollout=init-tracking                                          │

Hi! I believe this line should have a check for if the rollout has 0 replicas to prevent a panic:)

zimmertr commented 1 month ago

Duplicate: https://github.com/argoproj/argo-rollouts/issues/3686