mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 08:17:26 +00:00
Log an EBS vol's instance when attaching fails because VolumeInUse
This commit is contained in:
parent
becd626c8e
commit
9afbb356de
@ -1490,6 +1490,28 @@ func (c *Cloud) getAwsInstance(nodeName types.NodeName) (*awsInstance, error) {
|
|||||||
return awsInstance, nil
|
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
|
// AttachDisk implements Volumes.AttachDisk
|
||||||
func (c *Cloud) AttachDisk(diskName KubernetesVolumeID, nodeName types.NodeName, readOnly bool) (string, error) {
|
func (c *Cloud) AttachDisk(diskName KubernetesVolumeID, nodeName types.NodeName, readOnly bool) (string, error) {
|
||||||
disk, err := newAWSDisk(c, diskName)
|
disk, err := newAWSDisk(c, diskName)
|
||||||
@ -1546,7 +1568,7 @@ func (c *Cloud) AttachDisk(diskName KubernetesVolumeID, nodeName types.NodeName,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
attachEnded = true
|
attachEnded = true
|
||||||
// TODO: Check if the volume was concurrently attached?
|
// 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 {
|
if da, ok := c.deviceAllocators[awsInstance.nodeName]; ok {
|
||||||
da.Deprioritize(mountDevice)
|
da.Deprioritize(mountDevice)
|
||||||
|
Loading…
Reference in New Issue
Block a user