Skip to content

Commit a59837a

Browse files
committed
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.
1 parent 9aeed81 commit a59837a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pkg/nfs/nodeserver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
139139
return nil, status.Error(codes.Internal, err.Error())
140140
}
141141
if notMnt {
142-
return nil, status.Error(codes.NotFound, "Volume not mounted")
142+
klog.V(2).Infof("NodeUnpublishVolume: Targetpath %s of volumeID(%s) is not mounted", targetPath, volumeID)
143+
return &csi.NodeUnpublishVolumeResponse{}, nil
143144
}
144145

145146
klog.V(2).Infof("NodeUnpublishVolume: CleanupMountPoint %s on volumeID(%s)", targetPath, volumeID)

pkg/nfs/nodeserver_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,8 @@ func TestNodeUnpublishVolume(t *testing.T) {
189189
expectedErr: status.Error(codes.Internal, "fake IsLikelyNotMountPoint: fake error"),
190190
},
191191
{
192-
desc: "[Error] Volume not mounted",
193-
req: csi.NodeUnpublishVolumeRequest{TargetPath: targetFile, VolumeId: "vol_1"},
194-
expectedErr: status.Error(codes.NotFound, "Volume not mounted"),
192+
desc: "[Success] Volume not mounted",
193+
req: csi.NodeUnpublishVolumeRequest{TargetPath: targetFile, VolumeId: "vol_1"},
195194
},
196195
}
197196

0 commit comments

Comments
 (0)