aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/cli/cmd/destroy.go
blob: 51040c0af8ba91aa77b1dad8dc3b87e8d6ece8f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package cmd

import (
	"fmt"

	"github.com/fatih/color"
	"github.com/spf13/cobra"
	"github.com/vespa-engine/vespa/client/go/internal/vespa"
)

func newDestroyCmd(cli *CLI) *cobra.Command {
	force := false
	cmd := &cobra.Command{
		Use:   "destroy",
		Short: "Remove a deployed Vespa application and its data",
		Long: `Remove a deployed Vespa application and its data.

This command removes the currently deployed application and permanently
deletes its data.

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 can only be used to remove non-production deployments, in Vespa
Cloud. See https://cloud.vespa.ai/en/deleting-applications for how to remove
production deployments.

For other systems, destroy the application by removing the
containers in use by the application. For example:
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
$ vespa destroy --force`,
		DisableAutoGenTag: true,
		SilenceUsage:      true,
		RunE: func(cmd *cobra.Command, args []string) error {
			target, err := cli.target(targetOptions{supportedType: cloudTargetOnly})
			if err != nil {
				return err
			}
			description := target.Deployment().String()
			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")
			}
			ok := force
			if !ok {
				cli.printWarning(fmt.Sprintf("This operation will irrecoverably remove the %s and all of its data", color.RedString(description)))
				ok, _ = cli.confirm("Proceed with removal?", false)
			}
			if ok {
				err := vespa.Deactivate(vespa.DeploymentOptions{Target: target})
				if err == nil {
					cli.printSuccess(fmt.Sprintf("Removed %s", description))
				}
				return err
			}
			return fmt.Errorf("refusing to remove %s without confirmation", description)
		},
	}
	cmd.PersistentFlags().BoolVar(&force, "force", false, "Disable confirmation (default false)")
	return cmd
}