@@ -167,9 +167,10 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
167167 }
168168
169169 // 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 ) {
173174 err := ctrl .processSnapshotWithDeletionTimestamp (snapshot )
174175 if err != nil {
175176 return err
@@ -193,15 +194,21 @@ func (ctrl *csiSnapshotCommonController) syncSnapshot(snapshot *crdv1.VolumeSnap
193194 return nil
194195}
195196
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 {
198199 // Get snapshot source which is a PVC
199200 pvc , err := ctrl .getClaimFromVolumeSnapshot (snapshot )
200201 if err != nil {
201202 klog .Infof ("cannot get claim from snapshot [%s]: [%v] Claim may be deleted already." , snapshot .Name , err )
202203 return false
203204 }
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 ) {
205212 klog .V (2 ).Infof ("PVC %s/%s is being used by snapshot %s/%s as source" , pvc .Namespace , pvc .Name , snapshot .Namespace , snapshot .Name )
206213 return true
207214 }
0 commit comments