diff --git a/vendor/k8s.io/kubernetes/pkg/cloudprovider/providers/aws/aws.go b/vendor/k8s.io/kubernetes/pkg/cloudprovider/providers/aws/aws.go index 2132ccc0eebe..f18274bf9552 100644 --- a/vendor/k8s.io/kubernetes/pkg/cloudprovider/providers/aws/aws.go +++ b/vendor/k8s.io/kubernetes/pkg/cloudprovider/providers/aws/aws.go @@ -1475,6 +1475,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) @@ -1531,7 +1553,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)