@@ -41,6 +41,7 @@ import (
4141 "k8s.io/client-go/kubernetes"
4242 "k8s.io/client-go/tools/cache"
4343 "k8s.io/client-go/util/workqueue"
44+ "k8s.io/utils/ptr"
4445
4546 commitclient "github.com/argoproj/argo-cd/v3/commitserver/apiclient"
4647 "github.com/argoproj/argo-cd/v3/common"
@@ -2244,20 +2245,22 @@ func (ctrl *ApplicationController) shouldSelfHeal(app *appv1.Application, alread
22442245 return true , time .Duration (0 )
22452246 }
22462247
2247- timeSinceOperation := time .Since (app .Status .OperationState .FinishedAt .Time )
2248+ var timeSinceOperation * time.Duration
2249+ if app .Status .OperationState .FinishedAt != nil {
2250+ timeSinceOperation = ptr .To (time .Since (app .Status .OperationState .FinishedAt .Time ))
2251+ }
22482252
22492253 // Reset counter if the prior sync was successful and the cooldown period is over OR if the revision has changed
2250- if ! alreadyAttempted || (len (app .Status .History ) > 0 && timeSinceOperation >= ctrl .selfHealBackoffCooldown && app .Status .Sync .Status == appv1 .SyncStatusCodeSynced ) {
2251- log .Printf ("Resetting self-heal attempts count for %s/%s" , app .Namespace , app .Name )
2254+ if ! alreadyAttempted || (timeSinceOperation != nil && * timeSinceOperation >= ctrl .selfHealBackoffCooldown && app .Status .Sync .Status == appv1 .SyncStatusCodeSynced ) {
22522255 app .Status .OperationState .Operation .Sync .SelfHealAttemptsCount = 0
22532256 }
22542257
22552258 var retryAfter time.Duration
22562259 if ctrl .selfHealBackOff == nil {
2257- if app . Status . OperationState . FinishedAt == nil {
2260+ if timeSinceOperation == nil {
22582261 retryAfter = ctrl .selfHealTimeout
22592262 } else {
2260- retryAfter = ctrl .selfHealTimeout - timeSinceOperation
2263+ retryAfter = ctrl .selfHealTimeout - * timeSinceOperation
22612264 }
22622265 } else {
22632266 backOff := * ctrl .selfHealBackOff
@@ -2267,10 +2270,11 @@ func (ctrl *ApplicationController) shouldSelfHeal(app *appv1.Application, alread
22672270 for i := 0 ; i < steps ; i ++ {
22682271 delay = backOff .Step ()
22692272 }
2270- if app .Status .OperationState .FinishedAt == nil {
2273+
2274+ if timeSinceOperation == nil {
22712275 retryAfter = delay
22722276 } else {
2273- retryAfter = delay - timeSinceOperation
2277+ retryAfter = delay - * timeSinceOperation
22742278 }
22752279 }
22762280 return retryAfter <= 0 , retryAfter
0 commit comments