Skip to content

Commit

Permalink
Drop Node event when EC2 instance does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
cartermckinnon committed Nov 27, 2023
1 parent 08ac6f0 commit 4a515e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions pkg/controllers/tagging/tagging_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,17 @@ func (tc *Controller) tagEc2Instance(node *v1.Node) error {
err := tc.cloud.TagResource(string(instanceID), tc.tags)

if err != nil {
if awsv1.IsAWSErrorInstanceNotFound(err) {
// This can happen for two reasons:
// 1. The CreateTags API is eventually consistent. In rare cases, a newly-created instance may not be taggable for a short period.
// 2. The event in our workQueue is stale, and the instance no longer exists. Tagging will never succeed.
//
// In either case, we don't return an error and requeue the current node event.
// In the first case, we will attempt tagging on the next node update event (in 5 minutes); which is an acceptable delay in the rare case.
// In the second case this would increase the workQueue size (causing higher dequeue latency for valid events).
klog.Infof("Skip tagging since EC2 instance %s for node %s does not exist", instanceID, node.GetName())
return nil
}
klog.Errorf("Error in tagging EC2 instance %s for node %s, error: %v", instanceID, node.GetName(), err)
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/v1/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ 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) {
if IsAWSErrorInstanceNotFound(err) {
return false, nil
}
return false, err
Expand Down Expand Up @@ -1946,7 +1946,7 @@ func (c *Cloud) GetZoneByNodeName(ctx context.Context, nodeName types.NodeName)

}

func isAWSErrorInstanceNotFound(err error) bool {
func IsAWSErrorInstanceNotFound(err error) bool {
if err == nil {
return false
}
Expand Down

0 comments on commit 4a515e7

Please sign in to comment.