Skip to content
Open
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
36 changes: 31 additions & 5 deletions cmd/admin_delete_cluster.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
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 (
adminDeleteClusterCmd = &cobra.Command{
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)
},
}
)
Expand All @@ -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
}
}
}
17 changes: 0 additions & 17 deletions pkg/delete_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down