Skip to content

Commit ef1bf8b

Browse files
Nikhil-Ladhamergify[bot]
authored andcommitted
check vgrcontent before removing finalizer
we should check if vgrcontent is present before trying to remove finalizer. It is possible that it might have been already deleted in a previous reconcile loop. Signed-off-by: Nikhil-Ladha <[email protected]>
1 parent fda94db commit ef1bf8b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

internal/controller/replication.storage/volumereplication_controller.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re
173173
vgr, vgrc, vgrErr = r.getVolumeGroupReplicationDataSource(logger, nameSpacedName)
174174
if vgrErr != nil {
175175
if errors.IsNotFound(vgrErr) && !instance.DeletionTimestamp.IsZero() {
176-
logger.Info("volumeGroupReplication resource not found, as volumeReplication resource is getting garbage collected")
176+
logger.Info("volumeGroupReplicationContent resource not found, as volumeReplication resource is getting garbage collected")
177177
break
178178
}
179179
logger.Error(vgrErr, "failed to get VolumeGroupReplication", "VGRName", instance.Spec.DataSource.Name)
@@ -278,9 +278,14 @@ func (r *VolumeReplicationReconciler) Reconcile(ctx context.Context, req ctrl.Re
278278
return reconcile.Result{}, err
279279
}
280280
case volumeGroupReplicationDataSource:
281-
if err = removeFinalizerFromVGRContent(r.Client, logger, vgrc, volumeReplicationFinalizer); err != nil {
282-
logger.Error(err, "Failed to remove VolumeReplication finalizer from VolumeGroupReplicationContent resource")
283-
return reconcile.Result{}, err
281+
// It is possible that the VGRContent has already been deleted
282+
// as the finalizer was removed in a previous reconcile loop,
283+
// and this is a reconcile that happened after that deletion.
284+
if vgrc != nil {
285+
if err = removeFinalizerFromVGRContent(r.Client, logger, vgrc, volumeReplicationFinalizer); err != nil {
286+
logger.Error(err, "Failed to remove VolumeReplication finalizer from VolumeGroupReplicationContent resource")
287+
return reconcile.Result{}, err
288+
}
284289
}
285290

286291
err = r.removeOwnerFromVGRAnnotation(ctx, logger, vgr)
@@ -822,7 +827,7 @@ func (r *VolumeReplicationReconciler) getVolumeGroupReplicationDataSource(logger
822827
if vgrcName == "" {
823828
logger.Error(err, "VolumeGroupReplicationContentName is empty", "VolumeGroupReplication Name", req.Name)
824829

825-
return nil, nil, stderrors.New("VolumeGroupReplicationContentName is empty")
830+
return volumeGroupReplication, nil, stderrors.New("VolumeGroupReplicationContentName is empty")
826831
}
827832

828833
vgrcReq := types.NamespacedName{Name: vgrcName}
@@ -833,7 +838,7 @@ func (r *VolumeReplicationReconciler) getVolumeGroupReplicationDataSource(logger
833838
logger.Error(err, "VolumeGroupReplicationContent not found", "VolumeGroupReplicationContent Name", vgrcName)
834839
}
835840

836-
return nil, nil, err
841+
return volumeGroupReplication, nil, err
837842
}
838843

839844
return volumeGroupReplication, volumeGroupReplicationContent, nil

0 commit comments

Comments
 (0)