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

Automated cherry pick of #14493 #18559

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion pkg/cloudprovider/providers/aws/aws.go
Expand Up @@ -1118,7 +1118,7 @@ func (aws *AWSCloud) AttachDisk(instanceName string, diskName string, readOnly b
attached := false
defer func() {
if !attached {
awsInstance.releaseMountDevice(disk.awsID, ec2Device)
awsInstance.releaseMountDevice(disk.awsID, mountpoint)
}
}()

Expand Down Expand Up @@ -1166,6 +1166,24 @@ func (aws *AWSCloud) DetachDisk(instanceName string, diskName string) error {
if response == nil {
return errors.New("no response from DetachVolume")
}

// At this point we are waiting for the volume being detached. This
// releases the volume and invalidates the cache even when there is a timeout.
//
// TODO: A timeout leaves the cache in an inconsistent state. The volume is still
// detaching though the cache shows it as ready to be attached again. Subsequent
// attach operations will fail. The attach is being retried and eventually
// works though. An option would be to completely flush the cache upon timeouts.
//
defer func() {
for mountDevice, existingVolumeID := range awsInstance.deviceMappings {
if existingVolumeID == disk.awsID {
awsInstance.releaseMountDevice(disk.awsID, mountDevice)
return
}
}
}()

err = disk.waitForAttachmentStatus("detached")
if err != nil {
return err
Expand Down