Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wait flag for delete cluster command #262

Merged
merged 1 commit into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions cmd/eksctl/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"github.com/weaveworks/eksctl/pkg/utils/kubeconfig"
)

var (
waitDelete bool
)

func deleteCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete",
Expand Down Expand Up @@ -51,6 +55,8 @@ func deleteClusterCmd() *cobra.Command {
fs.StringVarP(&cfg.Region, "region", "r", "", "AWS region")
fs.StringVarP(&cfg.Profile, "profile", "p", "", "AWS credentials profile to use (overrides the AWS_PROFILE environment variable)")

fs.BoolVarP(&waitDelete, "wait", "w", false, "Wait for deletion of all resources before exiting")

fs.DurationVar(&cfg.WaitTimeout, "timeout", api.DefaultWaitTimeout, "max wait time in any polling operations")

return cmd
Expand Down Expand Up @@ -94,14 +100,23 @@ func doDeleteCluster(cfg *api.ClusterConfig, name string) error {
stackManager := ctl.NewStackManager()

handleIfError(stackManager.WaitDeleteNodeGroup(), "node group")
if handleIfError(stackManager.DeleteCluster(), "cluster") {

var clusterErr bool
if waitDelete {
clusterErr = handleIfError(stackManager.WaitDeleteCluster(), "cluster")
} else {
clusterErr = handleIfError(stackManager.DeleteCluster(), "cluster")
}

if clusterErr {
if handleIfError(ctl.DeprecatedDeleteControlPlane(), "control plane") {
handleIfError(stackManager.DeprecatedDeleteStackControlPlane(), "stack control plane")
handleIfError(stackManager.DeprecatedDeleteStackControlPlane(waitDelete), "stack control plane")
}
}
handleIfError(stackManager.DeprecatedDeleteStackServiceRole(), "node group")
handleIfError(stackManager.DeprecatedDeleteStackVPC(), "stack VPC")
handleIfError(stackManager.DeprecatedDeleteStackDefaultNodeGroup(), "default node group")

handleIfError(stackManager.DeprecatedDeleteStackServiceRole(waitDelete), "node group")
handleIfError(stackManager.DeprecatedDeleteStackVPC(waitDelete), "stack VPC")
handleIfError(stackManager.DeprecatedDeleteStackDefaultNodeGroup(waitDelete), "default node group")

ctl.MaybeDeletePublicSSHKey()

Expand Down
1 change: 1 addition & 0 deletions humans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Kirsten Schumy @kschumy
Karinna Iniguez @karinnainiguez
Michael Seiwald @mseiwald
Anton Gruebel @gruebel
Bryan Peterson @lazyshot

/* Thanks */

Expand Down
5 changes: 5 additions & 0 deletions pkg/cfn/manager/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ func (c *StackCollection) DeleteCluster() error {
_, err := c.DeleteStack(c.makeClusterStackName())
return err
}

// WaitDeleteCluster waits till the cluster is deleted
func (c *StackCollection) WaitDeleteCluster() error {
return c.WaitDeleteStack(c.makeClusterStackName())
}
48 changes: 40 additions & 8 deletions pkg/cfn/manager/deprecated.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,57 @@
package manager

// DeprecatedDeleteStackVPC deletes the VPC stack
func (c *StackCollection) DeprecatedDeleteStackVPC() error {
_, err := c.DeleteStack("EKS-" + c.spec.ClusterName + "-VPC")
func (c *StackCollection) DeprecatedDeleteStackVPC(wait bool) error {
var err error
stackName := "EKS-" + c.spec.ClusterName + "-VPC"

if wait {
err = c.WaitDeleteStack(stackName)
} else {
_, err = c.DeleteStack(stackName)
}

return err
}

// DeprecatedDeleteStackServiceRole deletes the service role stack
func (c *StackCollection) DeprecatedDeleteStackServiceRole() error {
_, err := c.DeleteStack("EKS-" + c.spec.ClusterName + "-ServiceRole")
func (c *StackCollection) DeprecatedDeleteStackServiceRole(wait bool) error {
var err error
stackName := "EKS-" + c.spec.ClusterName + "-ServiceRole"

if wait {
err = c.WaitDeleteStack(stackName)
} else {
_, err = c.DeleteStack(stackName)
}

return err
}

// DeprecatedDeleteStackDefaultNodeGroup deletes the default node group stack
func (c *StackCollection) DeprecatedDeleteStackDefaultNodeGroup() error {
_, err := c.DeleteStack("EKS-" + c.spec.ClusterName + "-DefaultNodeGroup")
func (c *StackCollection) DeprecatedDeleteStackDefaultNodeGroup(wait bool) error {
var err error
stackName := "EKS-" + c.spec.ClusterName + "-DefaultNodeGroup"

if wait {
err = c.WaitDeleteStack(stackName)
} else {
_, err = c.DeleteStack(stackName)
}

return err
}

// DeprecatedDeleteStackControlPlane deletes the control plane stack
func (c *StackCollection) DeprecatedDeleteStackControlPlane() error {
_, err := c.DeleteStack("EKS-" + c.spec.ClusterName + "-ControlPlane")
func (c *StackCollection) DeprecatedDeleteStackControlPlane(wait bool) error {
var err error
stackName := "EKS-" + c.spec.ClusterName + "-ControlPlane"

if wait {
err = c.WaitDeleteStack(stackName)
} else {
_, err = c.DeleteStack(stackName)
}

return err
}