Skip to content

Commit 91af55d

Browse files
committed
Complete deletion of CnsFileAccessConfig instance if associated nodeVM instance is not found
1 parent f666450 commit 91af55d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pkg/syncer/cnsoperator/controller/cnsfileaccessconfig/cnsfileaccessconfig_controller.go

+21
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,27 @@ func (r *ReconcileCnsFileAccessConfig) Reconcile(ctx context.Context,
246246
msg := fmt.Sprintf("Failed to get virtualmachine instance for the VM with name: %q. Error: %+v",
247247
instance.Spec.VMName, err)
248248
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+
249270
setInstanceError(ctx, r, instance, msg)
250271
return reconcile.Result{RequeueAfter: timeout}, nil
251272
}

0 commit comments

Comments
 (0)