Skip to content

Commit

Permalink
fix: Fix calculating SelfHealBackOff delay when exceeding maximum (#2…
Browse files Browse the repository at this point in the history
…0976) (#20978)

* test: fix TestSelfHealExponentialBackoff to test exceeding Backoff.Cap

Signed-off-by: Michal Ryšavý <[email protected]>

* fix: fix calculating SelfHealBackOff delay when exceeding maximum

Signed-off-by: Michal Ryšavý <[email protected]>

---------

Signed-off-by: Michal Ryšavý <[email protected]>
Co-authored-by: Michal Ryšavý <[email protected]>
  • Loading branch information
mrysavy and michalrysavy-ext95730 authored Dec 19, 2024
1 parent 6b57b16 commit 8841b0d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,8 @@ func (ctrl *ApplicationController) shouldSelfHeal(app *appv1.Application) (bool,
backOff := *ctrl.selfHealBackOff
backOff.Steps = int(app.Status.OperationState.Operation.Sync.SelfHealAttemptsCount)
var delay time.Duration
for backOff.Steps > 0 {
steps := backOff.Steps
for i := 0; i < steps; i++ {
delay = backOff.Step()
}
if app.Status.OperationState.FinishedAt == nil {
Expand Down
17 changes: 16 additions & 1 deletion controller/appcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ func TestSelfHealExponentialBackoff(t *testing.T) {
ctrl.selfHealBackOff = &wait.Backoff{
Factor: 3,
Duration: 2 * time.Second,
Cap: 5 * time.Minute,
Cap: 2 * time.Minute,
}

app := &v1alpha1.Application{
Expand Down Expand Up @@ -2552,6 +2552,21 @@ func TestSelfHealExponentialBackoff(t *testing.T) {
finishedAt: nil,
expectedDuration: 18 * time.Second,
shouldSelfHeal: false,
}, {
attempts: 4,
finishedAt: nil,
expectedDuration: 54 * time.Second,
shouldSelfHeal: false,
}, {
attempts: 5,
finishedAt: nil,
expectedDuration: 120 * time.Second,
shouldSelfHeal: false,
}, {
attempts: 6,
finishedAt: nil,
expectedDuration: 120 * time.Second,
shouldSelfHeal: false,
}}

for i := range testCases {
Expand Down

0 comments on commit 8841b0d

Please sign in to comment.