Skip to content

Commit

Permalink
delete lrd&lrs
Browse files Browse the repository at this point in the history
Signed-off-by: youhangwang <[email protected]>
  • Loading branch information
youhangwang committed Jun 11, 2024
1 parent aecdc37 commit 6c4f602
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
8 changes: 8 additions & 0 deletions controllers/cephfscg/replicationgroupdestination.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (m *rgdMachine) Conditions() *[]metav1.Condition {
return &m.ReplicationGroupDestination.Status.Conditions
}

//nolint:cyclop
func (m *rgdMachine) Synchronize(ctx context.Context) (mover.Result, error) {
createdRDs := []*volsyncv1alpha1.ReplicationDestination{}
rds := []*corev1.ObjectReference{}
Expand All @@ -93,6 +94,13 @@ func (m *rgdMachine) Synchronize(ctx context.Context) (mover.Result, error) {
return mover.InProgress(), fmt.Errorf("failed to create replication destination: %w", err)
}

if rd == nil {
m.Logger.Info(fmt.Sprintf("ReplicationDestination for %s is not ready. We'll retry...",
rdSpec.ProtectedPVC.Name))

return mover.InProgress(), nil
}

createdRDs = append(createdRDs, rd)
rds = append(
rds,
Expand Down
14 changes: 7 additions & 7 deletions controllers/volsync/vshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ func (v *VSHandler) DeleteRD(pvcName string) error {

if rd.GetName() == getReplicationDestinationName(pvcName) {
if v.IsCopyMethodDirect() {
err := v.deleteLocalRDAndRS(&rd)
err := v.DeleteLocalRDAndRS(&rd)
if err != nil {
return err
}
Expand All @@ -768,8 +768,8 @@ func (v *VSHandler) DeleteRD(pvcName string) error {
}

//nolint:gocognit
func (v *VSHandler) deleteLocalRDAndRS(rd *volsyncv1alpha1.ReplicationDestination) error {
latestRDImage, err := v.getRDLatestImage(rd.GetName(), rd.GetNamespace())
func (v *VSHandler) DeleteLocalRDAndRS(rd *volsyncv1alpha1.ReplicationDestination) error {
latestRDImage, err := v.GetRDLatestImage(rd.GetName(), rd.GetNamespace())
if err != nil {
return err
}
Expand Down Expand Up @@ -941,7 +941,7 @@ func (v *VSHandler) listByOwner(list client.ObjectList) error {

func (v *VSHandler) EnsurePVCfromRD(rdSpec ramendrv1alpha1.VolSyncReplicationDestinationSpec, failoverAction bool,
) error {
latestImage, err := v.getRDLatestImage(rdSpec.ProtectedPVC.Name, rdSpec.ProtectedPVC.Namespace)
latestImage, err := v.GetRDLatestImage(rdSpec.ProtectedPVC.Name, rdSpec.ProtectedPVC.Namespace)
if err != nil {
return err
}
Expand Down Expand Up @@ -1603,7 +1603,7 @@ func isRSLastSyncTimeReady(rsStatus *volsyncv1alpha1.ReplicationSourceStatus) bo
return false
}

func (v *VSHandler) getRDLatestImage(pvcName, pvcNamespace string) (*corev1.TypedLocalObjectReference, error) {
func (v *VSHandler) GetRDLatestImage(pvcName, pvcNamespace string) (*corev1.TypedLocalObjectReference, error) {
rd, err := v.getRD(pvcName, pvcNamespace)
if err != nil || rd == nil {
return nil, err
Expand All @@ -1619,7 +1619,7 @@ func (v *VSHandler) getRDLatestImage(pvcName, pvcNamespace string) (*corev1.Type

// Returns true if at least one sync has completed (we'll consider this "data protected")
func (v *VSHandler) IsRDDataProtected(pvcName, pvcNamespace string) (bool, error) {
latestImage, err := v.getRDLatestImage(pvcName, pvcNamespace)
latestImage, err := v.GetRDLatestImage(pvcName, pvcNamespace)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -1943,7 +1943,7 @@ func (v *VSHandler) deleteLocalRD(lrdName, lrdNamespace string) error {

func (v *VSHandler) setupLocalRS(rd *volsyncv1alpha1.ReplicationDestination,
) (*corev1.PersistentVolumeClaim, error) {
latestImage, err := v.getRDLatestImage(rd.GetName(), rd.GetNamespace())
latestImage, err := v.GetRDLatestImage(rd.GetName(), rd.GetNamespace())
if err != nil {
return nil, err
}
Expand Down
24 changes: 23 additions & 1 deletion controllers/vrg_volsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"
"strings"

"github.com/backube/volsync/api/v1alpha1"
"github.com/go-logr/logr"
ramendrv1alpha1 "github.com/ramendr/ramen/api/v1alpha1"
"github.com/ramendr/ramen/controllers/cephfscg"
Expand Down Expand Up @@ -126,7 +127,7 @@ func (v *VRGInstance) reconcileVolSyncAsPrimary(finalSyncPrepared *bool) (requeu
return requeue
}

//nolint:gocognit,funlen,cyclop
//nolint:gocognit,funlen,cyclop,gocyclo,nestif
func (v *VRGInstance) reconcilePVCAsVolSyncPrimary(pvc corev1.PersistentVolumeClaim) (requeue bool) {
newProtectedPVC := &ramendrv1alpha1.ProtectedPVC{
Name: pvc.Name,
Expand Down Expand Up @@ -165,6 +166,27 @@ func (v *VRGInstance) reconcilePVCAsVolSyncPrimary(pvc corev1.PersistentVolumeCl
if err != nil {
return true
} else if pvcInCephfsCg {
latestRDImage, err := v.volSyncHandler.GetRDLatestImage(rsSpec.ProtectedPVC.Name, rsSpec.ProtectedPVC.Namespace)
if err != nil {
return true
}

if latestRDImage != nil {
// Before creating a new RGS, make sure any LocalReplicationDestination for this PVC is cleaned up first
// DeleteRD only delete LRD&LRS here, as only the lrd&lrs have vrg owner and also belongs a CG
err = v.volSyncHandler.DeleteLocalRDAndRS(
&v1alpha1.ReplicationDestination{
ObjectMeta: metav1.ObjectMeta{
Name: rsSpec.ProtectedPVC.Name,
Namespace: rsSpec.ProtectedPVC.Namespace,
},
},
)
if err != nil {
return true
}
}

volumeGroupSnapshotClassName, err := util.GetVolumeGroupSnapshotClassFromPVCsStorageClass(
v.ctx, v.reconciler.Client, v.instance.Spec.Async.VolumeGroupSnapshotClassSelector,
v.instance.Spec.CephFSConsistencyGroupSelector, v.instance.Namespace, v.log,
Expand Down

0 comments on commit 6c4f602

Please sign in to comment.