-
Notifications
You must be signed in to change notification settings - Fork 39
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
Add volume group replication controller code #610
base: main
Are you sure you want to change the base?
Conversation
The changes are not yet tested, will wait for #605 to get merged and then update a few things and test it. |
f322110
to
10df032
Compare
10df032
to
15b901d
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.
still need to do few more rounds of review, just done it for few files
controllers/replication.storage/volumegroupreplication_controller.go
Outdated
Show resolved
Hide resolved
controllers/replication.storage/volumegroupreplication_controller.go
Outdated
Show resolved
Hide resolved
controllers/replication.storage/volumegroupreplication_controller.go
Outdated
Show resolved
Hide resolved
// Check if the PVC has any labels defined | ||
objLabels := obj.GetLabels() | ||
if len(objLabels) == 0 { | ||
return []reconcile.Request{} |
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.
there can be a case where someone removed the label from the PVC, we need to remove that from the VGR as well.
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.
From what I understand from the docs, the enqueue function would be ran for both the old,new objects in case of update function. So, when the request is ran for older object, the details from the pvc annotation will be fetched and the VGR reconcile request will be enqueued, and since the object is already updated in the cluster the selector won't inlcude that PVC.
Though this is all theoritical, will test it to confirm.
vgrObjsList := &replicationv1alpha1.VolumeGroupReplicationList{} | ||
logger := log.FromContext(context) | ||
err := r.Client.List(context, vgrObjsList) | ||
if err != nil { | ||
logger.Error(err, "failed to list VolumeGroupReplication instances") | ||
return []reconcile.Request{} | ||
} | ||
|
||
// Check if the pvc labels match any VGRs based on selectors present in it's annotation | ||
for _, vgr := range vgrObjsList.Items { | ||
if vgr.Annotations != nil && vgr.Annotations["pvcSelector"] != "" { | ||
labelSelector, err := labels.Parse(vgr.Annotations["pvcSelector"]) | ||
if err != nil { | ||
logger.Error(err, "failed to parse selector from VolumeGroupReplication's annotation") | ||
return []reconcile.Request{} | ||
} | ||
objLabelsSet := labels.Set(objLabels) | ||
if labelSelector.Matches(objLabelsSet) { | ||
return []reconcile.Request{ | ||
{ | ||
NamespacedName: types.NamespacedName{ | ||
Namespace: vgr.Namespace, | ||
Name: vgr.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.
there should be a controller runtime util function for it check something like https://github.com/kubernetes-sigs/controller-runtime/blob/a0c9fd9d3f310f48155ce985366b21914675fbea/pkg/client/example_test.go#L265-L294
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.
Well, I will just update the code to fetch the VGR name from the annotation, since now we are adding the owner annotation to PVC.
EDIT: Ok, can't exactly do that. Since, new PVCs won't be considered then.
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 thing is we can't use a helper function like the one you mentioned is because the selector is not a single field that we can compare or so, and to match labels we need to create a selector requirement as done in the getPVCFromDataSource function.
15b901d
to
6b05893
Compare
0121241
to
8e8830d
Compare
8e8830d
to
fbeb1a7
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.
Can you also add documentation with an example in the docs/
directory? That makes it easier to visualize how things are supposed to work.
4fd2e6a
to
66d017c
Compare
internal/controller/replication.storage/volumegroupreplication_controller.go
Show resolved
Hide resolved
internal/controller/replication.storage/volumegroupreplication_controller.go
Show resolved
Hide resolved
internal/controller/replication.storage/volumegroupreplicationcontent_controller.go
Show resolved
Hide resolved
c208c80
to
cb4b33d
Compare
Nothing blocking, only test results missing.
|
||
"github.com/csi-addons/kubernetes-csi-addons/internal/controller/replication.storage/replication" |
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.
reorganize imports, internal pkgs go last
- Then, create the VR CR and add VGR name/namespace as the annotation to it | ||
- Update the VGR status with the VR status. | ||
|
||
In case of deletion: |
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.
Handle deletion case of object first.
maybe define an instance object like https://github.com/csi-addons/kubernetes-csi-addons/blob/main/internal/controller/replication.storage/volumereplication_controller.go#L616
and then write helper functions with it ?
The reconcile function is >250 lines.
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.
Handle deletion case of object first.
I feel, if we handle deletion first then it becomes a bit arbritary while reading the code to understand what exactly is happening and why. Having it in the end tells the reader that these all operations happened when the CR was created and that's why all these cleanups are needed.
maybe define an instance object like https://github.com/csi-addons/kubernetes-csi-addons/blob/main/internal/controller/replication.storage/volumereplication_controller.go#L616
and then write helper functions with it ?
I don't see any use case of defining such an instance object here, the only helper function here is the getPVCFromDataSource
and it doesn't makes sense to add this extra type for a single function.
The reconcile function is >250 lines.
It's a bit long I agree, but are there any rules defined for the lenght of the reconcile function?
Secondly, the operations that are happening in the reconcile function are very basic and can't be broken into individual helper functions. Those, that can be broken are already done. If you have any suggestions for it, I would be happy to know.
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.
Updated the code to move the creation of CRs into their individual functions.
Now it's < 250 :)
cb4b33d
to
9ad19b0
Compare
Here's the result of creating the VGR:
The CR is created and the dependend CRs i.e, VR and VGRContent created as well
|
There are a few minor conflicts that need to be resolved. Is there a way to set the |
9ad19b0
to
6ed68f4
Compare
Resolved the conflicts.
Well, we are just copying the status from VolumeReplication CR, so I am not sure if there is any way we can change that other than updating the VolumeReplication CR :/ |
6ed68f4
to
59d57ad
Compare
569acd1
to
9ada567
Compare
9ada567
to
7e35516
Compare
3634fbb
to
1588709
Compare
902954e
to
a6065ee
Compare
added controller logic for volume group replication Signed-off-by: Nikhil-Ladha <[email protected]>
add generated changes for crds, rbacs Signed-off-by: Nikhil-Ladha <[email protected]>
add docs for volumegroupreplication and volumegroupreplicationclass CRs. Signed-off-by: Nikhil-Ladha <[email protected]>
a6065ee
to
7d2176f
Compare
This PR adds the following codes/logic: