diff --git a/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go b/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go index 8e67eb7e459..4e620deec03 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go +++ b/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go @@ -1588,6 +1588,10 @@ func (c *Cloud) InstanceExistsByProviderID(ctx context.Context, providerID strin instances, err := c.ec2.DescribeInstances(request) if err != nil { + // if err is InstanceNotFound, return false with no error + if isAWSErrorInstanceNotFound(err) { + return false, nil + } return false, err } if len(instances) == 0 { @@ -1803,6 +1807,20 @@ func (c *Cloud) GetZoneByNodeName(ctx context.Context, nodeName types.NodeName) } +func isAWSErrorInstanceNotFound(err error) bool { + if err == nil { + return false + } + + if awsError, ok := err.(awserr.Error); ok { + if awsError.Code() == ec2.UnsuccessfulInstanceCreditSpecificationErrorCodeInvalidInstanceIdNotFound { + return true + } + } + + return false +} + // Used to represent a mount device for attaching an EBS volume // This should be stored as a single letter (i.e. c, not sdc or /dev/sdc) type mountDevice string