From b31a29fd8338e117408ccd4e2f6c876cacbbbf77 Mon Sep 17 00:00:00 2001 From: Timo Reimann Date: Sun, 7 Feb 2021 21:57:14 +0100 Subject: [PATCH] Retain CreateSnapshot error The error returned from CreateSnapshot was overwritten by the call to removeAnnVolumeSnapshotBeingCreated. Retain the error through variable shadowing so that it can be propagated and reported upwards the call stack. We also improve the error line by dropping an unnecessary comma and dequoting the error string (since we already employ a colon separator). --- pkg/sidecar-controller/snapshot_controller.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/sidecar-controller/snapshot_controller.go b/pkg/sidecar-controller/snapshot_controller.go index d0144b18..b43c929b 100644 --- a/pkg/sidecar-controller/snapshot_controller.go +++ b/pkg/sidecar-controller/snapshot_controller.go @@ -300,13 +300,12 @@ func (ctrl *csiSnapshotSideCarController) createSnapshotWrapper(content *crdv1.V // storage system has responded with an error klog.Infof("createSnapshotWrapper: CreateSnapshot for content %s returned error: %v", content.Name, err) if isCSIFinalError(err) { - err = ctrl.removeAnnVolumeSnapshotBeingCreated(content) - if err != nil { - return nil, fmt.Errorf("failed to remove VolumeSnapshotBeingCreated annotation from the content %s: %q", content.Name, err) + if err := ctrl.removeAnnVolumeSnapshotBeingCreated(content); err != nil { + return nil, fmt.Errorf("failed to remove VolumeSnapshotBeingCreated annotation from the content %s: %s", content.Name, err) } } - return nil, fmt.Errorf("failed to take snapshot of the volume, %s: %q", *content.Spec.Source.VolumeHandle, err) + return nil, fmt.Errorf("failed to take snapshot of the volume %s: %q", *content.Spec.Source.VolumeHandle, err) } klog.V(5).Infof("Created snapshot: driver %s, snapshotId %s, creationTime %v, size %d, readyToUse %t", driverName, snapshotID, creationTime, size, readyToUse)