@@ -140,6 +140,7 @@ func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.Resourc
140140 log .V (2 ).Info (fmt .Sprintf ("%sing resource" , logMessageVerbPrefix ), "service" , serviceName , "resource" , resourceName , "resourceGroup" , rgName )
141141 result , sdkFuture , err := s .Creator .CreateOrUpdateAsync (ctx , spec , parameters )
142142 errWrapped := errors .Wrapf (err , fmt .Sprintf ("failed to %se resource %s/%s (service: %s)" , logMessageVerbPrefix , rgName , resourceName , serviceName ))
143+
143144 if sdkFuture != nil {
144145 future , err := converters .SDKToFuture (sdkFuture , infrav1 .PutFuture , serviceName , resourceName , rgName )
145146 if err != nil {
@@ -148,6 +149,11 @@ func (s *Service) CreateOrUpdateResource(ctx context.Context, spec azure.Resourc
148149 s .Scope .SetLongRunningOperationState (future )
149150 return nil , azure .WithTransientError (azure .NewOperationNotDoneError (future ), getRequeueAfterFromFuture (sdkFuture ))
150151 } else if err != nil {
152+ // If it is an intermittent failure with context deadline exceeded or canceled as the reconciler could not complete
153+ // in the max amount of time, mark it as a transient error and return.
154+ if azure .IsContextDeadlineExceededOrCanceledError (ctx .Err ()) {
155+ return nil , azure .WithTransientError (errWrapped , getRetryAfterFromError (err ))
156+ }
151157 return nil , errWrapped
152158 }
153159
@@ -174,6 +180,7 @@ func (s *Service) DeleteResource(ctx context.Context, spec azure.ResourceSpecGet
174180 // No long running operation is active, so delete the resource.
175181 log .V (2 ).Info ("deleting resource" , "service" , serviceName , "resource" , resourceName , "resourceGroup" , rgName )
176182 sdkFuture , err := s .Deleter .DeleteAsync (ctx , spec )
183+
177184 if sdkFuture != nil {
178185 future , err := converters .SDKToFuture (sdkFuture , infrav1 .DeleteFuture , serviceName , resourceName , rgName )
179186 if err != nil {
@@ -186,6 +193,11 @@ func (s *Service) DeleteResource(ctx context.Context, spec azure.ResourceSpecGet
186193 // already deleted
187194 return nil
188195 }
196+ // If it is an intermittent failure with context deadline exceeded or canceled as the reconciler could not complete
197+ // in the max amount of time, mark it as a transient error and return.
198+ if azure .IsContextDeadlineExceededOrCanceledError (ctx .Err ()) {
199+ return azure .WithTransientError (err , getRetryAfterFromError (err ))
200+ }
189201 return errors .Wrapf (err , "failed to delete resource %s/%s (service: %s)" , rgName , resourceName , serviceName )
190202 }
191203
0 commit comments