Skip to content

Commit

Permalink
Merge pull request #2183 from ConnorJC3/fix-attachvolume-spam
Browse files Browse the repository at this point in the history
Only bail to AttachVolume if volume is detached
  • Loading branch information
k8s-ci-robot authored Oct 14, 2024
2 parents 635c4c9 + 0ef0e76 commit e6dae61
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ func (c *cloud) WaitForAttachmentState(ctx context.Context, volumeID, expectedSt
// if we expected volume to be attached and it was reported as already attached via DescribeInstance call
// 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) {
if (expectedState == volumeAttachedState) && alreadyAssigned && (attachmentState == volumeDetachedState) {
request := &ec2.AttachVolumeInput{
Device: aws.String(expectedDevice),
InstanceId: aws.String(expectedInstance),
Expand Down
16 changes: 14 additions & 2 deletions pkg/cloud/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3301,14 +3301,23 @@ func TestWaitForAttachmentState(t *testing.T) {
expectError: true,
},
{
name: "failure: already assigned but wrong state",
name: "failure: already assigned but detached state",
volumeID: "vol-test-1234",
expectedState: volumeAttachedState,
expectedInstance: "1234",
expectedDevice: defaultPath,
alreadyAssigned: true,
expectError: true,
},
{
name: "failure: already assigned but attaching state",
volumeID: "vol-test-1234",
expectedState: volumeAttachedState,
expectedInstance: "1234",
expectedDevice: defaultPath,
alreadyAssigned: true,
expectError: false,
},
{
name: "failure: multiple attachments with Multi-Attach disabled",
volumeID: "vol-test-1234",
Expand Down Expand Up @@ -3353,9 +3362,12 @@ func TestWaitForAttachmentState(t *testing.T) {
switch tc.name {
case "success: detached":
mockEC2.EXPECT().DescribeVolumes(gomock.Any(), gomock.Any()).Return(&ec2.DescribeVolumesOutput{Volumes: []types.Volume{detachedVol}}, nil).AnyTimes()
case "failure: already assigned but wrong state":
case "failure: already assigned but detached state":
mockEC2.EXPECT().DescribeVolumes(gomock.Any(), gomock.Any()).Return(&ec2.DescribeVolumesOutput{Volumes: []types.Volume{detachedVol}}, nil)
mockEC2.EXPECT().AttachVolume(gomock.Any(), gomock.Any()).Return(nil, nil)
case "failure: already assigned but attaching state":
mockEC2.EXPECT().DescribeVolumes(gomock.Any(), gomock.Any()).Return(&ec2.DescribeVolumesOutput{Volumes: []types.Volume{attachingVol}}, nil)
mockEC2.EXPECT().DescribeVolumes(gomock.Any(), gomock.Any()).Return(&ec2.DescribeVolumesOutput{Volumes: []types.Volume{attachedVol}}, nil)
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 e6dae61

Please sign in to comment.