Skip to content

Commit

Permalink
chore: Add retryable error to cloud provider (#1164)
Browse files Browse the repository at this point in the history
  • Loading branch information
jigisha620 authored Apr 4, 2024
1 parent 545d88a commit 702b524
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 25 additions & 2 deletions pkg/cloudprovider/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/controllers/nodeclaim/termination/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 702b524

Please sign in to comment.