-
Notifications
You must be signed in to change notification settings - Fork 20
/
kube_delete.go
55 lines (43 loc) · 1.1 KB
/
kube_delete.go
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
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// kubeDeleteCmd represents the delete command
var kubeDeleteCmd = &cobra.Command{
Use: "delete <cluster name>",
Short: "Delete a standalone Kubernetes cluster instance",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
clusterName := args[0]
vm, err := getKubeVM(clusterName)
if err != nil {
return err
}
force, err := cmd.Flags().GetBool("force")
if err != nil {
return err
}
if !force {
if !askQuestion(fmt.Sprintf("sure you want to delete %q cluster instance", vm.Name)) {
return nil
}
}
fmt.Printf("Destroying cluster instance... ")
if err := cs.DeleteWithContext(gContext, vm); err != nil {
fmt.Println("instance deletion failed")
return err
}
fmt.Println("done")
if err := deleteKeyPair(*vm.ID); err != nil {
return err
}
return deleteKubeData(clusterName)
},
}
func init() {
kubeDeleteCmd.Flags().BoolP("force", "f", false, "Attempt to remove cluster instance without prompting for confirmation")
kubeCmd.AddCommand(kubeDeleteCmd)
}