diff --git a/cli/cmd/uninstall/uninstall.go b/cli/cmd/uninstall/uninstall.go index 80ce278af2..8431008754 100644 --- a/cli/cmd/uninstall/uninstall.go +++ b/cli/cmd/uninstall/uninstall.go @@ -423,11 +423,11 @@ func (c *Command) removeCustomResources(uiLogger action.DebugLog) error { return err } if len(crs) != 0 { - return common.NewDeletionError(fmt.Sprintf("%d custom resources remain after deletion request. Retrying deletion", len(crs))) + return common.NewDanglingResourceError(fmt.Sprintf("%d custom resources remain after deletion request", len(crs))) } return nil }, backoff.WithMaxRetries(backoff.NewConstantBackOff(time.Second), 5)) - if !common.IsDeletionError(err) { + if !common.IsDanglingResourceError(err) { return err } @@ -443,12 +443,18 @@ func (c *Command) removeCustomResources(uiLogger action.DebugLog) error { return err } - crs, err = c.fetchCustomResources(crds) + err = backoff.Retry(func() error { + crs, err := c.fetchCustomResources(crds) + if err != nil { + return err + } + if len(crs) != 0 { + return common.NewDanglingResourceError(fmt.Sprintf("%d custom resources remain after request to patch finalizers", len(crs))) + } + return nil + }, backoff.WithMaxRetries(backoff.NewConstantBackOff(time.Second), 5)) if err != nil { - return err - } - if len(crs) != 0 { - return fmt.Errorf("unable to remove all custom resources managed by Consul. %d custom resources remain and will need to be removed manually", len(crs)) + return fmt.Errorf("unable to remove all custom resources managed by Consul. %d custom resources remain and will need to be removed manually. %v", len(crs), err) } return nil diff --git a/cli/common/error.go b/cli/common/error.go index 7901e09b56..3d8e3deb51 100644 --- a/cli/common/error.go +++ b/cli/common/error.go @@ -1,24 +1,25 @@ package common -// DeletionError should be used when a request was made to delete a resource -// and that request failed. -type DeletionError struct { +// DanglingResourceError should be used when a request was made to remove +// a resource and the resource still remains after enough time has elapsed +// that it should have been removed by Kubernetes. +type DanglingResourceError struct { message string } -// NewDeletionError returns a new instance of DeletionError for handling -// failures in deletion requests. -func NewDeletionError(message string) *DeletionError { - return &DeletionError{message} +// NewDanglingResourceError returns a new instance of DanglingResourceError with +// the given message. +func NewDanglingResourceError(message string) *DanglingResourceError { + return &DanglingResourceError{message} } -// Error returns a string representation of the deletion error. -func (d *DeletionError) Error() string { +// Error returns a string representation of the dangling resource error. +func (d *DanglingResourceError) Error() string { return d.message } -// IsDeletionError returns true if the error passed in is of type DeletionError. -func IsDeletionError(err error) bool { - _, ok := err.(*DeletionError) +// IsDanglingResourceError returns true if the error passed in is of type DanglingResourceError. +func IsDanglingResourceError(err error) bool { + _, ok := err.(*DanglingResourceError) return ok }