Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operators: ignore node deletion errors on absence #3113

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package client
import (
"context"
"fmt"
"strings"
"time"

"github.com/aws/aws-sdk-go-v2/service/autoscaling"
Expand Down Expand Up @@ -207,7 +208,7 @@ func (c *Client) DeleteNode(ctx context.Context, providerID string) error {
ShouldDecrementDesiredCapacity: toPtr(true),
},
)
if err != nil {
if err != nil && !isInstanceNotFoundError(err) {
return fmt.Errorf("failed to terminate instance: %w", err)
}

Expand All @@ -217,3 +218,10 @@ func (c *Client) DeleteNode(ctx context.Context, providerID string) error {
func toPtr[T any](v T) *T {
return &v
}

func isInstanceNotFoundError(err error) bool {
if err == nil {
return false
}
return strings.Contains(err.Error(), "Instance Id not found")
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package client

import (
"context"
"fmt"
"testing"

"github.com/aws/aws-sdk-go-v2/service/autoscaling"
Expand Down Expand Up @@ -382,6 +383,10 @@ func TestDeleteNode(t *testing.T) {
terminateInstanceErr: assert.AnError,
wantErr: true,
},
"deleting node succeeds when the instance does not exist": {
providerID: "aws:///us-east-2a/i-00000000000000000",
terminateInstanceErr: fmt.Errorf("Instance Id not found - No managed instance found for instance ID: i-00000000000000000"),
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,16 @@ func (c *Client) DeleteNode(ctx context.Context, providerID string) error {
Project: instanceGroupProject,
Zone: instanceGroupZone,
InstanceGroupManagersDeleteInstancesRequestResource: &computepb.InstanceGroupManagersDeleteInstancesRequest{
Instances: []string{instanceID},
Instances: []string{instanceID},
SkipInstancesOnValidationError: toPtr(true),
},
})
if err != nil {
return fmt.Errorf("deleting instance %q from instance group manager %q: %w", instanceID, scalingGroupID, err)
}
return op.Wait(ctx)
}

func toPtr[T any](v T) *T {
return &v
}
Loading