Fix aws provider to return no error when instance is not found for InstanceExistsByProviderID

This commit is contained in:
Cheng Pan 2020-01-09 06:39:29 +00:00
parent b34c96b62c
commit 2568b552c8

View File

@ -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