Skip to content

Commit 9cf863f

Browse files
committed
Fix requeueing snapshot content after deletion error
Let syncContent() continue cleaning up VolumeSnapshotContent (i.e. remove its finalizers) after its snapshot has been deleted from the storage backend. It will requeue on all errors. Calling ctrl.updateContentInInformerCache() directly from deleteCSISnapshotOperation() does not requeue the snapshot content on error.
1 parent 0f21537 commit 9cf863f

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

pkg/sidecar-controller/snapshot_controller.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,22 @@ func (ctrl *csiSnapshotSideCarController) syncContent(content *crdv1.VolumeSnaps
6767
// Note that the deletion snapshot operation will update content SnapshotHandle
6868
// to nil upon a successful deletion. At this
6969
// 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)
7172
if err != nil {
7273
return true, err
7374
}
74-
return false, nil
75+
// Continue removing the finalizer
7576
}
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,
7879
// remove the finalizer if there is one so that API server could delete
7980
// the object if there is no other finalizer.
8081
err := ctrl.removeContentFinalizer(content)
8182
if err != nil {
8283
return true, err
8384
}
8485
return false, nil
85-
8686
}
8787

8888
// Create snapshot calling the CSI driver only if it is a dynamic
@@ -109,7 +109,7 @@ func (ctrl *csiSnapshotSideCarController) syncContent(content *crdv1.VolumeSnaps
109109
}
110110

111111
// deleteCSISnapshot starts delete action.
112-
func (ctrl *csiSnapshotSideCarController) deleteCSISnapshot(content *crdv1.VolumeSnapshotContent) error {
112+
func (ctrl *csiSnapshotSideCarController) deleteCSISnapshot(content *crdv1.VolumeSnapshotContent) (*crdv1.VolumeSnapshotContent, error) {
113113
klog.V(5).Infof("Deleting snapshot for content: %s", content.Name)
114114
return ctrl.deleteCSISnapshotOperation(content)
115115
}
@@ -397,31 +397,29 @@ func (ctrl *csiSnapshotSideCarController) createSnapshotWrapper(content *crdv1.V
397397
}
398398

399399
// 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) {
401401
klog.V(5).Infof("deleteCSISnapshotOperation [%s] started", content.Name)
402402

403403
snapshotterCredentials, err := ctrl.GetCredentialsFromAnnotation(content)
404404
if err != nil {
405405
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)
407407
}
408408

409409
err = ctrl.handler.DeleteSnapshot(content, snapshotterCredentials)
410410
if err != nil {
411411
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)
413413
}
414414
// the snapshot has been deleted from the underlying storage system, update
415415
// 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)
416417
newContent, err := ctrl.clearVolumeContentStatus(content.Name)
417418
if err != nil {
418419
ctrl.eventRecorder.Event(content, v1.EventTypeWarning, "SnapshotDeleteError", "Failed to clear content status")
419-
return err
420+
return content, err
420421
}
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
425423
}
426424

427425
// clearVolumeContentStatus resets all fields to nil related to a snapshot in

0 commit comments

Comments
 (0)