Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
Ask for confirmation before destroy (#1178)
Browse files Browse the repository at this point in the history
Closes #1165
  • Loading branch information
jorge07 authored and mumoshu committed Mar 12, 2018
1 parent 5e15ac9 commit 8bbf89d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -77,7 +77,7 @@ $ kube-aws update --s3-uri s3://<your-bucket>/<optional-prefix>
Destroy:

```
# Destroy all the cfn stacks including the one for control-plane and the ones for worker node pools
# Destroy all the cfn stacks including the one for control-plane and the ones for worker node pools. Use `--force` for skip confirmation.
$ kube-aws destroy
```

Expand Down
18 changes: 18 additions & 0 deletions cmd/destroy.go
@@ -1,7 +1,10 @@
package cmd

import (
"bufio"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"

Expand All @@ -22,9 +25,15 @@ var (
func init() {
RootCmd.AddCommand(cmdDestroy)
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(cmd *cobra.Command, args []string) error {
if !destroyOpts.Force && !destroyConfirmation() {
fmt.Printf("Operation Cancelled")
return nil
}

c, err := root.ClusterDestroyerFromFile(configPath, destroyOpts)
if err != nil {
return fmt.Errorf("Error parsing config: %v", err)
Expand All @@ -37,3 +46,12 @@ func runCmdDestroy(cmd *cobra.Command, args []string) error {
fmt.Println("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"
}
2 changes: 2 additions & 0 deletions core/root/destroyer.go
Expand Up @@ -2,6 +2,7 @@ package root

import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/kubernetes-incubator/kube-aws/cfnstack"
Expand All @@ -10,6 +11,7 @@ import (

type DestroyOptions struct {
AwsDebug bool
Force bool
}

type ClusterDestroyer interface {
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/step-7-destroy.md
@@ -1,5 +1,5 @@
## Destroy the cluster

When you are done with your cluster `kube-aws destroy` to destroy all the cluster components.
When you are done with your cluster `kube-aws destroy` to destroy all the cluster components. It will as for confirmation. Use `--force` to skip confirmation step.

If you created any Kubernetes Services of type `LoadBalancer`, you must delete these first, as the CloudFormation cannot be fully destroyed if any externally-managed resources still exist.

0 comments on commit 8bbf89d

Please sign in to comment.