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

Fix deletion of resources with deleted CRDs #778

Merged
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
12 changes: 12 additions & 0 deletions pkg/reconcilermanager/controllers/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ func (ooe *ObjectOperationError) Error() string {
ooe.ID.Kind, ooe.ID.ObjectKey, ooe.Operation, ooe.Cause)
}

// Unwrap returns the cause of the error, to allow type checking with errors.Is
// and errors.As.
func (ooe *ObjectOperationError) Unwrap() error {
return ooe.Cause
}

// NewObjectOperationError constructs a new ObjectOperationError
func NewObjectOperationError(err error, obj client.Object, op Operation) *ObjectOperationError {
id := core.IDOf(obj)
Expand Down Expand Up @@ -144,6 +150,12 @@ func (oripe *ObjectReconcileError) Error() string {
oripe.ID.Kind, oripe.ID.ObjectKey, oripe.Status, oripe.Cause)
}

// Unwrap returns the cause of the error, to allow type checking with errors.Is
// and errors.As.
func (oripe *ObjectReconcileError) Unwrap() error {
return oripe.Cause
}

// NewObjectReconcileError constructs a new ObjectReconcileError
func NewObjectReconcileError(err error, obj client.Object, status kstatus.Status) *ObjectReconcileError {
id := core.IDOf(obj)
Expand Down
8 changes: 8 additions & 0 deletions pkg/util/watch/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -166,6 +167,13 @@ func DeleteAndWait(ctx context.Context, c client.WithWatch, obj client.Object, r
// Stop waiting - object already deleted
return true, nil
}
if meta.IsNoMatchError(err) {
klog.V(3).Infof("Resource not registered %q=%q, %q=%q",
logFieldObjectRef, id.ObjectKey.String(),
logFieldObjectKind, id.Kind)
// Stop waiting - resource not registered
return true, nil
}
// Stop waiting
return false, err
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/watch/until.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ func UntilDeletedWithSync(ctx context.Context, c client.WithWatch, obj client.Ob
if err != nil {
return err
}
// Validate that the resource API is registered.
// If not, error and let the caller deal with whether NoMatchError is
// tolerated or not.
// Without this check, the informer will retry endlessly waiting for the
// ListAndWatch to succeed.
_, err = c.RESTMapper().RESTMapping(itemGVK.GroupKind(), itemGVK.Version)
if err != nil {
return err
}
var objList client.ObjectList
if _, ok := obj.(*unstructured.Unstructured); ok {
objList = kinds.NewUnstructuredListForItemGVK(itemGVK)
Expand Down