diff --git a/CHANGES.md b/CHANGES.md index e526e35bc5ae55a5f61820bd6eb04ab3658318ab..c396e6acbbddf59fa24bf073ab31f2e74c5be603 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## master + +- Fix stuck volume terminating when the volume was already deleted + ## v1.3.1 - Add correct deployment file for latest version diff --git a/api/volume.go b/api/volume.go index 4ee3eabd328ff3f304544e7facc1c3dd5ef316a2..74dba0849abf122a83600bbe3817d38bca811472 100644 --- a/api/volume.go +++ b/api/volume.go @@ -241,6 +241,14 @@ func (s *VolumeService) Detach(ctx context.Context, volume *csi.Volume, server * hcloudVolume, _, err := s.client.Volume.GetByID(ctx, int(volume.ID)) if err != nil { + if hcloud.IsError(err, hcloud.ErrorCodeNotFound) { + level.Info(s.logger).Log( + "msg", "volume to detach not found", + "volume-id", volume.ID, + "err", err, + ) + return volumes.ErrVolumeNotFound + } level.Info(s.logger).Log( "msg", "failed to get volume to detach", "volume-id", volume.ID, diff --git a/driver/controller.go b/driver/controller.go index 74d57adca687adc3d5f24f0f2f5515abf0f552a9..a8aab0766300b6f7cbdcfa3f3fc4d5631feab63c 100644 --- a/driver/controller.go +++ b/driver/controller.go @@ -196,8 +196,9 @@ func (s *ControllerService) ControllerUnpublishVolume(ctx context.Context, req * if err := s.volumeService.Detach(ctx, volume, server); err != nil { code := codes.Internal switch err { - case volumes.ErrVolumeNotFound: - code = codes.NotFound + case volumes.ErrVolumeNotFound: // Based on the spec it is save to assume that the call was successful if the volume is not found + resp := &proto.ControllerUnpublishVolumeResponse{} + return resp, nil case volumes.ErrServerNotFound: code = codes.NotFound case volumes.ErrLockedServer: diff --git a/driver/controller_test.go b/driver/controller_test.go index a3a90c6635d4e9a3b8bb6f4e965edda38584ee64..e374b50d7e8df6242f33f20b1d6dbeba0f2e9ce9 100644 --- a/driver/controller_test.go +++ b/driver/controller_test.go @@ -682,11 +682,6 @@ func TestControllerServiceUnpublishVolumeDetachErrors(t *testing.T) { DetachError error Code codes.Code }{ - { - Name: "volume not found", - DetachError: volumes.ErrVolumeNotFound, - Code: codes.NotFound, - }, { Name: "server not found", DetachError: volumes.ErrServerNotFound,