From 021c6d76ab083e9642b20762bc8900cbe366e9b6 Mon Sep 17 00:00:00 2001 From: Benamar Mekhissi Date: Wed, 18 Dec 2024 02:42:36 -0500 Subject: [PATCH] Delay temporary PVC creation until scheduled time on fresh deploy For consistency groups, temporary PVCs will now be created at the scheduled time rather than immediately upon fresh deployment. Signed-off-by: Benamar Mekhissi --- .../cephfscg/replicationgroupsource.go | 18 +++++++++--------- .../cephfscg/volumegroupsourcehandler.go | 4 ++-- internal/controller/vrg_volrep.go | 4 ++-- internal/controller/vrg_volsync.go | 6 ++++++ 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/internal/controller/cephfscg/replicationgroupsource.go b/internal/controller/cephfscg/replicationgroupsource.go index 477d3fbc3..d217d0e1d 100644 --- a/internal/controller/cephfscg/replicationgroupsource.go +++ b/internal/controller/cephfscg/replicationgroupsource.go @@ -113,15 +113,6 @@ func (m *replicationGroupSourceMachine) Synchronize(ctx context.Context) (mover. return mover.InProgress(), err } - m.Logger.Info("Restore PVCs from volume group snapshot") - - restoredPVCs, err := m.VolumeGroupHandler.RestoreVolumesFromVolumeGroupSnapshot(ctx, m.ReplicationGroupSource) - if err != nil { - m.Logger.Error(err, "Failed to restore volume group snapshot") - - return mover.InProgress(), err - } - m.Logger.Info("Create ReplicationSource for each Restored PVC") vrgName := m.ReplicationGroupSource.GetLabels()[volsync.VRGOwnerNameLabel] // Pre-allocated shared secret - DRPC will generate and propagate this secret from hub to clusters @@ -141,6 +132,15 @@ func (m *replicationGroupSourceMachine) Synchronize(ctx context.Context) (mover. return mover.InProgress(), nil } + m.Logger.Info("Restore PVCs from volume group snapshot") + + restoredPVCs, err := m.VolumeGroupHandler.RestoreVolumesFromVolumeGroupSnapshot(ctx, m.ReplicationGroupSource) + if err != nil { + m.Logger.Error(err, "Failed to restore volume group snapshot") + + return mover.InProgress(), err + } + replicationSources, err := m.VolumeGroupHandler.CreateOrUpdateReplicationSourceForRestoredPVCs( ctx, m.ReplicationGroupSource.Status.LastSyncStartTime.String(), restoredPVCs, m.ReplicationGroupSource) if err != nil { diff --git a/internal/controller/cephfscg/volumegroupsourcehandler.go b/internal/controller/cephfscg/volumegroupsourcehandler.go index 0daa9195a..f23cb1575 100644 --- a/internal/controller/cephfscg/volumegroupsourcehandler.go +++ b/internal/controller/cephfscg/volumegroupsourcehandler.go @@ -26,8 +26,8 @@ import ( ) var ( - VolumeGroupSnapshotNameFormat = "cephfscg-%s" - RestorePVCinCGNameFormat = "cephfscg-%s" + VolumeGroupSnapshotNameFormat = "vs-cg-%s" + RestorePVCinCGNameFormat = "vs-cg-%s" SnapshotGroup = "snapshot.storage.k8s.io" SnapshotGroupKind = "VolumeSnapshot" ) diff --git a/internal/controller/vrg_volrep.go b/internal/controller/vrg_volrep.go index 1bdbdf236..1c7d67546 100644 --- a/internal/controller/vrg_volrep.go +++ b/internal/controller/vrg_volrep.go @@ -437,7 +437,7 @@ func (v *VRGInstance) protectPVC(pvc *corev1.PersistentVolumeClaim, log logr.Log // any further and it can be skipped. The pvc will go away eventually. func skipPVC(pvc *corev1.PersistentVolumeClaim, log logr.Logger) (bool, string) { if pvc.Status.Phase != corev1.ClaimBound { - log.Info("Skipping handling of VR as PersistentVolumeClaim is not bound", "pvcPhase", pvc.Status.Phase) + log.Info("Skipping handling of VR as PVC is not bound", "pvcPhase", pvc.Status.Phase) msg := "PVC not bound yet" // v.updateProtectedPVCCondition(pvc.Name, VRGConditionReasonProgressing, msg) @@ -451,7 +451,7 @@ func skipPVC(pvc *corev1.PersistentVolumeClaim, log logr.Logger) (bool, string) func isPVCDeletedAndNotProtected(pvc *corev1.PersistentVolumeClaim, log logr.Logger) (bool, string) { // If PVC deleted but not yet protected with a finalizer, skip it! if !containsString(pvc.Finalizers, PvcVRFinalizerProtected) && rmnutil.ResourceIsDeleted(pvc) { - log.Info("Skipping PersistentVolumeClaim, as it is marked for deletion and not yet protected") + log.Info("Skipping PVC, as it is marked for deletion and not yet protected") msg := "Skipping pvc marked for deletion" // v.updateProtectedPVCCondition(pvc.Name, VRGConditionReasonProgressing, msg) diff --git a/internal/controller/vrg_volsync.go b/internal/controller/vrg_volsync.go index 2f7b107f7..500abee86 100644 --- a/internal/controller/vrg_volsync.go +++ b/internal/controller/vrg_volsync.go @@ -113,6 +113,12 @@ func (v *VRGInstance) reconcileVolSyncAsPrimary(finalSyncPrepared *bool) (requeu } for _, pvc := range v.volSyncPVCs { + if pvc.Status.Phase != corev1.ClaimBound { + v.log.Info("Skipping PVC - PVC is not Bound.", "name", pvc.GetName()) + + continue + } + requeuePVC := v.reconcilePVCAsVolSyncPrimary(pvc) if requeuePVC { requeue = true