Skip to content

Commit cd34941

Browse files
authored
Merge pull request kubernetes#87839 from leakingtapan/cloud-provider
Fix aws provider to return no error when instance is not found for InstanceExistsByProviderID
2 parents 20e6883 + 2568b55 commit cd34941

File tree

1 file changed

+18
-0
lines changed
  • staging/src/k8s.io/legacy-cloud-providers/aws

1 file changed

+18
-0
lines changed

staging/src/k8s.io/legacy-cloud-providers/aws/aws.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,10 @@ func (c *Cloud) InstanceExistsByProviderID(ctx context.Context, providerID strin
15881588

15891589
instances, err := c.ec2.DescribeInstances(request)
15901590
if err != nil {
1591+
// if err is InstanceNotFound, return false with no error
1592+
if isAWSErrorInstanceNotFound(err) {
1593+
return false, nil
1594+
}
15911595
return false, err
15921596
}
15931597
if len(instances) == 0 {
@@ -1803,6 +1807,20 @@ func (c *Cloud) GetZoneByNodeName(ctx context.Context, nodeName types.NodeName)
18031807

18041808
}
18051809

1810+
func isAWSErrorInstanceNotFound(err error) bool {
1811+
if err == nil {
1812+
return false
1813+
}
1814+
1815+
if awsError, ok := err.(awserr.Error); ok {
1816+
if awsError.Code() == ec2.UnsuccessfulInstanceCreditSpecificationErrorCodeInvalidInstanceIdNotFound {
1817+
return true
1818+
}
1819+
}
1820+
1821+
return false
1822+
}
1823+
18061824
// Used to represent a mount device for attaching an EBS volume
18071825
// This should be stored as a single letter (i.e. c, not sdc or /dev/sdc)
18081826
type mountDevice string

0 commit comments

Comments
 (0)