Repository navigation
Expand file tree
/
Copy pathdestroy.go
More file actions
59 lines (48 loc) · 1.55 KB
/
Copy pathdestroy.go
File metadata and controls
59 lines (48 loc) · 1.55 KB
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
package cmd
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/kubernetes-incubator/kube-aws/core/root"
"github.com/kubernetes-incubator/kube-aws/logger"
)
var (
cmdDestroy = &cobra.Command{
Use: "destroy",
Short: "Destroy an existing Kubernetes cluster",
Long: ``,
RunE: runCmdDestroy,
SilenceUsage: true,
}
destroyOpts = root.DestroyOptions{}
)
func init() {
RootCmd.AddCommand(cmdDestroy)
cmdDestroy.Flags().StringVar(&destroyOpts.Profile, "profile", "", "The AWS profile to use from credentials file")
cmdDestroy.Flags().BoolVar(&destroyOpts.AwsDebug, "aws-debug", false, "Log debug information from aws-sdk-go library")
cmdDestroy.Flags().BoolVar(&destroyOpts.Force, "force", false, "Don't ask for confirmation")
}
func runCmdDestroy(_ *cobra.Command, _ []string) error {
if !destroyOpts.Force && !destroyConfirmation() {
logger.Info("Operation Cancelled")
return nil
}
c, err := root.ClusterDestroyerFromFile(configPath, destroyOpts)
if err != nil {
return fmt.Errorf("error parsing config: %v", err)
}
if err := c.Destroy(); err != nil {
return fmt.Errorf("failed destroying cluster: %v", err)
}
logger.Info("CloudFormation stack is being destroyed. This will take several minutes")
return nil
}
func destroyConfirmation() bool {
reader := bufio.NewReader(os.Stdin)
fmt.Print("This operation will destroy the cluster. Are you sure? [y,n]: ")
text, _ := reader.ReadString('\n')
text = strings.TrimSuffix(strings.ToLower(text), "\n")
return text == "y" || text == "yes"
}