@@ -246,82 +246,93 @@ func (cl *Resources) Cleanup() {
246246 ctx := context .Background ()
247247
248248 // Clean up resources in LIFO order to account for dependency order.
249+ var errs []error
249250 for i := len (cl .managedResourceInfos ) - 1 ; i >= 0 ; i -- {
250251 resInfo := cl .managedResourceInfos [i ]
251252 id := resInfo .id
252253 switch resType := resInfo .data .(type ) {
253254 case volumeInfo :
254- cl .cleanupVolume (ctx , 2 , id , resType )
255+ errs = append ( errs , cl .cleanupVolume (ctx , 2 , id , resType ) ... )
255256 case snapshotInfo :
256- cl .cleanupSnapshot (ctx , 2 , id )
257+ errs = append ( errs , cl .cleanupSnapshot (ctx , 2 , id ) ... )
257258 default :
258259 Fail (fmt .Sprintf ("unknown resource type: %T" , resType ), 1 )
259260 }
260261 }
262+
263+ ExpectWithOffset (2 , errs ).To (BeEmpty (), "resource cleanup failed" )
264+
261265 klog .V (4 ).Info ("clearing managed resources list" )
262266 cl .managedResourceInfos = []resourceInfo {}
263267}
264268
265- func (cl * Resources ) cleanupVolume (ctx context.Context , offset int , volumeID string , info volumeInfo ) {
269+ func (cl * Resources ) cleanupVolume (ctx context.Context , offset int , volumeID string , info volumeInfo ) ( errs [] error ) {
266270 klog .V (4 ).Infof ("deleting volume ID %s" , volumeID )
267271 if cl .NodeClient != nil {
268- _ , err := cl .NodeUnpublishVolume (
272+ if _ , err := cl .NodeUnpublishVolume (
269273 ctx ,
270274 & csi.NodeUnpublishVolumeRequest {
271275 VolumeId : volumeID ,
272276 TargetPath : cl .Context .TargetPath + "/target" ,
273277 },
274- )
275- expectNoErrorOrMissing (offset + 1 , err , "NodeUnpublishVolume failed" )
278+ ); isRelevantError (err ) {
279+ errs = append (errs , fmt .Errorf ("NodeUnpublishVolume for volume ID %s failed: %s" , volumeID , err ))
280+ }
276281
277282 if cl .NodeStageSupported {
278- _ , err := cl .NodeUnstageVolume (
283+ if _ , err := cl .NodeUnstageVolume (
279284 ctx ,
280285 & csi.NodeUnstageVolumeRequest {
281286 VolumeId : volumeID ,
282287 StagingTargetPath : cl .Context .StagingPath ,
283288 },
284- )
285- expectNoErrorOrMissing (offset + 1 , err , "NodeUnstageVolume failed" )
289+ ); isRelevantError (err ) {
290+ errs = append (errs , fmt .Errorf ("NodeUnstageVolume for volume ID %s failed: %s" , volumeID , err ))
291+ }
286292 }
287293 }
288294
289295 if cl .ControllerPublishSupported && info .NodeID != "" {
290- _ , err := cl .ControllerClient .ControllerUnpublishVolume (
296+ if _ , err := cl .ControllerClient .ControllerUnpublishVolume (
291297 ctx ,
292298 & csi.ControllerUnpublishVolumeRequest {
293299 VolumeId : volumeID ,
294300 NodeId : info .NodeID ,
295301 Secrets : cl .Context .Secrets .ControllerUnpublishVolumeSecret ,
296302 },
297- )
298- ExpectWithOffset (offset , err ).NotTo (HaveOccurred (), "ControllerUnpublishVolume failed" )
303+ ); err != nil {
304+ errs = append (errs , fmt .Errorf ("ControllerUnpublishVolume for volume ID %s failed: %s" , volumeID , err ))
305+ }
299306 }
300307
301- _ , err := cl .ControllerClient .DeleteVolume (
308+ if _ , err := cl .ControllerClient .DeleteVolume (
302309 ctx ,
303310 & csi.DeleteVolumeRequest {
304311 VolumeId : volumeID ,
305312 Secrets : cl .Context .Secrets .DeleteVolumeSecret ,
306313 },
307- )
308- ExpectWithOffset (offset , err ).NotTo (HaveOccurred (), "DeleteVolume failed" )
314+ ); err != nil {
315+ errs = append (errs , fmt .Errorf ("DeleteVolume for volume ID %s failed: %s" , volumeID , err ))
316+ }
317+
318+ return errs
309319}
310320
311- func (cl * Resources ) cleanupSnapshot (ctx context.Context , offset int , id string ) {
312- klog .Infof ("deleting snapshot ID %s" , id )
313- _ , err := cl .ControllerClient .DeleteSnapshot (
321+ func (cl * Resources ) cleanupSnapshot (ctx context.Context , offset int , snapshotID string ) [] error {
322+ klog .Infof ("deleting snapshot ID %s" , snapshotID )
323+ if _ , err := cl .ControllerClient .DeleteSnapshot (
314324 ctx ,
315325 & csi.DeleteSnapshotRequest {
316- SnapshotId : id ,
326+ SnapshotId : snapshotID ,
317327 Secrets : cl .Context .Secrets .DeleteSnapshotSecret ,
318328 },
319- )
320- ExpectWithOffset (offset , err ).NotTo (HaveOccurred (), "DeleteSnapshot failed" )
329+ ); err != nil {
330+ return []error {fmt .Errorf ("NodeUnstageVolume for volume ID %s failed: %s" , snapshotID , err )}
331+ }
332+
333+ return nil
321334}
322335
323- func expectNoErrorOrMissing (offset int , err error , description string ) {
324- ExpectWithOffset (offset , err ).To (SatisfyAny (
325- Not (HaveOccurred ()),
326- WithTransform (status .Code , Equal (codes .NotFound ))), description )
336+ func isRelevantError (err error ) bool {
337+ return err != nil && status .Code (err ) != codes .NotFound
327338}
0 commit comments