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
base: main
Are you sure you want to change the base?
Conversation
797db48
to
50c9cdd
Compare
There was a problem hiding this 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" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
controllers/vrg_volrep.go
Outdated
| @@ -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 { | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
controllers/vrg_volrep.go
Outdated
| @@ -1516,6 +1527,7 @@ func (v *VRGInstance) addProtectedAnnotationForPVC(pvc *corev1.PersistentVolumeC | |||
| } | |||
|
|
|||
| pvc.ObjectMeta.Annotations[pvcVRAnnotationProtectedKey] = pvcVRAnnotationProtectedValue | |||
| pvc.ObjectMeta.Annotations[pvcVRAnnotationOwnerKey] = v.instance.Name | |||
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
f211990
to
845cabf
Compare
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>
845cabf
to
d5b9214
Compare
|
Moved it to draft because I am making many forced updates. Will remove from draft status soon. |
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.