From 6dbdc54dc75d266e213b95c6406da60bbb1a4e75 Mon Sep 17 00:00:00 2001 From: allenxu404 Date: Tue, 25 Jul 2023 18:45:45 +0800 Subject: [PATCH] check if restore crd exist before operating restore Signed-off-by: allenxu404 --- changelogs/unreleased/6544-allenxu404 | 1 + pkg/cmd/cli/uninstall/uninstall.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/6544-allenxu404 diff --git a/changelogs/unreleased/6544-allenxu404 b/changelogs/unreleased/6544-allenxu404 new file mode 100644 index 0000000000..88b7f28a58 --- /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 79ed048eb3..ec2de648fc 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