-
Notifications
You must be signed in to change notification settings - Fork 813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
delete leaked volume if driver don't know the volume status #771
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,14 +41,15 @@ const ( | |
|
||
func TestCreateDisk(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
volumeName string | ||
volState string | ||
diskOptions *DiskOptions | ||
expDisk *Disk | ||
expErr error | ||
expCreateVolumeErr error | ||
expDescVolumeErr error | ||
name string | ||
volumeName string | ||
volState string | ||
diskOptions *DiskOptions | ||
expDisk *Disk | ||
cleanUpFailedVolume bool | ||
expErr error | ||
expCreateVolumeErr error | ||
expDescVolumeErr error | ||
}{ | ||
{ | ||
name: "success: normal", | ||
|
@@ -163,7 +164,7 @@ func TestCreateDisk(t *testing.T) { | |
expErr: nil, | ||
}, | ||
{ | ||
name: "fail: CreateVolume returned CreateVolume error", | ||
name: "fail: ec2.CreateVolume returned CreateVolume error", | ||
volumeName: "vol-test-name-error", | ||
diskOptions: &DiskOptions{ | ||
CapacityBytes: util.GiBToBytes(1), | ||
|
@@ -174,27 +175,29 @@ func TestCreateDisk(t *testing.T) { | |
expCreateVolumeErr: fmt.Errorf("CreateVolume generic error"), | ||
}, | ||
{ | ||
name: "fail: CreateVolume returned a DescribeVolumes error", | ||
name: "fail: ec2.DescribeVolumes error after volume created", | ||
volumeName: "vol-test-name-error", | ||
volState: "creating", | ||
diskOptions: &DiskOptions{ | ||
CapacityBytes: util.GiBToBytes(1), | ||
Tags: map[string]string{VolumeNameTagKey: "vol-test"}, | ||
AvailabilityZone: "", | ||
}, | ||
expErr: fmt.Errorf("could not create volume in EC2: DescribeVolumes generic error"), | ||
expCreateVolumeErr: fmt.Errorf("DescribeVolumes generic error"), | ||
expErr: fmt.Errorf("failed to get an available volume in EC2: DescribeVolumes generic error"), | ||
expDescVolumeErr: fmt.Errorf("DescribeVolumes generic error"), | ||
cleanUpFailedVolume: true, | ||
}, | ||
{ | ||
name: "fail: CreateVolume returned a volume with wrong state", | ||
name: "fail: Volume is not ready to use, volume stuck in creating status and controller timed out waiting for the condition", | ||
volumeName: "vol-test-name-error", | ||
volState: "creating", | ||
diskOptions: &DiskOptions{ | ||
CapacityBytes: util.GiBToBytes(1), | ||
Tags: map[string]string{VolumeNameTagKey: "vol-test"}, | ||
AvailabilityZone: "", | ||
}, | ||
expErr: fmt.Errorf("failed to get an available volume in EC2: timed out waiting for the condition"), | ||
cleanUpFailedVolume: true, | ||
expErr: fmt.Errorf("failed to get an available volume in EC2: timed out waiting for the condition"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the test case above (DescribeVolume error ) we should also expect to clean up. (the test case names are a bit confusing since CreateVolume could mean ec2.createvolume or csi.createvolume. If it helps and you dont mind could you disambiguate them in the test names) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
}, | ||
{ | ||
name: "success: normal from snapshot", | ||
|
@@ -243,7 +246,9 @@ func TestCreateDisk(t *testing.T) { | |
if len(tc.diskOptions.SnapshotID) > 0 { | ||
mockEC2.EXPECT().DescribeSnapshotsWithContext(gomock.Eq(ctx), gomock.Any()).Return(&ec2.DescribeSnapshotsOutput{Snapshots: []*ec2.Snapshot{snapshot}}, nil).AnyTimes() | ||
} | ||
|
||
if tc.cleanUpFailedVolume == true { | ||
mockEC2.EXPECT().DeleteVolumeWithContext(gomock.Eq(ctx), gomock.Any()).Return(&ec2.DeleteVolumeOutput{}, nil) | ||
} | ||
if len(tc.diskOptions.AvailabilityZone) == 0 { | ||
mockEC2.EXPECT().DescribeAvailabilityZonesWithContext(gomock.Eq(ctx), gomock.Any()).Return(&ec2.DescribeAvailabilityZonesOutput{ | ||
AvailabilityZones: []*ec2.AvailabilityZone{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So delete works if the volume is not available when we make the call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I did a test on my account. One concern here is if the deleteVolume call failed as well then we can not prevent the volume get leaked anyway..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that makes sense.