diff options
author | Harald Musum <musum@yahooinc.com> | 2023-08-31 08:20:29 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2023-08-31 08:20:29 +0200 |
commit | b9030618968866c273abcc9c8a3f4dd18425c99f (patch) | |
tree | c3ef5788c15cea2eede7dfc89f50e6cb3a3c6dd0 /client | |
parent | 41ff938521ec0ddd45d273a7fbe6618403f6dadf (diff) |
destroy is only allowed for Vespa Cloud
Diffstat (limited to 'client')
-rw-r--r-- | client/go/internal/cli/cmd/destroy.go | 14 | ||||
-rw-r--r-- | client/go/internal/cli/cmd/destroy_test.go | 29 |
2 files changed, 29 insertions, 14 deletions
diff --git a/client/go/internal/cli/cmd/destroy.go b/client/go/internal/cli/cmd/destroy.go index 4df81179318..ca69f21a9b4 100644 --- a/client/go/internal/cli/cmd/destroy.go +++ b/client/go/internal/cli/cmd/destroy.go @@ -22,9 +22,13 @@ When run interactively, the command will prompt for confirmation before removing the application. When run non-interactively, the command will refuse to remove the application unless the --force option is given. -This command cannot be used to remove production deployments in Vespa Cloud. See -https://cloud.vespa.ai/en/deleting-applications for how to remove production -deployments. +This command can only be used to remove non-production deployments. See +https://cloud.vespa.ai/en/deleting-applications for how to remove +production deployments. This command can only be used for deployments to +Vespa Cloud, for other systems destroy an application by cleaning up +containers in use by the application, see e.g +https://github.com/vespa-engine/sample-apps/tree/master/examples/operations/multinode-HA#clean-up-after-testing + `, Example: `$ vespa destroy $ vespa destroy -a mytenant.myapp.myinstance @@ -37,7 +41,9 @@ $ vespa destroy --force`, return err } description := target.Deployment().String() - if target.IsCloud() { + if !target.IsCloud() { + return errHint(fmt.Errorf("cannot remove deployment, only supported for Vespa Cloud")) + } else { env := target.Deployment().Zone.Environment if env != "dev" && env != "perf" { return errHint(fmt.Errorf("cannot remove production %s", description), "See https://cloud.vespa.ai/en/deleting-applications") diff --git a/client/go/internal/cli/cmd/destroy_test.go b/client/go/internal/cli/cmd/destroy_test.go index 3cc106fb83c..b23e524e0ab 100644 --- a/client/go/internal/cli/cmd/destroy_test.go +++ b/client/go/internal/cli/cmd/destroy_test.go @@ -19,33 +19,42 @@ func TestDestroy(t *testing.T) { var buf bytes.Buffer cli.Stdin = &buf + require.Nil(t, cli.Run("config", "set", "target", "cloud")) + require.Nil(t, cli.Run("config", "set", "application", "foo.bar.baz")) + require.Nil(t, cli.Run("auth", "api-key")) + // No removal without confirmation + stdout.Reset() + stderr.Reset() buf.WriteString("\n") - require.NotNil(t, cli.Run("destroy")) - warning := "Warning: This operation will irrecoverably remove the deployment of default.application.default in prod.default and all of its data" + require.NotNil(t, cli.Run("destroy", "-z", "dev.aws-us-east-1c")) + warning := "Warning: This operation will irrecoverably remove the deployment of foo.bar.baz in dev.aws-us-east-1c and all of its data" confirmation := "Proceed with removal? [y/N] " - assert.Equal(t, warning+"\nError: refusing to remove deployment of default.application.default in prod.default without confirmation\n", stderr.String()) + assert.Equal(t, warning+"\nError: refusing to remove deployment of foo.bar.baz in dev.aws-us-east-1c without confirmation\n", stderr.String()) assert.Equal(t, confirmation, stdout.String()) // Removes deployment with confirmation stdout.Reset() stderr.Reset() buf.WriteString("y\n") - require.Nil(t, cli.Run("destroy")) - success := "Success: Removed deployment of default.application.default in prod.default\n" + require.Nil(t, cli.Run("destroy", "-z", "dev.aws-us-east-1c")) + success := "Success: Removed deployment of foo.bar.baz in dev.aws-us-east-1c\n" assert.Equal(t, confirmation+success, stdout.String()) // Force flag always removes deployment stdout.Reset() stderr.Reset() - require.Nil(t, cli.Run("destroy", "--force")) + require.Nil(t, cli.Run("destroy", "-z", "dev.aws-us-east-1c", "--force")) assert.Equal(t, success, stdout.String()) - // Cannot remove prod deployment in Vespa Cloud + // Cannot remove a prod deployment + require.NotNil(t, cli.Run("destroy", "-z", "prod.aws-us-east-1c")) + assert.Equal(t, "Error: cannot remove production deployment of foo.bar.baz in prod.aws-us-east-1c\nHint: See https://cloud.vespa.ai/en/deleting-applications\n", stderr.String()) + + // Cannot remove a local deployment at all stderr.Reset() - require.Nil(t, cli.Run("config", "set", "target", "cloud")) + require.Nil(t, cli.Run("config", "set", "target", "local")) require.Nil(t, cli.Run("config", "set", "application", "foo.bar.baz")) - require.Nil(t, cli.Run("auth", "api-key")) require.NotNil(t, cli.Run("destroy", "-z", "prod.aws-us-east-1c")) - assert.Equal(t, "Error: cannot remove production deployment of foo.bar.baz in prod.aws-us-east-1c\nHint: See https://cloud.vespa.ai/en/deleting-applications\n", stderr.String()) + assert.Equal(t, "Error: cannot remove deployment, only supported for Vespa Cloud\n", stderr.String()) } |