From e8356b3dfb02147ff50f686747a6f1fa0452f5cb Mon Sep 17 00:00:00 2001 From: youhangwang Date: Wed, 12 Jun 2024 15:36:16 +0800 Subject: [PATCH] add vsInRGD to check if a vs need to be deleted Signed-off-by: youhangwang --- .../cephfscg/replicationgroupdestination.go | 4 +++- controllers/util/cephfs_cg.go | 23 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/controllers/cephfscg/replicationgroupdestination.go b/controllers/cephfscg/replicationgroupdestination.go index 78f28f60c5..28883ac766 100644 --- a/controllers/cephfscg/replicationgroupdestination.go +++ b/controllers/cephfscg/replicationgroupdestination.go @@ -83,7 +83,7 @@ func (m *rgdMachine) Conditions() *[]metav1.Condition { return &m.ReplicationGroupDestination.Status.Conditions } -//nolint:cyclop +//nolint:cyclop,funlen func (m *rgdMachine) Synchronize(ctx context.Context) (mover.Result, error) { createdRDs := []*volsyncv1alpha1.ReplicationDestination{} rds := []*corev1.ObjectReference{} @@ -136,11 +136,13 @@ func (m *rgdMachine) Synchronize(ctx context.Context) (mover.Result, error) { readytoUse, err := m.CheckImagesReadyToUse(ctx, latestImages, m.ReplicationGroupDestination.Namespace) if err != nil { m.Logger.Error(err, "Failed to check if images are ready to use") + return mover.InProgress(), err } if !readytoUse { m.Logger.Error(err, "Images are not ready to use") + return mover.InProgress(), nil } diff --git a/controllers/util/cephfs_cg.go b/controllers/util/cephfs_cg.go index b745f72a0f..f38e7bf853 100644 --- a/controllers/util/cephfs_cg.go +++ b/controllers/util/cephfs_cg.go @@ -23,8 +23,6 @@ import ( ) const ( - ManualStringAnnotaion = "ramendr.openshift.io/manual-string" - // do not delete the vs in a vgs, only for testing SkipDeleteAnnotaion = "rgd.ramendr.openshift.io/do-not-delete" @@ -275,13 +273,6 @@ func DeferDeleteImage(ctx context.Context, labels[RGDOwnerLabel] = rgdName volumeSnapshot.SetLabels(labels) - annotations := volumeSnapshot.GetAnnotations() - if annotations == nil { - annotations = make(map[string]string) - } - annotations[ManualStringAnnotaion] = manual - volumeSnapshot.SetAnnotations(annotations) - return k8sClient.Update(ctx, volumeSnapshot) }) } @@ -304,9 +295,7 @@ func CleanExpiredRDImages(ctx context.Context, continue } - ManualString, ok := vs.Annotations[ManualStringAnnotaion] - if ok && rgd.Status.LastSyncStartTime != nil && - ManualString != rgd.Status.LastSyncStartTime.String() { + if !vsInRGD(vs, rgd) { if err := k8sClient.Delete(ctx, &vsv1.VolumeSnapshot{ ObjectMeta: metav1.ObjectMeta{Name: vs.Name, Namespace: vs.Namespace}, }); err != nil { @@ -317,3 +306,13 @@ func CleanExpiredRDImages(ctx context.Context, return nil } + +func vsInRGD(vs vsv1.VolumeSnapshot, rgd *ramendrv1alpha1.ReplicationGroupDestination) bool { + for _, image := range rgd.Status.LatestImages { + if image.Name == vs.Name { + return true + } + } + + return false +}