Skip to content

Commit

Permalink
Changed messages for deleting a cluster
Browse files Browse the repository at this point in the history
When a user deleted a cluster, the user received a message saying the cluster had been deleted, even if the cluster did not exist. This commit changes the message to inform the user what has been deleted. It also includes more verbose logger messages about what succeeded when debugging.

Issue #154, first part
  • Loading branch information
Kirsten Schumy committed Sep 24, 2018
1 parent e57229d commit 2e0cc8d
Showing 1 changed file with 19 additions and 29 deletions.
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
}

0 comments on commit 2e0cc8d

Please sign in to comment.