From 37bb8fa045048021611a2362cdd1dd0c33162e28 Mon Sep 17 00:00:00 2001 From: Swami Viwanathan Date: Wed, 17 Jan 2024 19:49:31 -0800 Subject: [PATCH] handle unpublish gracefully for volumes that are unmounted already Signed-off-by: Swami Viswanathan --- pkg/driver/driver.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index edc6230..ba73e12 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -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) }