@@ -406,76 +406,76 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
406
406
return & csi.DeleteVolumeResponse {}, nil
407
407
}
408
408
409
- //TODO: Add Delete File System when FS provisioning is implemented
410
- if accessPointId != "" {
409
+ if accessPointId == "" {
410
+ klog .V (5 ).Infof ("DeleteVolume: No Access Point for volume %v, returning success" , volId )
411
+ return & csi.DeleteVolumeResponse {}, nil
412
+ }
411
413
412
- // Delete access point root directory if delete-access-point-root-dir is set.
413
- if d .deleteAccessPointRootDir {
414
- // Check if Access point exists.
415
- // If access point exists, retrieve its root directory and delete it/
416
- accessPoint , err := localCloud .DescribeAccessPoint (ctx , accessPointId )
417
- if err != nil {
418
- if err == cloud .ErrAccessDenied {
419
- return nil , status .Errorf (codes .Unauthenticated , "Access Denied. Please ensure you have the right AWS permissions: %v" , err )
420
- }
421
- if err == cloud .ErrNotFound {
422
- klog .V (5 ).Infof ("DeleteVolume: Access Point %v not found, returning success" , accessPointId )
423
- return & csi.DeleteVolumeResponse {}, nil
424
- }
425
- return nil , status .Errorf (codes .Internal , "Could not get describe Access Point: %v , error: %v" , accessPointId , err )
414
+ //TODO: Add Delete File System when FS provisioning is implemented
415
+ // Delete access point root directory if delete-access-point-root-dir is set.
416
+ if d .deleteAccessPointRootDir {
417
+ // Check if Access point exists.
418
+ // If access point exists, retrieve its root directory and delete it/
419
+ accessPoint , err := localCloud .DescribeAccessPoint (ctx , accessPointId )
420
+ if err != nil {
421
+ if err == cloud .ErrAccessDenied {
422
+ return nil , status .Errorf (codes .Unauthenticated , "Access Denied. Please ensure you have the right AWS permissions: %v" , err )
426
423
}
424
+ if err == cloud .ErrNotFound {
425
+ klog .V (5 ).Infof ("DeleteVolume: Access Point %v not found, returning success" , accessPointId )
426
+ return & csi.DeleteVolumeResponse {}, nil
427
+ }
428
+ return nil , status .Errorf (codes .Internal , "Could not get describe Access Point: %v , error: %v" , accessPointId , err )
429
+ }
427
430
428
- //Mount File System at it root and delete access point root directory
429
- mountOptions := []string {"tls" , "iam" }
430
- if roleArn != "" {
431
- if crossAccountDNSEnabled {
432
- // Connect via dns rather than mounttargetip
433
- mountOptions = append (mountOptions , CrossAccount )
431
+ //Mount File System at it root and delete access point root directory
432
+ mountOptions := []string {"tls" , "iam" }
433
+ if roleArn != "" {
434
+ if crossAccountDNSEnabled {
435
+ // Connect via dns rather than mounttargetip
436
+ mountOptions = append (mountOptions , CrossAccount )
437
+ } else {
438
+ mountTarget , err := localCloud .DescribeMountTargets (ctx , fileSystemId , "" )
439
+ if err == nil {
440
+ mountOptions = append (mountOptions , MountTargetIp + "=" + mountTarget .IPAddress )
434
441
} else {
435
- mountTarget , err := localCloud .DescribeMountTargets (ctx , fileSystemId , "" )
436
- if err == nil {
437
- mountOptions = append (mountOptions , MountTargetIp + "=" + mountTarget .IPAddress )
438
- } else {
439
- klog .Warningf ("Failed to describe mount targets for file system %v. Skip using `mounttargetip` mount option: %v" , fileSystemId , err )
440
- }
442
+ klog .Warningf ("Failed to describe mount targets for file system %v. Skip using `mounttargetip` mount option: %v" , fileSystemId , err )
441
443
}
442
444
}
445
+ }
443
446
444
- target := TempMountPathPrefix + "/" + accessPointId
445
- if err := d .mounter .MakeDir (target ); err != nil {
446
- return nil , status .Errorf (codes .Internal , "Could not create dir %q: %v" , target , err )
447
- }
448
- if err := d .mounter .Mount (fileSystemId , target , "efs" , mountOptions ); err != nil {
449
- os .Remove (target )
450
- return nil , status .Errorf (codes .Internal , "Could not mount %q at %q: %v" , fileSystemId , target , err )
451
- }
452
- err = os .RemoveAll (target + accessPoint .AccessPointRootDir )
453
- if err != nil {
454
- return nil , status .Errorf (codes .Internal , "Could not delete access point root directory %q: %v" , accessPoint .AccessPointRootDir , err )
455
- }
456
- err = d .mounter .Unmount (target )
457
- if err != nil {
458
- return nil , status .Errorf (codes .Internal , "Could not unmount %q: %v" , target , err )
459
- }
460
- err = os .RemoveAll (target )
461
- if err != nil {
462
- return nil , status .Errorf (codes .Internal , "Could not delete %q: %v" , target , err )
463
- }
447
+ target := TempMountPathPrefix + "/" + accessPointId
448
+ if err := d .mounter .MakeDir (target ); err != nil {
449
+ return nil , status .Errorf (codes .Internal , "Could not create dir %q: %v" , target , err )
450
+ }
451
+ if err := d .mounter .Mount (fileSystemId , target , "efs" , mountOptions ); err != nil {
452
+ os .Remove (target )
453
+ return nil , status .Errorf (codes .Internal , "Could not mount %q at %q: %v" , fileSystemId , target , err )
464
454
}
455
+ err = os .RemoveAll (target + accessPoint .AccessPointRootDir )
456
+ if err != nil {
457
+ return nil , status .Errorf (codes .Internal , "Could not delete access point root directory %q: %v" , accessPoint .AccessPointRootDir , err )
458
+ }
459
+ err = d .mounter .Unmount (target )
460
+ if err != nil {
461
+ return nil , status .Errorf (codes .Internal , "Could not unmount %q: %v" , target , err )
462
+ }
463
+ err = os .RemoveAll (target )
464
+ if err != nil {
465
+ return nil , status .Errorf (codes .Internal , "Could not delete %q: %v" , target , err )
466
+ }
467
+ }
465
468
466
- // Delete access point
467
- if err = localCloud .DeleteAccessPoint (ctx , accessPointId ); err != nil {
468
- if err == cloud .ErrAccessDenied {
469
- return nil , status .Errorf (codes .Unauthenticated , "Access Denied. Please ensure you have the right AWS permissions: %v" , err )
470
- }
471
- if err == cloud .ErrNotFound {
472
- klog .V (5 ).Infof ("DeleteVolume: Access Point not found, returning success" )
473
- return & csi.DeleteVolumeResponse {}, nil
474
- }
475
- return nil , status .Errorf (codes .Internal , "Failed to Delete volume %v: %v" , volId , err )
469
+ // Delete access point
470
+ if err = localCloud .DeleteAccessPoint (ctx , accessPointId ); err != nil {
471
+ if err == cloud .ErrAccessDenied {
472
+ return nil , status .Errorf (codes .Unauthenticated , "Access Denied. Please ensure you have the right AWS permissions: %v" , err )
476
473
}
477
- } else {
478
- return nil , status .Errorf (codes .NotFound , "Failed to find access point for volume: %v" , volId )
474
+ if err == cloud .ErrNotFound {
475
+ klog .V (5 ).Infof ("DeleteVolume: Access Point not found, returning success" )
476
+ return & csi.DeleteVolumeResponse {}, nil
477
+ }
478
+ return nil , status .Errorf (codes .Internal , "Failed to Delete volume %v: %v" , volId , err )
479
479
}
480
480
481
481
return & csi.DeleteVolumeResponse {}, nil
0 commit comments