Skip to content

Commit

Permalink
Add explicit AttachVolume call in WaitForAttachmentState
Browse files Browse the repository at this point in the history
Signed-off-by: torredil <[email protected]>
  • Loading branch information
torredil committed Apr 11, 2024
1 parent e92b955 commit b6cb4f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/cloud/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b6cb4f8

Please sign in to comment.