From c040f77a87521060becf62c2424c39dcb9551458 Mon Sep 17 00:00:00 2001 From: Wen Zhou Date: Fri, 7 Jun 2024 17:28:52 +0200 Subject: [PATCH] fix: when delete resource if no CRD in the cluster (#1044) Signed-off-by: Wen Zhou --- pkg/deploy/deploy.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/deploy/deploy.go b/pkg/deploy/deploy.go index c2b08e1e90f..4279f11e20d 100644 --- a/pkg/deploy/deploy.go +++ b/pkg/deploy/deploy.go @@ -32,6 +32,7 @@ import ( "strings" "golang.org/x/exp/maps" + "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/types" @@ -209,7 +210,7 @@ func manageResource(ctx context.Context, cli client.Client, obj *unstructured.Un // Return if error getting resource in cluster found, err := getResource(ctx, cli, obj) - if client.IgnoreNotFound(err) != nil { + if err != nil { return err } @@ -357,8 +358,13 @@ func getResource(ctx context.Context, cli client.Client, obj *unstructured.Unstr found := &unstructured.Unstructured{} // Setting gvk is required to do Get request found.SetGroupVersionKind(obj.GroupVersionKind()) - err := cli.Get(ctx, types.NamespacedName{Name: obj.GetName(), Namespace: obj.GetNamespace()}, found) - if err != nil { + if err := cli.Get(ctx, types.NamespacedName{Name: obj.GetName(), Namespace: obj.GetNamespace()}, found); err != nil { + if errors.Is(err, &meta.NoKindMatchError{}) { + return nil, nil // ignore mising CRD error + } + if client.IgnoreNotFound(err) == nil { + return nil, nil // not found resource + } return nil, err } return found, nil