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: add vrg owner annotation to pv and pvc #627

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

raghavendra-talur
Copy link
Member

@raghavendra-talur raghavendra-talur commented Nov 21, 2022

Set the vrg owner name annotation to the PV and PVC.

This will be used to detect and prevent multiple owners of the PVC. The
annotation on the PVC is used to detect conflicts. The annotation on the
PV is only for debugging.

@raghavendra-talur raghavendra-talur changed the title vrg: add vrg owner annotation to pv vrg: add vrg owner annotation to pv and pvc Nov 21, 2022
@raghavendra-talur raghavendra-talur requested review from BenamarMk and ShyamsundarR and removed request for BenamarMk November 21, 2022 16:54
Copy link
Member

@ShyamsundarR ShyamsundarR left a comment

Choose a reason for hiding this comment

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

I think overall we need to do the following:

  • Detect a VRG conflicts with another in the same namespace with the same label selector (across MetroDR, volsync and VolRep)
  • Let only one VRG reconcile if there is a collision
  • The other VRG should have a broader error reported in the summary status (DataReady)

I suggest we use locks, mapping them to a map with key based on --. This will ensure only one VRG is reconciled at a time, and serialize the conflict checks in the code (PVC ownership).

There would be an additional case where a new PVC is created, and in this case we potentially want the VRG that protected the data to succeed and not the VRG that went second/later. This needs to be resolved post locking to ensure PVCs that need protection are owned by the current VRG before further reconciliation.

pvVRAnnotationRetentionKey = "volumereplicationgroups.ramendr.openshift.io/vr-retained"
pvVRAnnotationRetentionValue = "retained"
PVRestoreAnnotation = "volumereplicationgroups.ramendr.openshift.io/ramen-restore"
pvcVRAnnotationOwnerKey = "volumereplicationgroups.ramendr.openshift.io/vrg-name"
Copy link
Member

Choose a reason for hiding this comment

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

(nit) Can fold protected and owner as a single annotation

pvVRAnnotationRetentionKey = "volumereplicationgroups.ramendr.openshift.io/vr-retained"
pvVRAnnotationRetentionValue = "retained"
PVRestoreAnnotation = "volumereplicationgroups.ramendr.openshift.io/ramen-restore"
pvVRAnnotationOwnerKey = "volumereplicationgroups.ramendr.openshift.io/vrg-name"
Copy link
Member

Choose a reason for hiding this comment

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

PV owner is needed for MetroDR? As ownership of PVC is enough to decide not to protect the PVC, the PV should not matter at that point is the assumption.

Copy link
Member Author

Choose a reason for hiding this comment

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

This can be removed. I don't think it is required.

@@ -210,6 +210,17 @@ func (v *VRGInstance) preparePVCForVRProtection(pvc *corev1.PersistentVolumeClai
return !requeue, !skip
}

// if PVC is protected by another VRG, skip this PVC
// there might be PVCs that don't have a conflicting owner
if pvcVRGOwner, found := pvc.Annotations[pvcVRAnnotationOwnerKey]; found {
Copy link
Member

Choose a reason for hiding this comment

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

At this point we have conflicting VRGs and should not allow progression of the reconcile, as PVCs maybe protected by either VRGs as they race in reconciliation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I suggest we use locks, mapping them to a map with key based on --. This will ensure only one VRG is reconciled at a time, and serialize the conflict checks in the code (PVC ownership).

Could you elaborate a bit more on "mapping them to a map with key based on --".

IIUC, this is a lock within the controller. Wouldn't that have an impact the processing time as there could be many VRGs in the system?

Copy link
Member

Choose a reason for hiding this comment

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

The map of locks is this pattern. This will serialize only those reconciles that conflict on the string that is common, and hence other VRG resources would reconcile in parallel.

Looks like I did not add a potential key example, it would be say <namespace>-<label-selector-hash> so that 2 VRGs in the same namespace having the same label selector will not reconcile in parallel.

@@ -1516,6 +1527,7 @@ func (v *VRGInstance) addProtectedAnnotationForPVC(pvc *corev1.PersistentVolumeC
}

pvc.ObjectMeta.Annotations[pvcVRAnnotationProtectedKey] = pvcVRAnnotationProtectedValue
pvc.ObjectMeta.Annotations[pvcVRAnnotationOwnerKey] = v.instance.Name
Copy link
Member

Choose a reason for hiding this comment

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

This will not be added during deletion, which may cause some conflict? (need to analyze)

// if PVC is protected by another VRG, skip this PVC
// there might be PVCs that don't have a conflicting owner
if pvcVRGOwner, found := pvc.Annotations[pvcVRAnnotationOwnerKey]; found {
if pvcVRGOwner != v.instance.Name {
Copy link
Member

Choose a reason for hiding this comment

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

If a PVC is owned by another instance of VRG, then this is an error. We should at least log it as such.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@raghavendra-talur raghavendra-talur force-pushed the rtalur-fix-bug1 branch 3 times, most recently from f211990 to 845cabf Compare December 16, 2022 20:22
Set the vrg owner name annotation to the PV and PVC.

This will be used to detect and prevent multiple owners of the PVC. The
annotation on the PVC is used to detect conflicts. The annotation on the
PV is only for debugging.

Signed-off-by: Raghavendra Talur <raghavendra.talur@gmail.com>
@raghavendra-talur
Copy link
Member Author

Moved it to draft because I am making many forced updates. Will remove from draft status soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

None yet

3 participants