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

Changed messages for deleting a cluster #225

Merged
merged 1 commit into from
Sep 24, 2018
Merged
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
48 changes: 19 additions & 29 deletions cmd/eksctl/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package main

import (
"fmt"
"os"

"github.com/spf13/cobra"
"os"
"strings"

"github.com/kubicorn/kubicorn/pkg/logger"

Expand Down Expand Up @@ -74,51 +74,41 @@ func doDeleteCluster(cfg *api.ClusterConfig, name string) error {

logger.Info("deleting EKS cluster %q", cfg.ClusterName)

handleError := func(err error) bool {
var deletedResources []string

handleIfError := func(err error, name string) bool {
if err != nil {
logger.Debug("continue despite error: %v", err)
return true
}
logger.Debug("deleted %q", name)
deletedResources = append(deletedResources, name)
return false
}

// We can remove all 'DeprecatedDelete*' calls in 0.2.0

stackManager := ctl.NewStackManager()

if err := stackManager.WaitDeleteNodeGroup(); err != nil {
handleError(err)
}

if err := stackManager.DeleteCluster(); err != nil {
if handleError(err) {
if err := ctl.DeprecatedDeleteControlPlane(); err != nil {
if handleError(err) {
if err := stackManager.DeprecatedDeleteStackControlPlane(); err != nil {
handleError(err)
}
}
}
handleIfError(stackManager.WaitDeleteNodeGroup(), "node group")
if handleIfError(stackManager.DeleteCluster(), "cluster") {
if handleIfError(ctl.DeprecatedDeleteControlPlane(),"control plane") {
handleIfError(stackManager.DeprecatedDeleteStackControlPlane(), "stack control plane")
}
}

if err := stackManager.DeprecatedDeleteStackServiceRole(); err != nil {
handleError(err)
}

if err := stackManager.DeprecatedDeleteStackVPC(); err != nil {
handleError(err)
}

if err := stackManager.DeprecatedDeleteStackDefaultNodeGroup(); err != nil {
handleError(err)
}
handleIfError(stackManager.DeprecatedDeleteStackServiceRole(), "node group")
handleIfError(stackManager.DeprecatedDeleteStackVPC(), "stack VPC")
handleIfError(stackManager.DeprecatedDeleteStackDefaultNodeGroup(), "default node group")

ctl.MaybeDeletePublicSSHKey()

kubeconfig.MaybeDeleteConfig(cfg.ClusterName)

logger.Success("all EKS cluster resource for %q will be deleted (if in doubt, check CloudFormation console)", cfg.ClusterName)
if len(deletedResources) == 0 {
logger.Warning("no EKS cluster resources were found for %q", ctl.Spec.ClusterName)
} else {
logger.Success("the following EKS cluster resource(s) for %q will be deleted: %s. If in doubt, check CloudFormation console", ctl.Spec.ClusterName, strings.Join(deletedResources, ", "))
}

return nil
}