From b6cb4f857fe94f814a5318f3c2467f3a83c241f8 Mon Sep 17 00:00:00 2001 From: torredil Date: Thu, 11 Apr 2024 17:57:24 +0000 Subject: [PATCH] Add explicit AttachVolume call in WaitForAttachmentState Signed-off-by: torredil --- pkg/cloud/cloud.go | 9 +++++++++ pkg/cloud/cloud_test.go | 1 + 2 files changed, 10 insertions(+) diff --git a/pkg/cloud/cloud.go b/pkg/cloud/cloud.go index 6b66987c21..67049f20c8 100644 --- a/pkg/cloud/cloud.go +++ b/pkg/cloud/cloud.go @@ -1024,6 +1024,15 @@ func (c *cloud) WaitForAttachmentState(ctx context.Context, volumeID, expectedSt // but DescribeVolume told us volume is detached, we will short-circuit this long wait loop and return error // so as AttachDisk can be retried without waiting for 20 minutes. if (expectedState == volumeAttachedState) && alreadyAssigned && (attachmentState != expectedState) { + request := &ec2.AttachVolumeInput{ + Device: aws.String(expectedDevice), + InstanceId: aws.String(expectedInstance), + VolumeId: aws.String(volumeID), + } + _, err := c.ec2.AttachVolume(ctx, request) + if err != nil { + klog.InfoS("WaitForAttachmentState: AttachVolume call error", "volumeID", volumeID, "instanceID", expectedInstance, "Device", expectedDevice, "err", err) + } return false, fmt.Errorf("attachment of disk %q failed, expected device to be attached but was %s", volumeID, attachmentState) } diff --git a/pkg/cloud/cloud_test.go b/pkg/cloud/cloud_test.go index 707521f5c3..88c5b4e6ea 100644 --- a/pkg/cloud/cloud_test.go +++ b/pkg/cloud/cloud_test.go @@ -3031,6 +3031,7 @@ func TestWaitForAttachmentState(t *testing.T) { switch tc.name { case "success: detached", "failure: already assigned but wrong state": mockEC2.EXPECT().DescribeVolumes(gomock.Any(), gomock.Any()).Return(&ec2.DescribeVolumesOutput{Volumes: []types.Volume{detachedVol}}, nil).AnyTimes() + mockEC2.EXPECT().AttachVolume(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() case "success: disk not found, assumed detached", "failure: disk not found, expected attached": mockEC2.EXPECT().DescribeVolumes(gomock.Any(), gomock.Any()).Return(nil, &smithy.GenericAPIError{ Code: "InvalidVolume.NotFound",