Skip to content

Commit

Permalink
During detach don't return error if VM is not found (#119)
Browse files Browse the repository at this point in the history
When detaching a volume from a VM, the VM might
not be found if it was deleted for whatever reason
at this point we can assume the volume is no longer
hotplugged, and thus the detach succeeded by default

Signed-off-by: Alexander Wels <[email protected]>
  • Loading branch information
awels authored Aug 20, 2024
1 parent 87f9fb4 commit 35836e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ func (c *ControllerService) ControllerUnpublishVolume(ctx context.Context, req *
// Get VM name
vmName, err := c.getVMNameByCSINodeID(ctx, req.NodeId)
if err != nil {
if status.Code(err) == codes.NotFound {
klog.Infof("VM for node ID %s not found, assuming volume is already detached", req.NodeId)
return &csi.ControllerUnpublishVolumeResponse{}, nil
}
return nil, err
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/service/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@ var _ = Describe("PublishUnPublish", func() {
_, err := controller.ControllerUnpublishVolume(context.TODO(), getUnpublishVolumeRequest())
Expect(err).ToNot(HaveOccurred())
})

It("should return success when unpublishing a volume from a VM that doesn't exist", func() {
req := getUnpublishVolumeRequest()
req.NodeId = "non-existent-node"
_, err := controller.ControllerUnpublishVolume(context.TODO(), req)
Expect(err).ToNot(HaveOccurred())
})
})

var _ = Describe("Snapshots", func() {
Expand Down

0 comments on commit 35836e0

Please sign in to comment.