diff --git a/pkg/cloudprovider/types.go b/pkg/cloudprovider/types.go index ee1fa1f496..c2e6957252 100644 --- a/pkg/cloudprovider/types.go +++ b/pkg/cloudprovider/types.go @@ -198,8 +198,8 @@ func IsNodeClaimNotFoundError(err error) bool { if err == nil { return false } - var mnfErr *NodeClaimNotFoundError - return errors.As(err, &mnfErr) + var ncnfErr *NodeClaimNotFoundError + return errors.As(err, &ncnfErr) } func IgnoreNodeClaimNotFoundError(err error) error { @@ -268,3 +268,26 @@ func IgnoreNodeClassNotReadyError(err error) error { } return err } + +// RetryableError is an error type returned by CloudProviders when the action emitting the error has to be retried +type RetryableError struct { + error +} + +func NewRetryableError(err error) *RetryableError { + return &RetryableError{ + error: err, + } +} + +func (e *RetryableError) Error() string { + return fmt.Sprintf("retryable error, %s", e.error) +} + +func IsRetryableError(err error) bool { + if err == nil { + return false + } + var retryableError *RetryableError + return errors.As(err, &retryableError) +} diff --git a/pkg/controllers/nodeclaim/termination/controller.go b/pkg/controllers/nodeclaim/termination/controller.go index 6e6b4f0d3a..373b518cee 100644 --- a/pkg/controllers/nodeclaim/termination/controller.go +++ b/pkg/controllers/nodeclaim/termination/controller.go @@ -89,7 +89,7 @@ func (c *Controller) Finalize(ctx context.Context, nodeClaim *v1beta1.NodeClaim) return reconcile.Result{}, nil } if nodeClaim.Status.ProviderID != "" { - if err = c.cloudProvider.Delete(ctx, nodeClaim); cloudprovider.IgnoreNodeClaimNotFoundError(err) != nil { + if err = c.cloudProvider.Delete(ctx, nodeClaim); cloudprovider.IgnoreNodeClaimNotFoundError(err) != nil || cloudprovider.IsRetryableError(err) { return reconcile.Result{}, fmt.Errorf("terminating cloudprovider instance, %w", err) } }