@@ -67,22 +67,22 @@ func (ctrl *csiSnapshotSideCarController) syncContent(content *crdv1.VolumeSnaps
67
67
// Note that the deletion snapshot operation will update content SnapshotHandle
68
68
// to nil upon a successful deletion. At this
69
69
// point, the finalizer on content should NOT be removed to avoid leaking.
70
- err := ctrl .deleteCSISnapshot (content )
70
+ var err error
71
+ content , err = ctrl .deleteCSISnapshot (content )
71
72
if err != nil {
72
73
return true , err
73
74
}
74
- return false , nil
75
+ // Continue removing the finalizer
75
76
}
76
- // otherwise, either the snapshot has been deleted from the underlying
77
- // storage system, or it belongs to a volumegroupsnapshot, or the deletion policy is Retain,
77
+ // the snapshot has been deleted from the underlying storage system, or
78
+ // it belongs to a volumegroupsnapshot, or the deletion policy is Retain,
78
79
// remove the finalizer if there is one so that API server could delete
79
80
// the object if there is no other finalizer.
80
81
err := ctrl .removeContentFinalizer (content )
81
82
if err != nil {
82
83
return true , err
83
84
}
84
85
return false , nil
85
-
86
86
}
87
87
88
88
// Create snapshot calling the CSI driver only if it is a dynamic
@@ -109,7 +109,7 @@ func (ctrl *csiSnapshotSideCarController) syncContent(content *crdv1.VolumeSnaps
109
109
}
110
110
111
111
// deleteCSISnapshot starts delete action.
112
- func (ctrl * csiSnapshotSideCarController ) deleteCSISnapshot (content * crdv1.VolumeSnapshotContent ) error {
112
+ func (ctrl * csiSnapshotSideCarController ) deleteCSISnapshot (content * crdv1.VolumeSnapshotContent ) ( * crdv1. VolumeSnapshotContent , error ) {
113
113
klog .V (5 ).Infof ("Deleting snapshot for content: %s" , content .Name )
114
114
return ctrl .deleteCSISnapshotOperation (content )
115
115
}
@@ -397,31 +397,29 @@ func (ctrl *csiSnapshotSideCarController) createSnapshotWrapper(content *crdv1.V
397
397
}
398
398
399
399
// Delete a snapshot: Ask the backend to remove the snapshot device
400
- func (ctrl * csiSnapshotSideCarController ) deleteCSISnapshotOperation (content * crdv1.VolumeSnapshotContent ) error {
400
+ func (ctrl * csiSnapshotSideCarController ) deleteCSISnapshotOperation (content * crdv1.VolumeSnapshotContent ) ( * crdv1. VolumeSnapshotContent , error ) {
401
401
klog .V (5 ).Infof ("deleteCSISnapshotOperation [%s] started" , content .Name )
402
402
403
403
snapshotterCredentials , err := ctrl .GetCredentialsFromAnnotation (content )
404
404
if err != nil {
405
405
ctrl .eventRecorder .Event (content , v1 .EventTypeWarning , "SnapshotDeleteError" , "Failed to get snapshot credentials" )
406
- return fmt .Errorf ("failed to get input parameters to delete snapshot for content %s: %q" , content .Name , err )
406
+ return content , fmt .Errorf ("failed to get input parameters to delete snapshot for content %s: %q" , content .Name , err )
407
407
}
408
408
409
409
err = ctrl .handler .DeleteSnapshot (content , snapshotterCredentials )
410
410
if err != nil {
411
411
ctrl .eventRecorder .Event (content , v1 .EventTypeWarning , "SnapshotDeleteError" , "Failed to delete snapshot" )
412
- return fmt .Errorf ("failed to delete snapshot %#v, err: %v" , content .Name , err )
412
+ return content , fmt .Errorf ("failed to delete snapshot %#v, err: %v" , content .Name , err )
413
413
}
414
414
// the snapshot has been deleted from the underlying storage system, update
415
415
// content status to remove snapshot handle etc.
416
+ // This triggers a re-sync of the content object, which will continue cleaning the object (e.g. finalizers)
416
417
newContent , err := ctrl .clearVolumeContentStatus (content .Name )
417
418
if err != nil {
418
419
ctrl .eventRecorder .Event (content , v1 .EventTypeWarning , "SnapshotDeleteError" , "Failed to clear content status" )
419
- return err
420
+ return content , err
420
421
}
421
- // trigger syncContent
422
- // TODO: just enqueue the content object instead of calling syncContent directly
423
- ctrl .updateContentInInformerCache (newContent )
424
- return nil
422
+ return newContent , nil
425
423
}
426
424
427
425
// clearVolumeContentStatus resets all fields to nil related to a snapshot in
0 commit comments