@@ -246,6 +246,27 @@ func (r *ReconcileCnsFileAccessConfig) Reconcile(ctx context.Context,
246
246
msg := fmt .Sprintf ("Failed to get virtualmachine instance for the VM with name: %q. Error: %+v" ,
247
247
instance .Spec .VMName , err )
248
248
log .Error (msg )
249
+ // If virtualmachine instance is NotFound and if deletion timestamp is set on CnsFileAccessConfig instance,
250
+ // then proceed with the deletion of CnsFileAccessConfig instance.
251
+ if apierrors .IsNotFound (err ) && instance .DeletionTimestamp != nil {
252
+ log .Infof ("CnsFileAccessConfig instance %q has deletion timestamp set, but VM instance with " +
253
+ "name %q is not found. Processing the deletion of CnsFileAccessConfig instance." ,
254
+ instance .Name , instance .Spec .VMName )
255
+ removeFinalizerFromCRDInstance (ctx , instance )
256
+ err = updateCnsFileAccessConfig (ctx , r .client , instance )
257
+ if err != nil {
258
+ msg := fmt .Sprintf ("failed to update CnsFileAccessConfig instance: %q on namespace: %q. Error: %+v" ,
259
+ instance .Name , instance .Namespace , err )
260
+ recordEvent (ctx , r , instance , v1 .EventTypeWarning , msg )
261
+ return reconcile.Result {RequeueAfter : timeout }, nil
262
+ }
263
+ // Cleanup instance entry from backOffDuration map.
264
+ backOffDurationMapMutex .Lock ()
265
+ delete (backOffDuration , instance .Name )
266
+ backOffDurationMapMutex .Unlock ()
267
+ return reconcile.Result {}, nil
268
+ }
269
+
249
270
setInstanceError (ctx , r , instance , msg )
250
271
return reconcile.Result {RequeueAfter : timeout }, nil
251
272
}
0 commit comments