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 to prevent deletion of individual volume snapshots #972

Merged

Conversation

RaunakShah
Copy link
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR adds a finaliser to volume snapshot objects that are part of a group snapshot. The finaliser is removed if the group snapshot is deleted.
This is to prevent individual snapshots from being deleted when the group snapshot still exists

Testing

Create a group snapshot:

% kubectl get vgs
NAME                READYTOUSE   VOLUMEGROUPSNAPSHOTCLASS   VOLUMEGROUPSNAPSHOTCONTENT                              CREATIONTIME   AGE
my-group-snapshot   true         vgs-class                  groupsnapcontent-eb950570-7be9-41c6-a1aa-363d20019095   3s             3s
% kubectl get vs
NAME                                                                                           READYTOUSE   SOURCEPVC   SOURCESNAPSHOTCONTENT                                                                             RESTORESIZE   SNAPSHOTCLASS   SNAPSHOTCONTENT                                                                                   CREATIONTIME   AGE
snapshot-16f64470380b9fadfd5c37aefd2169e56cdd59dbe6c36a3fd1f5cba8203e9241-2023-12-07-12.20.9   true                     snapcontent-16f64470380b9fadfd5c37aefd2169e56cdd59dbe6c36a3fd1f5cba8203e9241-2023-12-07-12.20.9   1Gi                           snapcontent-16f64470380b9fadfd5c37aefd2169e56cdd59dbe6c36a3fd1f5cba8203e9241-2023-12-07-12.20.9   11s            11s
snapshot-cfb80f3c4fe5ad13011e84ed233998ebc58c13b80d7d9c70915cf342d823cf68-2023-12-07-12.20.9   true                     snapcontent-cfb80f3c4fe5ad13011e84ed233998ebc58c13b80d7d9c70915cf342d823cf68-2023-12-07-12.20.9   1Gi                           snapcontent-cfb80f3c4fe5ad13011e84ed233998ebc58c13b80d7d9c70915cf342d823cf68-2023-12-07-12.20.9   11s            11s

Delete a volume snapshot and view events:

% kubectl delete vs snapshot-16f64470380b9fadfd5c37aefd2169e56cdd59dbe6c36a3fd1f5cba8203e9241-2023-12-07-12.20.9
'volumesnapshot.snapshot.storage.k8s.io "snapshot-16f64470380b9fadfd5c37aefd2169e56cdd59dbe6c36a3fd1f5cba8203e9241-2023-12-07-12.20.9" deleted
^C
% kubectl describe vs snapshot-16f64470380b9fadfd5c37aefd2169e56cdd59dbe6c36a3fd1f5cba8203e9241-2023-12-07-12.20.9
...
Events:
  Type     Reason                 Age              From                 Message
  ----     ------                 ----             ----                 -------
  Normal   SnapshotCreated        38s              snapshot-controller  Snapshot default/snapshot-16f64470380b9fadfd5c37aefd2169e56cdd59dbe6c36a3fd1f5cba8203e9241-2023-12-07-12.20.9 was successfully created by the CSI driver.
  Normal   SnapshotReady          38s              snapshot-controller  Snapshot default/snapshot-16f64470380b9fadfd5c37aefd2169e56cdd59dbe6c36a3fd1f5cba8203e9241-2023-12-07-12.20.9 is ready to use.
  Warning  SnapshotDeletePending  2s (x3 over 5s)  snapshot-controller  deletion of the individual volume snapshot default/snapshot-16f64470380b9fadfd5c37aefd2169e56cdd59dbe6c36a3fd1f5cba8203e9241-2023-12-07-12.20.9 is not allowed as it belongs to group snapshot default/my-group-snapshot. Deleting the group snapshot will trigger the deletion of all the individual volume snapshots that are part of the group

Delete group snapshot and validate that all resources are deleted:

% kubectl delete -f volumegroupsnapshot-example.yaml 
volumegroupsnapshot.groupsnapshot.storage.k8s.io "my-group-snapshot" deleted
% kubectl get vgs
No resources found in default namespace.
% kubectl get vgsc
No resources found
% kubectl get vs
No resources found in default namespace.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Add finalizer to prevent deletion of individual volume snapshots that are part of a group

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 7, 2023
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 7, 2023
@xing-yang
Copy link
Collaborator

Can you fix the unit test failure?

@xing-yang
Copy link
Collaborator

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 7, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RaunakShah, 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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 7, 2023
@k8s-ci-robot k8s-ci-robot merged commit feca95e into kubernetes-csi:master Dec 7, 2023
8 checks passed
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants