From acd59bb32f67db707789a7969312c00113b4926c Mon Sep 17 00:00:00 2001 From: David Eliahu Date: Tue, 22 Jun 2021 00:08:10 -0700 Subject: [PATCH 1/4] Update cluster deletion logic --- cli/cmd/cluster.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go index bb5ccf5cfa..bb4f8daf17 100644 --- a/cli/cmd/cluster.go +++ b/cli/cmd/cluster.go @@ -475,22 +475,17 @@ var _clusterDownCmd = &cobra.Command{ errors.PrintError(err) fmt.Println() } else { - state := clusterstate.GetClusterState(stacks) - if err := clusterstate.AssertClusterState(stacks, state, clusterstate.StateClusterDoesntExist); err != nil { - awsClient.DeleteQueuesWithPrefix(clusterconfig.SQSNamePrefix(accessConfig.ClusterName)) - awsClient.DeletePolicy(clusterconfig.DefaultPolicyARN(accountID, accessConfig.ClusterName, accessConfig.Region)) - if !_flagClusterDownKeepAWSResources { - volumes, err := listPVCVolumesForCluster(awsClient, accessConfig.ClusterName) - if err == nil { - for _, volume := range volumes { - awsClient.DeleteVolume(*volume.VolumeId) - } - } - } + + switch clusterstate.GetClusterState(stacks) { + case clusterstate.StateClusterExists: + fmt.Println("✓") + clusterExists = true + case clusterstate.StateClusterDoesntExist: + fmt.Println("cluster doesn't exist ✓") + default: + // still attempt to spin down the cluster if it's in an unexpected state fmt.Println("✓") clusterExists = true - } else { - fmt.Println("already deleted ✓") } } @@ -511,7 +506,9 @@ var _clusterDownCmd = &cobra.Command{ fmt.Println("✓") } + // this will be updated later if the EKS cluster deletion succeeded clusterDoesntExist := !clusterExists + if clusterExists { fmt.Print("○ spinning down the cluster ...") out, exitCode, err := runManagerAccessCommand("/root/uninstall.sh", *accessConfig, awsClient, nil, nil) From 0e6be255cd406b76fa7f32c1e1d0b608487a6168 Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Tue, 22 Jun 2021 15:32:51 +0300 Subject: [PATCH 2/4] Revert "Update cluster deletion logic" This reverts commit acd59bb32f67db707789a7969312c00113b4926c. --- cli/cmd/cluster.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go index bb4f8daf17..bb5ccf5cfa 100644 --- a/cli/cmd/cluster.go +++ b/cli/cmd/cluster.go @@ -475,17 +475,22 @@ var _clusterDownCmd = &cobra.Command{ errors.PrintError(err) fmt.Println() } else { - - switch clusterstate.GetClusterState(stacks) { - case clusterstate.StateClusterExists: - fmt.Println("✓") - clusterExists = true - case clusterstate.StateClusterDoesntExist: - fmt.Println("cluster doesn't exist ✓") - default: - // still attempt to spin down the cluster if it's in an unexpected state + state := clusterstate.GetClusterState(stacks) + if err := clusterstate.AssertClusterState(stacks, state, clusterstate.StateClusterDoesntExist); err != nil { + awsClient.DeleteQueuesWithPrefix(clusterconfig.SQSNamePrefix(accessConfig.ClusterName)) + awsClient.DeletePolicy(clusterconfig.DefaultPolicyARN(accountID, accessConfig.ClusterName, accessConfig.Region)) + if !_flagClusterDownKeepAWSResources { + volumes, err := listPVCVolumesForCluster(awsClient, accessConfig.ClusterName) + if err == nil { + for _, volume := range volumes { + awsClient.DeleteVolume(*volume.VolumeId) + } + } + } fmt.Println("✓") clusterExists = true + } else { + fmt.Println("already deleted ✓") } } @@ -506,9 +511,7 @@ var _clusterDownCmd = &cobra.Command{ fmt.Println("✓") } - // this will be updated later if the EKS cluster deletion succeeded clusterDoesntExist := !clusterExists - if clusterExists { fmt.Print("○ spinning down the cluster ...") out, exitCode, err := runManagerAccessCommand("/root/uninstall.sh", *accessConfig, awsClient, nil, nil) From 34d6ada2f30ef72363b1fd1e213835a0dd4a27d4 Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Tue, 22 Jun 2021 15:33:43 +0300 Subject: [PATCH 3/4] Best effort deletion of cluster resources even when the cluster is already removed --- cli/cmd/cluster.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go index bb5ccf5cfa..7a54c6fef2 100644 --- a/cli/cmd/cluster.go +++ b/cli/cmd/cluster.go @@ -477,6 +477,9 @@ var _clusterDownCmd = &cobra.Command{ } else { state := clusterstate.GetClusterState(stacks) if err := clusterstate.AssertClusterState(stacks, state, clusterstate.StateClusterDoesntExist); err != nil { + fmt.Println("✓") + clusterExists = true + } else { awsClient.DeleteQueuesWithPrefix(clusterconfig.SQSNamePrefix(accessConfig.ClusterName)) awsClient.DeletePolicy(clusterconfig.DefaultPolicyARN(accountID, accessConfig.ClusterName, accessConfig.Region)) if !_flagClusterDownKeepAWSResources { @@ -487,9 +490,6 @@ var _clusterDownCmd = &cobra.Command{ } } } - fmt.Println("✓") - clusterExists = true - } else { fmt.Println("already deleted ✓") } } From a5e1c12b8221e280a0d9d98f5d823c8479b67e2f Mon Sep 17 00:00:00 2001 From: David Eliahu Date: Tue, 22 Jun 2021 08:57:38 -0700 Subject: [PATCH 4/4] Update cluster check --- cli/cmd/cluster.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go index 7a54c6fef2..1616565b71 100644 --- a/cli/cmd/cluster.go +++ b/cli/cmd/cluster.go @@ -475,22 +475,11 @@ var _clusterDownCmd = &cobra.Command{ errors.PrintError(err) fmt.Println() } else { - state := clusterstate.GetClusterState(stacks) - if err := clusterstate.AssertClusterState(stacks, state, clusterstate.StateClusterDoesntExist); err != nil { + if clusterstate.GetClusterState(stacks) == clusterstate.StateClusterDoesntExist { + fmt.Println("cluster doesn't exist ✓") + } else { fmt.Println("✓") clusterExists = true - } else { - awsClient.DeleteQueuesWithPrefix(clusterconfig.SQSNamePrefix(accessConfig.ClusterName)) - awsClient.DeletePolicy(clusterconfig.DefaultPolicyARN(accountID, accessConfig.ClusterName, accessConfig.Region)) - if !_flagClusterDownKeepAWSResources { - volumes, err := listPVCVolumesForCluster(awsClient, accessConfig.ClusterName) - if err == nil { - for _, volume := range volumes { - awsClient.DeleteVolume(*volume.VolumeId) - } - } - } - fmt.Println("already deleted ✓") } }