Repository: kubernetes-csi/external-snapshotter
Pull request #275 (2020-03-13 19:58:02)

Allows VolumeSnapshot to be deleted if the class isn't found
**What type of PR is this?**
/kind flake

**What this PR does / why we need it**:
There were some instances where a namespace remained after a test due to a VolumeSnapshot persisted after the associated objects (VolumeSnapshotContent/PVC) and VolumeSnapshotClass had been deleted. If the cluster entered into this state, then the namespace would remain until the VolumeSnapshot was manually removed.

This PR allows a VolumeSnapshot that's been scheduled for deletion to be successfully deleted if the VolumeSnapshotClass cannot be found.

**Which issue(s) this PR fixes**:
N/A

**Special notes for your reviewer**:

**Does this PR introduce a user-facing change?**:
```release-note
NONE
```


k8s-ci-robot: Hi @huffmanca. Thanks for your PR.

I'm waiting for a [kubernetes-csi](https://github.com/orgs/kubernetes-csi/people) member to verify that this patch is reasonable to test. If it is, they should reply with `/ok-to-test` on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should [join the org](https://git.k8s.io/community/community-membership.md#member) to skip this step.

Once the patch is verified, the new status will be reflected by the `ok-to-test` label.

I understand the commands that are listed [here](https://go.k8s.io/bot-commands?repo=kubernetes-csi%2Fexternal-snapshotter).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
</details>

k8s-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-csi/external-snapshotter/pull/275#" title="Author self-approved">huffmanca</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **jingxu97**
You can assign the PR to them by writing `/assign @jingxu97` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-csi%2Fexternal-snapshotter).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubernetes-csi/external-snapshotter/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["jingxu97"]} -->
xing-yang: /ok-to-test
k8s-ci-robot: @huffmanca: The following test **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-kubernetes-csi-external-snapshotter-unit | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-unit/1238555699772919808) | `/test pull-kubernetes-csi-external-snapshotter-unit`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-csi&repo=external-snapshotter&pr=275). [Your PR dashboard](https://gubernator.k8s.io/pr/huffmanca). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-csi/external-snapshotter/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @huffmanca: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-kubernetes-csi-external-snapshotter-unit | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-unit/1238555699772919808) | `/test pull-kubernetes-csi-external-snapshotter-unit`
pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15 | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15/1238555699777114114) | `/test pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-csi&repo=external-snapshotter&pr=275). [Your PR dashboard](https://gubernator.k8s.io/pr/huffmanca). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-csi/external-snapshotter/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @huffmanca: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-kubernetes-csi-external-snapshotter-unit | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-unit/1238555699772919808) | `/test pull-kubernetes-csi-external-snapshotter-unit`
pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15 | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15/1238555699777114114) | `/test pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15`
pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16 | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16/1238555699777114113) | `/test pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-csi&repo=external-snapshotter&pr=275). [Your PR dashboard](https://gubernator.k8s.io/pr/huffmanca). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-csi/external-snapshotter/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @huffmanca: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-kubernetes-csi-external-snapshotter-unit | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-unit/1238555699772919808) | `/test pull-kubernetes-csi-external-snapshotter-unit`
pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15 | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15/1238555699777114114) | `/test pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15`
pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16 | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16/1238555699777114113) | `/test pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16`
pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17 | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17/1238555699777114112) | `/test pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-csi&repo=external-snapshotter&pr=275). [Your PR dashboard](https://gubernator.k8s.io/pr/huffmanca). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-csi/external-snapshotter/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @huffmanca: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-kubernetes-csi-external-snapshotter-unit | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-unit/1238555699772919808) | `/test pull-kubernetes-csi-external-snapshotter-unit`
pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16 | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16/1238555699777114113) | `/test pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16`
pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17 | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17/1238555699777114112) | `/test pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17`
pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15 | 169ede198712bcc73877aa747aae6db4e8456c14 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15/1239950468071821315) | `/test pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-csi&repo=external-snapshotter&pr=275). [Your PR dashboard](https://gubernator.k8s.io/pr/huffmanca). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-csi/external-snapshotter/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @huffmanca: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16 | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16/1238555699777114113) | `/test pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16`
pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17 | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17/1238555699777114112) | `/test pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17`
pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15 | 169ede198712bcc73877aa747aae6db4e8456c14 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15/1239950468071821315) | `/test pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15`
pull-kubernetes-csi-external-snapshotter-unit | 169ede198712bcc73877aa747aae6db4e8456c14 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-unit/1239950468071821312) | `/test pull-kubernetes-csi-external-snapshotter-unit`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-csi&repo=external-snapshotter&pr=275). [Your PR dashboard](https://gubernator.k8s.io/pr/huffmanca). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-csi/external-snapshotter/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @huffmanca: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16 | f5bd31e551471adeea54f0f2ad9497ed53cdbf33 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16/1238555699777114113) | `/test pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16`
pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15 | 169ede198712bcc73877aa747aae6db4e8456c14 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15/1239950468071821315) | `/test pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15`
pull-kubernetes-csi-external-snapshotter-unit | 169ede198712bcc73877aa747aae6db4e8456c14 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-unit/1239950468071821312) | `/test pull-kubernetes-csi-external-snapshotter-unit`
pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17 | 169ede198712bcc73877aa747aae6db4e8456c14 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17/1239950468071821313) | `/test pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-csi&repo=external-snapshotter&pr=275). [Your PR dashboard](https://gubernator.k8s.io/pr/huffmanca). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-csi/external-snapshotter/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @huffmanca: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15 | 169ede198712bcc73877aa747aae6db4e8456c14 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15/1239950468071821315) | `/test pull-kubernetes-csi-external-snapshotter-1-15-on-kubernetes-1-15`
pull-kubernetes-csi-external-snapshotter-unit | 169ede198712bcc73877aa747aae6db4e8456c14 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-unit/1239950468071821312) | `/test pull-kubernetes-csi-external-snapshotter-unit`
pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17 | 169ede198712bcc73877aa747aae6db4e8456c14 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17/1239950468071821313) | `/test pull-kubernetes-csi-external-snapshotter-1-17-on-kubernetes-1-17`
pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16 | 169ede198712bcc73877aa747aae6db4e8456c14 | [link](https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/kubernetes-csi_external-snapshotter/275/pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16/1239950468071821314) | `/test pull-kubernetes-csi-external-snapshotter-1-16-on-kubernetes-1-16`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-csi&repo=external-snapshotter&pr=275). [Your PR dashboard](https://gubernator.k8s.io/pr/huffmanca). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-csi/external-snapshotter/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
huffmanca: @xing-yang - this should be ready for review
huffmanca: I also removed the second commit and submitted it as a separate PR in https://github.com/kubernetes-csi/external-snapshotter/pull/278 .

Patch:
diff --git a/pkg/common-controller/snapshot_controller.go b/pkg/common-controller/snapshot_controller.go
index cc3b00665..0d136ede0 100644
--- a/pkg/common-controller/snapshot_controller.go
+++ b/pkg/common-controller/snapshot_controller.go
@@ -266,7 +266,7 @@ func (ctrl *csiSnapshotCommonController) checkandRemoveSnapshotFinalizersAndChec
 		}
 
 		if !inUse {
-			klog.V(5).Infof("checkandRemoveSnapshotFinalizersAndCheckandDeleteContent: Set VolumeSnapshotBeingDeleted annotation on the content")
+			klog.V(5).Infof("checkandRemoveSnapshotFinalizersAndCheckandDeleteContent: Set VolumeSnapshotBeingDeleted annotation on the content [%s]", content.Name)
 			ctrl.setAnnVolumeSnapshotBeingDeleted(content)
 
 			klog.V(5).Infof("checkandRemoveSnapshotFinalizersAndCheckandDeleteContent: Remove Finalizer for VolumeSnapshot[%s]", utils.SnapshotKey(snapshot))
@@ -1076,7 +1076,7 @@ func (ctrl *csiSnapshotCommonController) getSnapshotClass(className string) (*cr
 	class, err := ctrl.classLister.Get(className)
 	if err != nil {
 		klog.Errorf("failed to retrieve snapshot class %s from the informer: %q", className, err)
-		return nil, fmt.Errorf("failed to retrieve snapshot class %s from the informer: %q", className, err)
+		return nil, err
 	}
 
 	return class, nil
@@ -1281,9 +1281,6 @@ func (ctrl *csiSnapshotCommonController) getSnapshotFromStore(snapshotName strin
 func (ctrl *csiSnapshotCommonController) setAnnVolumeSnapshotBeingDeleted(content *crdv1.VolumeSnapshotContent) error {
 	// Set AnnVolumeSnapshotBeingDeleted if it is not set yet
 	if !metav1.HasAnnotation(content.ObjectMeta, utils.AnnVolumeSnapshotBeingDeleted) {
-		if content == nil {
-			return nil
-		}
 		klog.V(5).Infof("setAnnVolumeSnapshotBeingDeleted: set annotation [%s] on content [%s].", utils.AnnVolumeSnapshotBeingDeleted, content.Name)
 		metav1.SetMetaDataAnnotation(&content.ObjectMeta, utils.AnnVolumeSnapshotBeingDeleted, "yes")
 
diff --git a/pkg/common-controller/snapshot_controller_base.go b/pkg/common-controller/snapshot_controller_base.go
index 97659d73b..01d6c596a 100644
--- a/pkg/common-controller/snapshot_controller_base.go
+++ b/pkg/common-controller/snapshot_controller_base.go
@@ -26,7 +26,7 @@ import (
 	storagelisters "github.com/kubernetes-csi/external-snapshotter/v2/pkg/client/listers/volumesnapshot/v1beta1"
 	"github.com/kubernetes-csi/external-snapshotter/v2/pkg/utils"
 
-	"k8s.io/api/core/v1"
+	v1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/api/errors"
 	"k8s.io/apimachinery/pkg/labels"
 	"k8s.io/apimachinery/pkg/util/wait"
@@ -215,8 +215,11 @@ func (ctrl *csiSnapshotCommonController) snapshotWorker() {
 			// The volume snapshot still exists in informer cache, the event must have
 			// been add/update/sync
 			newSnapshot, err := ctrl.checkAndUpdateSnapshotClass(snapshot)
-			if err == nil {
-				klog.V(5).Infof("passed checkAndUpdateSnapshotClass for snapshot %q", key)
+			if err == nil || (newSnapshot.ObjectMeta.DeletionTimestamp != nil && errors.IsNotFound(err)) {
+				// If the VolumeSnapshotClass is not found, we still need to process an update
+				// so that syncSnapshot can delete the snapshot, should it still exist in the
+				// cluster after it's been removed from the informer cache
+				klog.V(5).Infof("updating snapshot %q; snapshotClass may have already been removed", key)
 				ctrl.updateSnapshot(newSnapshot)
 			}
 			return false
@@ -243,7 +246,10 @@ func (ctrl *csiSnapshotCommonController) snapshotWorker() {
 			return false
 		}
 		newSnapshot, err := ctrl.checkAndUpdateSnapshotClass(snapshot)
-		if err == nil {
+		if err == nil || errors.IsNotFound(err) {
+			// We should still handle deletion events even if the VolumeSnapshotClass
+			// is not found in the cluster
+			klog.V(5).Infof("deleting snapshot %q; snapshotClass may have already been removed", key)
 			ctrl.deleteSnapshot(newSnapshot)
 		}
 		return false
@@ -329,7 +335,8 @@ func (ctrl *csiSnapshotCommonController) checkAndUpdateSnapshotClass(snapshot *c
 		if err != nil {
 			klog.Errorf("checkAndUpdateSnapshotClass failed to getSnapshotClass %v", err)
 			ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "GetSnapshotClassFailed", fmt.Sprintf("Failed to get snapshot class with error %v", err))
-			return nil, err
+			// we need to return the original snapshot even if the class isn't found, as it may need to be deleted
+			return newSnapshot, err
 		}
 	} else {
 		klog.V(5).Infof("checkAndUpdateSnapshotClass [%s]: SetDefaultSnapshotClass", snapshot.Name)


Test patch:
diff --git a/pkg/common-controller/snapshot_create_test.go b/pkg/common-controller/snapshot_create_test.go
index f0a3b0a80..6573db982 100644
--- a/pkg/common-controller/snapshot_create_test.go
+++ b/pkg/common-controller/snapshot_create_test.go
@@ -99,7 +99,7 @@ func TestCreateSnapshotSync(t *testing.T) {
 			initialContents:   nocontents,
 			expectedContents:  nocontents,
 			initialSnapshots:  newSnapshotArray("snap7-1", "snapuid7-1", "claim7-1", "", classNonExisting, "", &False, nil, nil, nil, false, true, nil),
-			expectedSnapshots: newSnapshotArray("snap7-1", "snapuid7-1", "claim7-1", "", classNonExisting, "", &False, nil, nil, newVolumeError("Failed to create snapshot content with error failed to get input parameters to create snapshot snap7-1: \"failed to retrieve snapshot class non-existing from the informer: \\\"volumesnapshotclass.snapshot.storage.k8s.io \\\\\\\"non-existing\\\\\\\" not found\\\"\""), false, true, nil),
+			expectedSnapshots: newSnapshotArray("snap7-1", "snapuid7-1", "claim7-1", "", classNonExisting, "", &False, nil, nil, newVolumeError("Failed to create snapshot content with error failed to get input parameters to create snapshot snap7-1: \"volumesnapshotclass.snapshot.storage.k8s.io \\\"non-existing\\\" not found\""), false, true, nil),
 			initialClaims:     newClaimArray("claim7-1", "pvc-uid7-1", "1Gi", "volume7-1", v1.ClaimBound, &classEmpty),
 			initialVolumes:    newVolumeArray("volume7-1", "pv-uid7-1", "pv-handle7-1", "1Gi", "pvc-uid7-1", "claim7-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
 			expectedEvents:    []string{"Warning SnapshotContentCreationFailed"},
diff --git a/pkg/common-controller/snapshot_update_test.go b/pkg/common-controller/snapshot_update_test.go
index 06cdb7e1c..7f71ef063 100644
--- a/pkg/common-controller/snapshot_update_test.go
+++ b/pkg/common-controller/snapshot_update_test.go
@@ -146,7 +146,7 @@ func TestSync(t *testing.T) {
 			initialContents:   nocontents,
 			expectedContents:  nocontents,
 			initialSnapshots:  newSnapshotArray("snap7-1", "snapuid7-1", "claim7-1", "", classNonExisting, "", &False, nil, nil, nil, false, true, nil),
-			expectedSnapshots: newSnapshotArray("snap7-1", "snapuid7-1", "claim7-1", "", classNonExisting, "", &False, nil, nil, newVolumeError("Failed to create snapshot content with error failed to get input parameters to create snapshot snap7-1: \"failed to retrieve snapshot class non-existing from the informer: \\\"volumesnapshotclass.snapshot.storage.k8s.io \\\\\\\"non-existing\\\\\\\" not found\\\"\""), false, true, nil),
+			expectedSnapshots: newSnapshotArray("snap7-1", "snapuid7-1", "claim7-1", "", classNonExisting, "", &False, nil, nil, newVolumeError("Failed to create snapshot content with error failed to get input parameters to create snapshot snap7-1: \"volumesnapshotclass.snapshot.storage.k8s.io \\\"non-existing\\\" not found\""), false, true, nil),
 			initialClaims:     newClaimArray("claim7-1", "pvc-uid7-1", "1Gi", "volume7-1", v1.ClaimBound, &classEmpty),
 			initialVolumes:    newVolumeArray("volume7-1", "pv-uid7-1", "pv-handle7-1", "1Gi", "pvc-uid7-1", "claim7-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
 			expectedEvents:    []string{"Warning SnapshotContentCreationFailed"},
diff --git a/pkg/common-controller/snapshotclass_test.go b/pkg/common-controller/snapshotclass_test.go
index 72ea3b5ae..83fdfb4fe 100644
--- a/pkg/common-controller/snapshotclass_test.go
+++ b/pkg/common-controller/snapshotclass_test.go
@@ -63,7 +63,7 @@ func TestUpdateSnapshotClass(t *testing.T) {
 			name:                  "1-3 - snapshot class name not found",
 			initialContents:       nocontents,
 			initialSnapshots:      newSnapshotArray("snap1-1", "snapuid1-1", "claim1-1", "content1-1", "missing-class", "content1-1", &True, nil, nil, nil, false, true, nil),
-			expectedSnapshots:     newSnapshotArray("snap1-1", "snapuid1-1", "claim1-1", "content1-1", "missing-class", "content1-1", &False, nil, nil, newVolumeError("Failed to get snapshot class with error failed to retrieve snapshot class missing-class from the informer: \"volumesnapshotclass.snapshot.storage.k8s.io \\\"missing-class\\\" not found\""), false, true, nil),
+			expectedSnapshots:     newSnapshotArray("snap1-1", "snapuid1-1", "claim1-1", "content1-1", "missing-class", "content1-1", &False, nil, nil, newVolumeError("Failed to get snapshot class with error volumesnapshotclass.snapshot.storage.k8s.io \"missing-class\" not found"), false, true, nil),
 			initialClaims:         newClaimArray("claim1-1", "pvc-uid1-1", "1Gi", "volume1-1", v1.ClaimBound, &sameDriver),
 			initialVolumes:        newVolumeArray("volume1-1", "pv-uid1-1", "pv-handle1-1", "1Gi", "pvc-uid1-1", "claim1-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
 			initialStorageClasses: []*storage.StorageClass{sameDriverStorageClass},