fix: NodeUnpublishVolume should be idempotent

In case the NodeUnpublishVolume procedure was aborted after unmounting
the volume, a repeated call will return an error like "Volume not
mounted".

Instead of returning the error, log a message and return success to
indicate that the volume is not mounted anymore.
This commit is contained in:
Niels de Vos 2022-04-23 16:17:25 +02:00
parent 9aeed81815
commit a59837abe1
2 changed files with 4 additions and 4 deletions

View File

@ -139,7 +139,8 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }
if notMnt { if notMnt {
return nil, status.Error(codes.NotFound, "Volume not mounted") klog.V(2).Infof("NodeUnpublishVolume: Targetpath %s of volumeID(%s) is not mounted", targetPath, volumeID)
return &csi.NodeUnpublishVolumeResponse{}, nil
} }
klog.V(2).Infof("NodeUnpublishVolume: CleanupMountPoint %s on volumeID(%s)", targetPath, volumeID) klog.V(2).Infof("NodeUnpublishVolume: CleanupMountPoint %s on volumeID(%s)", targetPath, volumeID)

View File

@ -189,9 +189,8 @@ func TestNodeUnpublishVolume(t *testing.T) {
expectedErr: status.Error(codes.Internal, "fake IsLikelyNotMountPoint: fake error"), expectedErr: status.Error(codes.Internal, "fake IsLikelyNotMountPoint: fake error"),
}, },
{ {
desc: "[Error] Volume not mounted", desc: "[Success] Volume not mounted",
req: csi.NodeUnpublishVolumeRequest{TargetPath: targetFile, VolumeId: "vol_1"}, req: csi.NodeUnpublishVolumeRequest{TargetPath: targetFile, VolumeId: "vol_1"},
expectedErr: status.Error(codes.NotFound, "Volume not mounted"),
}, },
} }