@@ -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
}
@@ -406,31 +406,29 @@ func (ctrl *csiSnapshotSideCarController) createSnapshotWrapper(content *crdv1.V
406
406
}
407
407
408
408
// Delete a snapshot: Ask the backend to remove the snapshot device
409
- func (ctrl * csiSnapshotSideCarController ) deleteCSISnapshotOperation (content * crdv1.VolumeSnapshotContent ) error {
409
+ func (ctrl * csiSnapshotSideCarController ) deleteCSISnapshotOperation (content * crdv1.VolumeSnapshotContent ) ( * crdv1. VolumeSnapshotContent , error ) {
410
410
klog .V (5 ).Infof ("deleteCSISnapshotOperation [%s] started" , content .Name )
411
411
412
412
snapshotterCredentials , err := ctrl .GetCredentialsFromAnnotation (content )
413
413
if err != nil {
414
414
ctrl .eventRecorder .Event (content , v1 .EventTypeWarning , "SnapshotDeleteError" , "Failed to get snapshot credentials" )
415
- return fmt .Errorf ("failed to get input parameters to delete snapshot for content %s: %q" , content .Name , err )
415
+ return content , fmt .Errorf ("failed to get input parameters to delete snapshot for content %s: %q" , content .Name , err )
416
416
}
417
417
418
418
err = ctrl .handler .DeleteSnapshot (content , snapshotterCredentials )
419
419
if err != nil {
420
420
ctrl .eventRecorder .Event (content , v1 .EventTypeWarning , "SnapshotDeleteError" , "Failed to delete snapshot" )
421
- return fmt .Errorf ("failed to delete snapshot %#v, err: %v" , content .Name , err )
421
+ return content , fmt .Errorf ("failed to delete snapshot %#v, err: %v" , content .Name , err )
422
422
}
423
423
// the snapshot has been deleted from the underlying storage system, update
424
424
// content status to remove snapshot handle etc.
425
+ // This triggers a re-sync of the content object, which will continue cleaning the object (e.g. finalizers)
425
426
newContent , err := ctrl .clearVolumeContentStatus (content .Name )
426
427
if err != nil {
427
428
ctrl .eventRecorder .Event (content , v1 .EventTypeWarning , "SnapshotDeleteError" , "Failed to clear content status" )
428
- return err
429
+ return content , err
429
430
}
430
- // trigger syncContent
431
- // TODO: just enqueue the content object instead of calling syncContent directly
432
- ctrl .updateContentInInformerCache (newContent )
433
- return nil
431
+ return newContent , nil
434
432
}
435
433
436
434
// clearVolumeContentStatus resets all fields to nil related to a snapshot in
0 commit comments