Skip to content

Commit 9a7b9cc

Browse files
committed
Fix volume delete failure for static provisioning when accessPointId is empty
1 parent a416c3d commit 9a7b9cc

File tree

2 files changed

+63
-63
lines changed

2 files changed

+63
-63
lines changed

pkg/driver/controller.go

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -406,76 +406,76 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
406406
return &csi.DeleteVolumeResponse{}, nil
407407
}
408408

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+
}
411413

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)
426423
}
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+
}
427430

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)
434441
} 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)
441443
}
442444
}
445+
}
443446

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)
464454
}
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+
}
465468

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)
476473
}
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)
479479
}
480480

481481
return &csi.DeleteVolumeResponse{}, nil

pkg/driver/controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,7 +3003,7 @@ func TestDeleteVolume(t *testing.T) {
30033003
},
30043004
},
30053005
{
3006-
name: "Fail: Access Point is missing in volume Id",
3006+
name: "Success: Access Point is missing in volume Id",
30073007
testFunc: func(t *testing.T) {
30083008
mockCtl := gomock.NewController(t)
30093009
mockCloud := mocks.NewMockCloud(mockCtl)
@@ -3020,8 +3020,8 @@ func TestDeleteVolume(t *testing.T) {
30203020

30213021
ctx := context.Background()
30223022
_, err := driver.DeleteVolume(ctx, req)
3023-
if err == nil {
3024-
t.Fatal("DeleteVolume did not fail")
3023+
if err != nil {
3024+
t.Fatalf("DeleteVolume failed: %v", err)
30253025
}
30263026
mockCtl.Finish()
30273027
},

0 commit comments

Comments
 (0)