Skip to content

Commit

Permalink
handle unpublish gracefully for volumes that are unmounted already
Browse files Browse the repository at this point in the history
Signed-off-by: Swami Viswanathan <[email protected]>
  • Loading branch information
Swami Viwanathan committed Jan 18, 2024
1 parent e9d5cdc commit 37bb8fa
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,17 @@ func (d *Driver) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublish
return nil, status.Error(codes.InvalidArgument, "request missing required target path")
}

if err := unmount(req.TargetPath); err != nil {
return nil, status.Errorf(codes.Internal, "unable to unmount %q: %v", req.TargetPath, err)
// Check if target is a valid mount and issue unmount request
if ok, err := isMountPoint(req.TargetPath); err != nil {
return nil, status.Errorf(codes.Internal, "unable to verify mount point %q: %v", req.TargetPath, err)
} else if ok {
if err := unmount(req.TargetPath); err != nil {
return nil, status.Errorf(codes.Internal, "unable to unmount %q: %v", req.TargetPath, err)
}
}
if err := os.Remove(req.TargetPath); err != nil {

// Check and remove the mount path if present, report an error otherwise
if err := os.Remove(req.TargetPath); err != nil && !errors.Is(err, os.ErrNotExist) {
return nil, status.Errorf(codes.Internal, "unable to remove target path %q: %v", req.TargetPath, err)
}

Expand Down

0 comments on commit 37bb8fa

Please sign in to comment.