From 17a297a4d9f830a12651eafb225265e427dc3582 Mon Sep 17 00:00:00 2001 From: Pierre Gerbelot Date: Fri, 5 Apr 2024 11:14:04 +0200 Subject: [PATCH] chore: route admin.force-delete-cluster to cluster.deleteCluster method --- cmd/admin_delete_cluster.go | 36 +++++++++++++++++++++++++++++++----- pkg/delete_cluster.go | 17 ----------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/cmd/admin_delete_cluster.go b/cmd/admin_delete_cluster.go index 6d87bd08..9a3ede6a 100644 --- a/cmd/admin_delete_cluster.go +++ b/cmd/admin_delete_cluster.go @@ -1,10 +1,12 @@ package cmd import ( + "context" + "github.com/qovery/qovery-cli/utils" + "github.com/qovery/qovery-client-go" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" - - "github.com/qovery/qovery-cli/pkg" + "os" ) var ( @@ -12,7 +14,7 @@ var ( Use: "force-delete-cluster", Short: "Force delete cluster by id (only Qovery DB side, without calling the engine)", Run: func(cmd *cobra.Command, args []string) { - deleteClusterById() + deleteClusterById(cmd) }, } ) @@ -24,10 +26,34 @@ func init() { adminCmd.AddCommand(adminDeleteClusterCmd) } -func deleteClusterById() { +func deleteClusterById(cmd *cobra.Command) { if orgaErr != nil { log.Error("Invalid cluster Id") } else { - pkg.DeleteClusterById(clusterId, dryRun) + utils.CheckAdminUrl() + utils.Capture(cmd) + + tokenType, token, err := utils.GetAccessToken() + if err != nil { + utils.PrintlnError(err) + os.Exit(1) + panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 + } + + client := utils.GetQoveryClient(tokenType, token) + orgaId, _, err := getOrganizationProjectContextResourcesIds(client) + + if err != nil { + utils.PrintlnError(err) + os.Exit(1) + panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 + } + + _ ,err = client.ClustersAPI.DeleteCluster(context.Background(), orgaId, clusterId).DeleteMode(qovery.CLUSTERDELETEMODE_DELETE_QOVERY_CONFIG).Execute() + if err != nil { + utils.PrintlnError(err) + os.Exit(1) + panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 + } } } diff --git a/pkg/delete_cluster.go b/pkg/delete_cluster.go index 03bfd6ca..558ad5e8 100644 --- a/pkg/delete_cluster.go +++ b/pkg/delete_cluster.go @@ -13,23 +13,6 @@ import ( "github.com/qovery/qovery-cli/utils" ) -func DeleteClusterById(clusterId string, dryRunDisabled bool) { - utils.CheckAdminUrl() - - utils.DryRunPrint(dryRunDisabled) - if utils.Validate("delete") { - res := httpDelete(utils.AdminUrl+"/cluster/"+clusterId, http.MethodDelete, dryRunDisabled) - - if !dryRunDisabled { - fmt.Println("Cluster with id " + clusterId + " deletable.") - } else if !strings.Contains(res.Status, "200") { - result, _ := io.ReadAll(res.Body) - log.Errorf("Could not delete cluster with id %s : %s. %s", clusterId, res.Status, string(result)) - } else { - fmt.Println("Cluster with id " + clusterId + " deleted.") - } - } -} func DeleteClusterUnDeployedInError() { utils.CheckAdminUrl()