Skip to content

Commit

Permalink
Fixed bug in aws cloudprovider where Terminating non-existent instanc…
Browse files Browse the repository at this point in the history
…es triggered an error and prevented k8s nodes to be deleted from api server (#553)
  • Loading branch information
bwagner5 committed Jul 26, 2021
1 parent 0ef608c commit 6a67e3a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/cloudprovider/aws/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ import (
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/awslabs/karpenter/pkg/cloudprovider"
"go.uber.org/multierr"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
)

const (
EC2InstanceIDNotFoundErrCode = "InvalidInstanceID.NotFound"
)

type InstanceProvider struct {
Expand Down Expand Up @@ -112,7 +116,10 @@ func (p *InstanceProvider) Terminate(ctx context.Context, node *v1.Node) error {
}
if _, err = p.ec2api.TerminateInstancesWithContext(ctx, &ec2.TerminateInstancesInput{
InstanceIds: []*string{id},
}); err != nil && !errors.IsNotFound(err) {
}); err != nil {
if aerr, ok := err.(awserr.Error); ok && aerr.Code() == EC2InstanceIDNotFoundErrCode {
return nil
}
return fmt.Errorf("terminating instance %s, %w", node.Name, err)
}
return nil
Expand Down

0 comments on commit 6a67e3a

Please sign in to comment.