diff --git a/changelogs/unreleased/6544-allenxu404 b/changelogs/unreleased/6544-allenxu404 new file mode 100644 index 000000000..88b7f28a5 --- /dev/null +++ b/changelogs/unreleased/6544-allenxu404 @@ -0,0 +1 @@ +check if restore crd exist before operating restores \ No newline at end of file diff --git a/pkg/cmd/cli/uninstall/uninstall.go b/pkg/cmd/cli/uninstall/uninstall.go index 79ed048eb..ec2de648f 100644 --- a/pkg/cmd/cli/uninstall/uninstall.go +++ b/pkg/cmd/cli/uninstall/uninstall.go @@ -212,7 +212,18 @@ func deleteNamespace(ctx context.Context, kbClient kbclient.Client, namespace st } func deleteResourcesWithFinalizer(ctx context.Context, kbClient kbclient.Client, namespace string) error { - // delete restores + //check if restore crd exists + v1crd := &apiextv1.CustomResourceDefinition{} + key := kbclient.ObjectKey{Name: "restores.velero.io"} + if err := kbClient.Get(ctx, key, v1crd); err != nil { + if apierrors.IsNotFound(err) { + return nil + } else { + return err + } + } + + // delete all the restores restoreList := &velerov1api.RestoreList{} if err := kbClient.List(ctx, restoreList, &kbclient.ListOptions{Namespace: namespace}); err != nil { return err