diff --git a/controller/appcontroller.go b/controller/appcontroller.go index 5a48f1d41cb09..b540bc1b2f214 100644 --- a/controller/appcontroller.go +++ b/controller/appcontroller.go @@ -2143,7 +2143,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 { diff --git a/controller/appcontroller_test.go b/controller/appcontroller_test.go index cf2c14c7e0447..93c2a3813d607 100644 --- a/controller/appcontroller_test.go +++ b/controller/appcontroller_test.go @@ -2205,7 +2205,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{ @@ -2243,6 +2243,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 {