From 266b75558f6c9b2967e274b71bde60c780a8f1f5 Mon Sep 17 00:00:00 2001 From: Oksana Grishchenko <91597950+oksana-grishchenko@users.noreply.github.com> Date: Wed, 13 Sep 2023 19:01:40 +0200 Subject: [PATCH] EVEREST-312 Repeated deletion fix (#133) EVEREST-312 handle repeated deletion --- cli-tests/tests/flow/all-operators.spec.ts | 9 +++++++++ pkg/delete/cluster.go | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/cli-tests/tests/flow/all-operators.spec.ts b/cli-tests/tests/flow/all-operators.spec.ts index 2932111d..d7a24475 100644 --- a/cli-tests/tests/flow/all-operators.spec.ts +++ b/cli-tests/tests/flow/all-operators.spec.ts @@ -61,6 +61,15 @@ test.describe('Everest CLI install operators', async () => { await verifyClusterResources(); await apiVerifyClusterExists(request, clusterName); await cliDeleteCluster(cli, request, clusterName); + + await test.step('try to delete cluster again', async () => { + const out = await cli.everestExecSilent('delete cluster'); + + await out.exitCodeEquals(1); + await out.outErrContainsNormalizedMany([ + 'no Kubernetes clusters found', + ]); + }); await verifyClusterResources(); }); }); diff --git a/pkg/delete/cluster.go b/pkg/delete/cluster.go index 48246d8e..7e314ea9 100644 --- a/pkg/delete/cluster.go +++ b/pkg/delete/cluster.go @@ -174,6 +174,12 @@ func (c *Cluster) askForKubernetesCluster(ctx context.Context) error { return err } + if len(clusters) == 0 { + l := c.l.WithOptions(zap.AddStacktrace(zap.DPanicLevel)) + l.Error("no Kubernetes clusters found") + return common.ErrExitWithError + } + opts := make([]string, 0, len(clusters)+1) for _, i := range clusters { opts = append(opts, i.Name)