Skip to content
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

Merged

Conversation

AndyXiangLi
Copy link
Contributor

Is this a bug fix or adding new feature?
Fixes #754
What is this PR about? / Why do we need it?
Delete volume if the driver don't know about the volume status after creation
What testing is done?
Could see this log after denying DescribeVolume api call manually
volume is deleted because it is not in desired state within retry limit
Added unit test

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 25, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @AndyXiangLi. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 25, 2021
@coveralls
Copy link

coveralls commented Feb 25, 2021

Pull Request Test Coverage Report for Build 1641

  • 6 of 7 (85.71%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 81.712%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/cloud/cloud.go 6 7 85.71%
Totals Coverage Status
Change from base Build 1636: 0.1%
Covered Lines: 1747
Relevant Lines: 2138

💛 - Coveralls

@AndyXiangLi AndyXiangLi force-pushed the delete-volume-on-leak branch from 5bd9df3 to 82a2c99 Compare February 25, 2021 21:47
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 25, 2021
@AndyXiangLi AndyXiangLi force-pushed the delete-volume-on-leak branch from 82a2c99 to 064215b Compare February 25, 2021 21:52
@wongma7
Copy link
Contributor

wongma7 commented Feb 25, 2021

/ok-to-test
/approve

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 25, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AndyXiangLi, wongma7

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 25, 2021
@@ -194,7 +195,8 @@ func TestCreateDisk(t *testing.T) {
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"),
Copy link
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -343,6 +343,13 @@ func (c *cloud) CreateDisk(ctx context.Context, volumeName string, diskOptions *
}

if err := c.waitForVolume(ctx, volumeID); err != nil {
// To avoid leaking volume, we should delete the volume just created
// TODO: Need to figure out how to handle DeleteDisk failed scenario instead of just log the error
if _, error := c.DeleteDisk(ctx, volumeID); error != nil {
Copy link
Contributor

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?

Copy link
Contributor Author

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..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that makes sense.

@AndyXiangLi AndyXiangLi force-pushed the delete-volume-on-leak branch from 064215b to 5b2faf9 Compare February 25, 2021 22:57
@ayberk
Copy link
Contributor

ayberk commented Feb 25, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 25, 2021
@k8s-ci-robot k8s-ci-robot merged commit 69000c9 into kubernetes-sigs:master Feb 26, 2021
@AndyXiangLi
Copy link
Contributor Author

Cherry pick upstream fix back to v1.21
kubernetes/kubernetes#100934

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Volumes may leak during Create operation: Delete/clean volume if waitForVolume fails during Create operation
5 participants