-
Notifications
You must be signed in to change notification settings - Fork 386
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 Finalizer for VolumeSnapshot and VolumeSnapshotContent #39
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: xing-yang The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
e6cc336
to
6ed0fef
Compare
70877b5
to
dd6f314
Compare
5de6d93
to
891f51f
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.
The code overall LGTM, only some nits.
|
||
// isVolumeBeingCreatedFromSnapshot checks if an volume is being created from the snapshot. | ||
func (ctrl *csiSnapshotController) isVolumeBeingCreatedFromSnapshot(snapshot *crdv1.VolumeSnapshot) bool { | ||
pvcList, err := ctrl.client.CoreV1().PersistentVolumeClaims(snapshot.Namespace).List(metav1.ListOptions{}) |
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.
we should use pvcLister
to reduce the server pressure instead of using client
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.
Good suggestion. I think a separate PR should be submitted to add pvcLister to the snapshot controller first, and after that this can be updated to use that.
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.
could you create an issue for it so that we won't forget?
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.
Sure. Opened issue #70
if needToAddContentFinalizer(content) { | ||
// Content is not being deleted -> it should have the finalizer. The | ||
// finalizer should be added by admission plugin, this is just to add | ||
// the finalizer to old volume snapshot contents that were created before |
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.
for now, we do not have admission plugin to add the finalizer for snapshot content.
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.
Will remove it for now.
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.
Removed
// Snapshot is not being deleted -> it should have the finalizer. The | ||
// finalizer should be added by admission plugin, this is just to add | ||
// the finalizer to old volume snapshots that were created before | ||
// the admission plugin was enabled. |
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.
for now, we do not have admission plugin to add the finalizer for snapshot.
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.
Will remove it for now.
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.
Removed
1.Since we are adding admission webhook #36, we can also add a 2.Can we make the protection feature in a separate controller, like k8s pv_protection_controller, it is convenient for us to test and we should obey single responsibility principle and make the snapshot controller to do the specialized task. |
We'll add a webhook to add finalizer for snapshot after #36 is merged. Jing and I discussed about whether to implement finalizer in a separate controller, similar to pv_protection_controller, but decided to keep it simple and add it to the same controller. There's a trade-off between separating logic into different controllers and the overhead of maintaining multiple controllers. PV controller is very big and adding more to it will make it more complicated, while the snapshot controller is much simpler and putting the logic in the same controller makes it easier to maintain. |
891f51f
to
c1078f1
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.
LGTM except some nits. And we need add unit test for these changes, maybe other pr.
// Check if a volume is being created from snapshot. | ||
isUsed := ctrl.isVolumeBeingCreatedFromSnapshot(snapshot) | ||
if !isUsed { | ||
glog.V(5).Infof("syncSnapshot: Remove Finalizer for VolumeSnapshot[%s]", snapshot.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.
snapshotKey(snapshot)
maybe better for logging
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
|
||
if needToAddSnapshotFinalizer(snapshot) { | ||
// Snapshot is not being deleted -> it should have the finalizer. | ||
glog.V(5).Infof("syncSnapshot: Add Finalizer for VolumeSnapshot[%s]", snapshot.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.
ditto
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
func (ctrl *csiSnapshotController) isVolumeBeingCreatedFromSnapshot(snapshot *crdv1.VolumeSnapshot) bool { | ||
pvcList, err := ctrl.client.CoreV1().PersistentVolumeClaims(snapshot.Namespace).List(metav1.ListOptions{}) | ||
if err != nil { | ||
glog.Errorf("Failed to retrieve PVCs from the API server to check if volume snapshot %s is being used by a volume: %q", snapshot.Name, err) |
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.
ditto
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
} | ||
} | ||
} | ||
glog.V(5).Infof("isVolumeBeingCreatedFromSnapshot: no volume is being created from snapshot %s", snapshot.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.
ditto
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
lgtm |
c1078f1
to
588e911
Compare
This PR adds a Finalizer for VolumeSnapshotContent. If the VolumeSnapshotContent is bound to a VolumeSnapshot, the VolumeSnapshotContent is being used and cannot be deleted. This PR also adds a Finalizer for VolumeSnapshot. If a volume is being created from the snapshot, the VolumeSnapshot is being used and cannot be deleted.
588e911
to
ea17039
Compare
/lgtm |
…cy-openshift-4.7-ose-csi-snapshot-controller Updating ose-csi-snapshot-controller builder & base images to be consistent with ART
This PR adds a Finalizer for VolumeSnapshotContent.
If the VolumeSnapshotContent is bound to a VolumeSnapshot,
the VolumeSnapshotContent is being used and cannot be
deleted.
This PR also adds a Finalizer for VolumeSnapshot.
If a volume is being created from the snapshot,
the VolumeSnapshot is being used and cannot be deleted.