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

Add Finalizer for VolumeSnapshot and VolumeSnapshotContent #39

Merged
merged 1 commit into from
Nov 27, 2018

Conversation

xing-yang
Copy link
Collaborator

@xing-yang xing-yang commented Oct 10, 2018

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.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 10, 2018
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 10, 2018
@xing-yang xing-yang force-pushed the content_protect branch 3 times, most recently from e6cc336 to 6ed0fef Compare October 15, 2018 02:39
@xing-yang xing-yang changed the title WIP: Add Finalizer for VolumeSnapshotContent WIP: Add Finalizer for VolumeSnapshot/VolumeSnapshotContent Oct 15, 2018
@xing-yang xing-yang changed the title WIP: Add Finalizer for VolumeSnapshot/VolumeSnapshotContent WIP: Add Finalizer for VolumeSnapshot and VolumeSnapshotContent Oct 15, 2018
@xing-yang xing-yang force-pushed the content_protect branch 3 times, most recently from 70877b5 to dd6f314 Compare November 1, 2018 17:15
@xing-yang xing-yang changed the title WIP: Add Finalizer for VolumeSnapshot and VolumeSnapshotContent Add Finalizer for VolumeSnapshot and VolumeSnapshotContent Nov 1, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 1, 2018
@xing-yang xing-yang force-pushed the content_protect branch 2 times, most recently from 5de6d93 to 891f51f Compare November 20, 2018 20:48
@xing-yang
Copy link
Collaborator Author

@jingxu97 @wackxu PTAL

Copy link
Contributor

@wackxu wackxu left a 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{})
Copy link
Contributor

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

Copy link
Collaborator Author

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

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
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

@wackxu
Copy link
Contributor

wackxu commented Nov 21, 2018

1.Since we are adding admission webhook #36, we can also add a MutatingWebhook to add finalizer for snapshot and snapshot content when they create.

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.

@xing-yang
Copy link
Collaborator Author

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.

Copy link
Contributor

@wackxu wackxu left a 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)
Copy link
Contributor

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

Copy link
Collaborator Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Collaborator Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Collaborator Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@jingxu97
Copy link
Collaborator

lgtm

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.
@jingxu97
Copy link
Collaborator

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 27, 2018
@k8s-ci-robot k8s-ci-robot merged commit 840095d into kubernetes-csi:master Nov 27, 2018
@xing-yang xing-yang deleted the content_protect branch April 8, 2019 02:07
bertinatto pushed a commit to bertinatto/external-snapshotter that referenced this pull request Aug 17, 2021
…cy-openshift-4.7-ose-csi-snapshot-controller

Updating ose-csi-snapshot-controller builder & base images to be consistent with ART
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants