Skip to content

Commit

Permalink
fix: when delete resource if no CRD in the cluster (#1044)
Browse files Browse the repository at this point in the history
Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw authored Jun 7, 2024
1 parent bd9b83c commit c040f77
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c040f77

Please sign in to comment.