@@ -167,9 +167,10 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
167
167
}
168
168
169
169
// Proceed with snapshot deletion only if snapshot is not in the middled of being
170
- // created from a PVC. This is to ensure that the PVC finalizer can be removed even
171
- // if a delete snapshot request is received before create snapshot has completed.
172
- if snapshot .ObjectMeta .DeletionTimestamp != nil && ! ctrl .isPVCInUseByCurrentSnapshot (snapshot ) {
170
+ // created from a PVC with a finalizer. This is to ensure that the PVC finalizer
171
+ // can be removed even if a delete snapshot request is received before create
172
+ // snapshot has completed.
173
+ if snapshot .ObjectMeta .DeletionTimestamp != nil && ! ctrl .isPVCwithFinalizerInUseByCurrentSnapshot (snapshot ) {
173
174
err := ctrl .processSnapshotWithDeletionTimestamp (snapshot )
174
175
if err != nil {
175
176
return err
@@ -193,15 +194,21 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
193
194
return nil
194
195
}
195
196
196
- // Check if PVC is being used by the current snapshot as source
197
- func (ctrl * csiSnapshotCommonController ) isPVCInUseByCurrentSnapshot (snapshot * crdv1.VolumeSnapshot ) bool {
197
+ // Check if PVC has a finalizer and if it is being used by the current snapshot as source.
198
+ func (ctrl * csiSnapshotCommonController ) isPVCwithFinalizerInUseByCurrentSnapshot (snapshot * crdv1.VolumeSnapshot ) bool {
198
199
// Get snapshot source which is a PVC
199
200
pvc , err := ctrl .getClaimFromVolumeSnapshot (snapshot )
200
201
if err != nil {
201
202
klog .Infof ("cannot get claim from snapshot [%s]: [%v] Claim may be deleted already." , snapshot .Name , err )
202
203
return false
203
204
}
204
- if snapshot .Spec .Source .PersistentVolumeClaimName != nil && pvc .Name == * snapshot .Spec .Source .PersistentVolumeClaimName && ! utils .IsSnapshotReady (snapshot ) {
205
+
206
+ // Check if there is a Finalizer on PVC. If not, return false
207
+ if ! slice .ContainsString (pvc .ObjectMeta .Finalizers , utils .PVCFinalizer , nil ) {
208
+ return false
209
+ }
210
+
211
+ if ! utils .IsSnapshotReady (snapshot ) {
205
212
klog .V (2 ).Infof ("PVC %s/%s is being used by snapshot %s/%s as source" , pvc .Namespace , pvc .Name , snapshot .Namespace , snapshot .Name )
206
213
return true
207
214
}
0 commit comments