mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #45049 from wongma7/volumeinuse
Automatic merge from submit-queue (batch tested with PRs 46686, 45049, 46323, 45708, 46487) Log an EBS vol's instance when attaching fails because VolumeInUse Messages now look something like this: E0427 15:44:37.617134 16932 attacher.go:73] Error attaching volume "vol-00095ddceae1a96ed": Error attaching EBS volume "vol-00095ddceae1a96ed" to instance "i-245203b7": VolumeInUse: vol-00095ddceae1a96ed is already attached to an instance status code: 400, request id: f510c439-64fe-43ea-b3ef-f496a5cd0577. The volume is currently attached to instance "i-072d9328131bcd9cd" weird that AWS doesn't bother to put that information in there for us (it does when you try to delete a vol that's in use) ```release-note NONE ```
This commit is contained in:
commit
43ac38e29e
@ -1522,6 +1522,28 @@ func (c *Cloud) getAwsInstance(nodeName types.NodeName) (*awsInstance, error) {
|
||||
return awsInstance, nil
|
||||
}
|
||||
|
||||
// wrapAttachError wraps the error returned by an AttachVolume request with
|
||||
// additional information, if needed and possible.
|
||||
func wrapAttachError(err error, disk *awsDisk, instance string) error {
|
||||
if awsError, ok := err.(awserr.Error); ok {
|
||||
if awsError.Code() == "VolumeInUse" {
|
||||
info, err := disk.describeVolume()
|
||||
if err != nil {
|
||||
glog.Errorf("Error describing volume %q: %v", disk.awsID, err)
|
||||
} else {
|
||||
for _, a := range info.Attachments {
|
||||
if disk.awsID != awsVolumeID(aws.StringValue(a.VolumeId)) {
|
||||
glog.Warningf("Expected to get attachment info of volume %q but instead got info of %q", disk.awsID, aws.StringValue(a.VolumeId))
|
||||
} else if aws.StringValue(a.State) == "attached" {
|
||||
return fmt.Errorf("Error attaching EBS volume %q to instance %q: %v. The volume is currently attached to instance %q", disk.awsID, instance, awsError, aws.StringValue(a.InstanceId))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("Error attaching EBS volume %q to instance %q: %v", disk.awsID, instance, err)
|
||||
}
|
||||
|
||||
// AttachDisk implements Volumes.AttachDisk
|
||||
func (c *Cloud) AttachDisk(diskName KubernetesVolumeID, nodeName types.NodeName, readOnly bool) (string, error) {
|
||||
disk, err := newAWSDisk(c, diskName)
|
||||
@ -1578,7 +1600,7 @@ func (c *Cloud) AttachDisk(diskName KubernetesVolumeID, nodeName types.NodeName,
|
||||
if err != nil {
|
||||
attachEnded = true
|
||||
// TODO: Check if the volume was concurrently attached?
|
||||
return "", fmt.Errorf("Error attaching EBS volume %q to instance %q: %v", disk.awsID, awsInstance.awsID, err)
|
||||
return "", wrapAttachError(err, disk, awsInstance.awsID)
|
||||
}
|
||||
if da, ok := c.deviceAllocators[awsInstance.nodeName]; ok {
|
||||
da.Deprioritize(mountDevice)
|
||||
|
Loading…
Reference in New Issue
Block a user