From a46d912311ab9d06235dee22b64db5e77cc36649 Mon Sep 17 00:00:00 2001 From: thorner Date: Fri, 17 Jun 2022 17:17:15 -0400 Subject: [PATCH] Allow Volume attach to retry if Volume is still attached to a Linode --- pkg/linode-bs/controllerserver.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/linode-bs/controllerserver.go b/pkg/linode-bs/controllerserver.go index a5c1bf34..c3b3341a 100644 --- a/pkg/linode-bs/controllerserver.go +++ b/pkg/linode-bs/controllerserver.go @@ -227,7 +227,11 @@ func (linodeCS *LinodeControllerServer) ControllerPublishVolume(ctx context.Cont } if _, err := linodeCS.CloudProvider.AttachVolume(ctx, volumeID, opts); err != nil { - return nil, status.Errorf(codes.Internal, "error attaching volume: %s", err) + retCode := codes.Internal + if apiErr, ok := err.(*linodego.Error); ok && strings.Contains(apiErr.Message, "is already attached") { + retCode = codes.Unavailable // Allow a retry if the volume is already attached: race condition can occur here + } + return nil, status.Errorf(retCode, "error attaching volume: %s", err) } glog.V(4).Infoln("waiting for volume to attach")