Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vrg: cleanup rd when vrg is secondary #1738

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

raghavendra-talur
Copy link
Member

In processForDeletion, we cleanup the resources that are related to volsync. It relies on v.volSyncPVCs but the list is empty when the vrg is secondary because it is populated by looking at the vrg.status.ProtectedPVCs.

For managed applications, the RD,RS and Snapshots were being as a consequence of the deletion of VRG as the VRG is the owner for them.

In the case of discovered apps, the vrg is not the owner and therefore the RD was being left behind.

@@ -566,5 +566,13 @@ func (v *VRGInstance) cleanupResources() error {
}
}

Copy link
Member

@BenamarMk BenamarMk Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few small comments on this change:

  1. The RD and RS terms in the function comment are misspelled, so this is a good opportunity to correct them.
  2. The object retrieved from volSyncPVCs is an actual PVC, while the one from ProtectedPVC is not. This makes the variable name pvc in the second loop misleading. Ideally, we should have named ProtectedPVC as ProtectedPVCInfo, but it is what it is.
  3. I would modify the function to look like the following, as we want to use the same function calls to delete the three resources in both cases:
func (v *VRGInstance) cleanupResources() error {
	for idx := range v.volSyncPVCs {
		pvc := &v.volSyncPVCs[idx]

		if err := v.doCleanupResources(pvc.Name, pvc.Namespace); err != nil {
			return err
		}
	}

	for idx := range v.instance.Spec.VolSync.RDSpec {
		protectedPVC := v.instance.Spec.VolSync.RDSpec[idx].ProtectedPVC

		if err := v.doCleanupResources(protectedPVC.Name, protectedPVC.Namespace); err != nil {
			return err
		}
	}

	return nil
}

func (v *VRGInstance) doCleanupResources(name, namespace string) error {
	if err := v.volSyncHandler.DeleteRS(name, namespace); err != nil {
		return err
	}

	if err := v.volSyncHandler.DeleteRD(name, namespace); err != nil {
		return err
	}

	if err := v.volSyncHandler.DeleteSnapshots(namespace); err != nil {
		return err
	}

	return nil
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Updated as suggested!

raghavendra-talur and others added 4 commits January 10, 2025 10:14
In processForDeletion, we cleanup the resources that are related to
volsync. It relies on v.volSyncPVCs but the list is empty when the vrg
is secondary because it is populated by looking at the
vrg.status.ProtectedPVCs.

For managed applications, the RD,RS and Snapshots were being as a
consequence of the deletion of VRG as the VRG is the owner for them.

In the case of discovered apps, the vrg is not the owner and therefore
the RD was being left behind.

Co-Authored-by: Annaraya Narasagond <[email protected]>
Signed-off-by: Raghavendra Talur <[email protected]>
Co-Authored-by: Annaraya Narasagond <[email protected]>
Signed-off-by: Raghavendra Talur <[email protected]>
if-return has been removed from the default list of revive for a valid
reason. See the argument in mgechev/revive#843.

Comparing two snippets

1.
```
if err := v.volSyncHandler.DeleteRS(name, namespace); err != nil {
	return err
}

if err := v.volSyncHandler.DeleteRD(name, namespace); err != nil {
	return err
}

if err := v.volSyncHandler.DeleteSnapshots(namespace); err != nil {
	return err
}

return nil
```

2.
```
if err := v.volSyncHandler.DeleteRS(name, namespace); err != nil {
	return err
}

if err := v.volSyncHandler.DeleteRD(name, namespace); err != nil {
	return err
}

return v.volSyncHandler.DeleteSnapshots(namespace)
```

1 is a lot easier to read compared to 2 but if-return throws an error
for it.

Signed-off-by: Raghavendra Talur <[email protected]>
Signed-off-by: Raghavendra Talur <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants