forked from coreos/coreos-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_destroy.go
48 lines (38 loc) · 948 Bytes
/
command_destroy.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
package main
import (
"fmt"
"os"
"path"
"github.com/spf13/cobra"
"github.com/coreos/coreos-kubernetes/multi-node/aws/pkg/cluster"
)
var (
cmdDestroy = &cobra.Command{
Use: "destroy",
Short: "Destroy an existing Kubernetes cluster",
Long: ``,
Run: runCmdDestroy,
}
)
func init() {
cmdRoot.AddCommand(cmdDestroy)
}
func runCmdDestroy(cmd *cobra.Command, args []string) {
cfg := cluster.NewDefaultConfig(VERSION)
err := cluster.DecodeConfigFromFile(cfg, rootOpts.ConfigPath)
if err != nil {
stderr("Unable to load cluster config: %v", err)
os.Exit(1)
}
c := cluster.New(cfg, newAWSConfig(cfg))
if err := c.Destroy(); err != nil {
stderr("Failed destroying cluster: %v", err)
os.Exit(1)
}
clusterDir := path.Join("clusters", cfg.ClusterName)
if err := os.RemoveAll(clusterDir); err != nil {
stderr("Failed removing local cluster directory: %v", err)
os.Exit(1)
}
fmt.Println("Destroyed cluster")
}