mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-06-19 11:44:20 -04:00
operators: ignore node deletion errors on absence (#3113)
* operators: ignore node deletion errors on absence
This commit is contained in:
parent
71fe73a076
commit
902b7f49a8
3 changed files with 20 additions and 2 deletions
|
@ -9,6 +9,7 @@ package client
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
|
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
|
||||||
|
@ -207,7 +208,7 @@ func (c *Client) DeleteNode(ctx context.Context, providerID string) error {
|
||||||
ShouldDecrementDesiredCapacity: toPtr(true),
|
ShouldDecrementDesiredCapacity: toPtr(true),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil && !isInstanceNotFoundError(err) {
|
||||||
return fmt.Errorf("failed to terminate instance: %w", err)
|
return fmt.Errorf("failed to terminate instance: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,3 +218,10 @@ func (c *Client) DeleteNode(ctx context.Context, providerID string) error {
|
||||||
func toPtr[T any](v T) *T {
|
func toPtr[T any](v T) *T {
|
||||||
return &v
|
return &v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isInstanceNotFoundError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return strings.Contains(err.Error(), "Instance Id not found")
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
|
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
|
||||||
|
@ -382,6 +383,10 @@ func TestDeleteNode(t *testing.T) {
|
||||||
terminateInstanceErr: assert.AnError,
|
terminateInstanceErr: assert.AnError,
|
||||||
wantErr: true,
|
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 {
|
for name, tc := range testCases {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
|
|
@ -139,7 +139,8 @@ func (c *Client) DeleteNode(ctx context.Context, providerID string) error {
|
||||||
Project: instanceGroupProject,
|
Project: instanceGroupProject,
|
||||||
Zone: instanceGroupZone,
|
Zone: instanceGroupZone,
|
||||||
InstanceGroupManagersDeleteInstancesRequestResource: &computepb.InstanceGroupManagersDeleteInstancesRequest{
|
InstanceGroupManagersDeleteInstancesRequestResource: &computepb.InstanceGroupManagersDeleteInstancesRequest{
|
||||||
Instances: []string{instanceID},
|
Instances: []string{instanceID},
|
||||||
|
SkipInstancesOnValidationError: toPtr(true),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -147,3 +148,7 @@ func (c *Client) DeleteNode(ctx context.Context, providerID string) error {
|
||||||
}
|
}
|
||||||
return op.Wait(ctx)
|
return op.Wait(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toPtr[T any](v T) *T {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue