@@ -2105,7 +2105,7 @@ func (c *Cloud) applyUnSchedulableTaint(nodeName types.NodeName, reason string)
2105
2105
2106
2106
// waitForAttachmentStatus polls until the attachment status is the expected value
2107
2107
// On success, it returns the last attachment state.
2108
- func (d * awsDisk ) waitForAttachmentStatus (status string , expectedDevice string ) (* ec2.VolumeAttachment , error ) {
2108
+ func (d * awsDisk ) waitForAttachmentStatus (status string , expectedInstance , expectedDevice string ) (* ec2.VolumeAttachment , error ) {
2109
2109
backoff := wait.Backoff {
2110
2110
Duration : volumeAttachmentStatusPollDelay ,
2111
2111
Factor : volumeAttachmentStatusFactor ,
@@ -2176,14 +2176,24 @@ func (d *awsDisk) waitForAttachmentStatus(status string, expectedDevice string)
2176
2176
if attachmentStatus == "" {
2177
2177
attachmentStatus = "detached"
2178
2178
}
2179
- if attachment != nil && expectedDevice != "" {
2179
+ if attachment != nil {
2180
+ // AWS eventual consistency can go back in time.
2181
+ // For example, we're waiting for a volume to be attached as /dev/xvdba, but AWS can tell us it's
2182
+ // attached as /dev/xvdbb, where it was attached before and it was already detached.
2183
+ // Retry couple of times, hoping AWS starts reporting the right status.
2180
2184
device := aws .StringValue (attachment .Device )
2181
- if device != "" && device != expectedDevice {
2182
- // AWS eventual consistency can go back in time.
2183
- // For example, we're waiting for a volume to be attached as /dev/xvdba, but AWS can tell us it's
2184
- // attached as /dev/xvdbb, where it was attached before and it was already detached.
2185
- // Retry couple of times, hoping AWS starts reporting the right status.
2186
- klog .Warningf ("Expected device %s %s, but found device %s %s" , expectedDevice , status , device , attachmentStatus )
2185
+ if expectedDevice != "" && device != "" && device != expectedDevice {
2186
+ klog .Warningf ("Expected device %s %s for volume %s, but found device %s %s" , expectedDevice , status , d .name , device , attachmentStatus )
2187
+ errorCount ++
2188
+ if errorCount > volumeAttachmentStatusConsecutiveErrorLimit {
2189
+ // report the error
2190
+ return false , fmt .Errorf ("attachment of disk %q failed: requested device %q but found %q" , d .name , expectedDevice , device )
2191
+ }
2192
+ return false , nil
2193
+ }
2194
+ instanceID := aws .StringValue (attachment .InstanceId )
2195
+ if expectedInstance != "" && instanceID != "" && instanceID != expectedInstance {
2196
+ klog .Warningf ("Expected instance %s/%s for volume %s, but found instance %s/%s" , expectedInstance , status , d .name , instanceID , attachmentStatus )
2187
2197
errorCount ++
2188
2198
if errorCount > volumeAttachmentStatusConsecutiveErrorLimit {
2189
2199
// report the error
@@ -2338,7 +2348,7 @@ func (c *Cloud) AttachDisk(diskName KubernetesVolumeID, nodeName types.NodeName)
2338
2348
klog .V (2 ).Infof ("AttachVolume volume=%q instance=%q request returned %v" , disk .awsID , awsInstance .awsID , attachResponse )
2339
2349
}
2340
2350
2341
- attachment , err := disk .waitForAttachmentStatus ("attached" , ec2Device )
2351
+ attachment , err := disk .waitForAttachmentStatus ("attached" , awsInstance . awsID , ec2Device )
2342
2352
2343
2353
if err != nil {
2344
2354
if err == wait .ErrWaitTimeout {
@@ -2416,7 +2426,7 @@ func (c *Cloud) DetachDisk(diskName KubernetesVolumeID, nodeName types.NodeName)
2416
2426
return "" , errors .New ("no response from DetachVolume" )
2417
2427
}
2418
2428
2419
- attachment , err := diskInfo .disk .waitForAttachmentStatus ("detached" , "" )
2429
+ attachment , err := diskInfo .disk .waitForAttachmentStatus ("detached" , awsInstance . awsID , "" )
2420
2430
if err != nil {
2421
2431
return "" , err
2422
2432
}
0 commit comments