Skip to content

Commit 11ac689

Browse files
committed
Ignore NotFound error on ControllerUnpublish
Assume that the volume is detached.
1 parent 11847e6 commit 11ac689

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pkg/attacher/attacher.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ func (a *attacher) Detach(ctx context.Context, volumeID string, nodeID string, s
8686
}
8787

8888
_, err := client.ControllerUnpublishVolume(ctx, &req)
89+
if err != nil {
90+
// Consume NotFound error.
91+
st, ok := status.FromError(err)
92+
if !ok {
93+
// This is not gRPC error.
94+
return err
95+
}
96+
if st.Code() == codes.NotFound {
97+
// Consume the error, the volume or the node has been deleted
98+
// and the volume must have been detached.
99+
klog.Warningf("Got NotFound error when detaching volume %q from node %q. Assuming the volume is detached.", volumeID, nodeID)
100+
return nil
101+
}
102+
}
89103
return err
90104
}
91105

pkg/attacher/attacher_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func TestDetachAttach(t *testing.T) {
323323
nodeID: defaultNodeID,
324324
input: defaultRequest,
325325
output: nil,
326-
injectError: codes.NotFound,
326+
injectError: codes.PermissionDenied,
327327
expectError: true,
328328
},
329329
{
@@ -335,6 +335,15 @@ func TestDetachAttach(t *testing.T) {
335335
injectError: codes.DeadlineExceeded,
336336
expectError: true,
337337
},
338+
{
339+
name: "gRPC NotFound error",
340+
volumeID: defaultVolumeID,
341+
nodeID: defaultNodeID,
342+
input: defaultRequest,
343+
output: nil,
344+
injectError: codes.NotFound,
345+
expectError: false,
346+
},
338347
}
339348

340349
tmpdir := tempDir(t)

0 commit comments

Comments
 (0)