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)