Skip to content

Commit

Permalink
remove all localrd and localrs
Browse files Browse the repository at this point in the history
Signed-off-by: youhangwang <[email protected]>
  • Loading branch information
youhangwang committed Jun 13, 2024
1 parent 0f4cf57 commit 7619882
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
46 changes: 21 additions & 25 deletions controllers/cephfscg/cghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,16 @@ type VSCGHandler interface {
) (*ramendrv1alpha1.ReplicationGroupDestination, error)

CreateOrUpdateReplicationGroupSource(
rsSpec ramendrv1alpha1.VolSyncReplicationSourceSpec,
replicationGroupSourceName, replicationGroupSourceNamespace string,
runFinalSync bool,
) (*ramendrv1alpha1.ReplicationGroupSource, bool, error)

GetLatestImageFromRGD(
ctx context.Context, rdSpec ramendrv1alpha1.VolSyncReplicationDestinationSpec,
ctx context.Context, pvcName string,
) (*corev1.TypedLocalObjectReference, error)

EnsurePVCfromRGD(rdSpec ramendrv1alpha1.VolSyncReplicationDestinationSpec, failoverAction bool) error
DeleteLocalRDAndRS(rdSpec ramendrv1alpha1.VolSyncReplicationDestinationSpec) error
DeleteLocalRDAndRS(rd *volsyncv1alpha1.ReplicationDestination) error
GetRDInCG() ([]ramendrv1alpha1.VolSyncReplicationDestinationSpec, error)
}

Expand Down Expand Up @@ -119,7 +118,6 @@ func (c *cgHandler) CreateOrUpdateReplicationGroupDestination(

//nolint:funlen,gocognit,cyclop,gocyclo
func (c *cgHandler) CreateOrUpdateReplicationGroupSource(
rsSpec ramendrv1alpha1.VolSyncReplicationSourceSpec,
replicationGroupSourceName, replicationGroupSourceNamespace string,
runFinalSync bool,
) (*ramendrv1alpha1.ReplicationGroupSource, bool, error) {
Expand All @@ -133,14 +131,12 @@ func (c *cgHandler) CreateOrUpdateReplicationGroupSource(

for i := range rdList.Items {
rd := rdList.Items[i]
if rd.GetName() == getReplicationDestinationName(rsSpec.ProtectedPVC.Name) {
if c.VSHandler.IsCopyMethodDirect() {
// 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 := c.DeleteLocalRDAndRS(ramendrv1alpha1.VolSyncReplicationDestinationSpec(rsSpec))
if err != nil {
return nil, false, err
}
if c.VSHandler.IsCopyMethodDirect() {
// 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 := c.DeleteLocalRDAndRS(&rd)
if err != nil {
return nil, false, err
}
}
}
Expand Down Expand Up @@ -223,7 +219,7 @@ func (c *cgHandler) CreateOrUpdateReplicationGroupSource(
}

func (c *cgHandler) GetLatestImageFromRGD(
ctx context.Context, rdSpec ramendrv1alpha1.VolSyncReplicationDestinationSpec,
ctx context.Context, pvcName string,
) (*corev1.TypedLocalObjectReference, error) {
rgdList := &ramendrv1alpha1.ReplicationGroupDestinationList{}

Expand All @@ -237,14 +233,14 @@ func (c *cgHandler) GetLatestImageFromRGD(
var latestImage *corev1.TypedLocalObjectReference

for _, rgd := range rgdList.Items {
if util.GetPVCLatestImageRGD(rdSpec.ProtectedPVC.Name, rgd) != nil {
latestImage = util.GetPVCLatestImageRGD(rdSpec.ProtectedPVC.Name, rgd)
if util.GetPVCLatestImageRGD(pvcName, rgd) != nil {
latestImage = util.GetPVCLatestImageRGD(pvcName, rgd)
}
}

if !isLatestImageReady(latestImage) {
noSnapErr := fmt.Errorf("unable to find LatestImage from ReplicationDestination %s", rdSpec.ProtectedPVC.Name)
c.logger.Error(noSnapErr, "No latestImage", "rdSpec", rdSpec)
noSnapErr := fmt.Errorf("unable to find LatestImage from ReplicationDestination %s", pvcName)
c.logger.Error(noSnapErr, "No latestImage", "rd", pvcName)

return nil, noSnapErr
}
Expand All @@ -255,7 +251,7 @@ func (c *cgHandler) GetLatestImageFromRGD(
func (c *cgHandler) EnsurePVCfromRGD(
rdSpec ramendrv1alpha1.VolSyncReplicationDestinationSpec, failoverAction bool,
) error {
latestImage, err := c.GetLatestImageFromRGD(c.ctx, rdSpec)
latestImage, err := c.GetLatestImageFromRGD(c.ctx, rdSpec.ProtectedPVC.Name)
if err != nil {
return err
}
Expand All @@ -273,8 +269,8 @@ func (c *cgHandler) EnsurePVCfromRGD(
}

//nolint:gocognit
func (c *cgHandler) DeleteLocalRDAndRS(rdSpec ramendrv1alpha1.VolSyncReplicationDestinationSpec) error {
latestRDImage, err := c.GetLatestImageFromRGD(c.ctx, rdSpec)
func (c *cgHandler) DeleteLocalRDAndRS(rd *volsyncv1alpha1.ReplicationDestination) error {
latestRDImage, err := c.GetLatestImageFromRGD(c.ctx, rd.Name)
if err != nil {
return err
}
Expand All @@ -283,8 +279,8 @@ func (c *cgHandler) DeleteLocalRDAndRS(rdSpec ramendrv1alpha1.VolSyncReplication

lrs := &volsyncv1alpha1.ReplicationSource{
ObjectMeta: metav1.ObjectMeta{
Name: getLocalReplicationName(rdSpec.ProtectedPVC.Name),
Namespace: rdSpec.ProtectedPVC.Namespace,
Name: getLocalReplicationName(rd.Name),
Namespace: rd.Namespace,
},
}

Expand All @@ -295,8 +291,8 @@ func (c *cgHandler) DeleteLocalRDAndRS(rdSpec ramendrv1alpha1.VolSyncReplication
if err != nil {
if errors.IsNotFound(err) {
return c.VSHandler.DeleteLocalRD(
getLocalReplicationName(rdSpec.ProtectedPVC.Name),
rdSpec.ProtectedPVC.Namespace,
getLocalReplicationName(rd.Name),
rd.Namespace,
)
}

Expand All @@ -313,7 +309,7 @@ func (c *cgHandler) DeleteLocalRDAndRS(rdSpec ramendrv1alpha1.VolSyncReplication
return err
}

c.logger.Info("Cleaned up local resources for RD", "name", rdSpec.ProtectedPVC.Name)
c.logger.Info("Cleaned up local resources for RD", "name", rd.Name)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/vrg_volsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (v *VRGInstance) reconcilePVCAsVolSyncPrimary(pvc corev1.PersistentVolumeCl
return true
} else if pvcInCephfsCg {
rgs, finalSyncComplete, err := v.cephfsCGHandler.CreateOrUpdateReplicationGroupSource(
rsSpec, v.instance.Name, v.instance.Namespace, v.instance.Spec.RunFinalSync,
v.instance.Name, v.instance.Namespace, v.instance.Spec.RunFinalSync,
)
if err != nil {
setVRGConditionTypeVolSyncRepSourceSetupError(&protectedPVC.Conditions, v.instance.Generation,
Expand Down

0 comments on commit 7619882

Please sign in to comment.