-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
675 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/qovery/qovery-cli/utils" | ||
) | ||
|
||
var ( | ||
adminClusterCmd = &cobra.Command{ | ||
Use: "cluster", | ||
Short: "Manage clusters", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
utils.Capture(cmd) | ||
|
||
if len(args) == 0 { | ||
_ = cmd.Help() | ||
os.Exit(0) | ||
} | ||
}, | ||
} | ||
// TODO (mzo) add parameter to random deploy clusters | ||
// TODO (mzo) handle pending clusters queue, when clusters couldn't be deployed because not in a final state | ||
// TODO (mzo) handle progression in a file to let resume from the last deployment launched in case of interruption | ||
) | ||
|
||
func init() { | ||
adminCmd.AddCommand(adminClusterCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/qovery/qovery-cli/pkg" | ||
"github.com/qovery/qovery-cli/utils" | ||
) | ||
|
||
var ( | ||
adminClusterDeployCmd = &cobra.Command{ | ||
Use: "deploy", | ||
Short: "Deploy or upgrade clusters", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
deployClusters() | ||
}, | ||
} | ||
refreshDelay int | ||
filters map[string]string | ||
executionMode string | ||
newK8sVersion string | ||
parallelRuns int | ||
) | ||
|
||
func init() { | ||
adminClusterDeployCmd.Flags().BoolVarP(&dryRun, "disable-dry-run", "y", false, "Disable dry run mode") | ||
adminClusterDeployCmd.Flags().IntVarP(¶llelRuns, "parallel-run", "n", 5, "Number of clusters to update in parallel - must be set between 1 and 20") | ||
adminClusterDeployCmd.Flags().IntVarP(&refreshDelay, "refresh-delay", "r", 30, "Time in seconds to wait before checking clusters status during deployment - must be between [5-120]") | ||
adminClusterDeployCmd.Flags().StringToStringVarP(&filters, "filters", "f", make(map[string]string), "Value to filter the property selected (property-to-filter must be set as well)") | ||
adminClusterDeployCmd.Flags().StringVarP(&executionMode, "execution-mode", "e", "batch", "Batch execution mode - 'batch' will wait for the N deployments to be finished and ask validation to continue - 'on-the-fly' will deploy continuously as soon as a slot is available") | ||
adminClusterDeployCmd.Flags().StringVarP(&newK8sVersion, "new-k8s-version", "k", "", "K8S version when upgrading clusters") | ||
adminClusterCmd.AddCommand(adminClusterDeployCmd) | ||
|
||
} | ||
|
||
func deployClusters() { | ||
utils.CheckAdminUrl() | ||
|
||
// if no filters is set, enforce to select only RUNNING clusters to avoid mistakes (e.g deploying a stopped cluster) | ||
_, containsKey := filters["ClusterStatus"] | ||
if !containsKey { | ||
filters["CurrentStatus"] = "DEPLOYED" | ||
} | ||
|
||
listService, err := pkg.NewAdminClusterListServiceImpl(filters) | ||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
deployService, err := pkg.NewAdminClusterBatchDeployServiceImpl(dryRun, parallelRuns, refreshDelay, executionMode, newK8sVersion) | ||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
err = pkg.DeployClustersByBatch(listService, deployService) | ||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/qovery/qovery-cli/pkg" | ||
"github.com/qovery/qovery-cli/utils" | ||
) | ||
|
||
var ( | ||
adminClusterListCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List clusters by applying any filter", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
listClusters() | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
adminClusterListCmd.Flags().StringToStringVarP(&filters, "filters", "f", make(map[string]string), "Value to filter the property selected (property-to-filter must be set as well)") | ||
adminClusterCmd.AddCommand(adminClusterListCmd) | ||
} | ||
|
||
func listClusters() { | ||
utils.CheckAdminUrl() | ||
|
||
listService, err := pkg.NewAdminClusterListServiceImpl(filters) | ||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
err = pkg.ListClusters(listService) | ||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package pkg | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/qovery/qovery-cli/utils" | ||
) | ||
|
||
func DeployClustersByBatch(listService AdminClusterListService, deployService AdminClusterBatchDeployService) error { | ||
clusters, err := listService.SelectClusters() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
utils.Println(fmt.Sprintf("%d clusters to deploy:", len(clusters))) | ||
err = PrintClustersTable(clusters) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
deployService.PrintParameters() | ||
|
||
utils.Println("Do you want to continue deploy process ?") | ||
var validated = utils.Validate("deploy") | ||
if !validated { | ||
utils.Println("Exiting: Validation failed") | ||
return nil | ||
} | ||
|
||
deployResult, err := deployService.Deploy(clusters) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(deployResult.PendingClusters) > 0 { | ||
utils.Println(fmt.Sprintf("%d clusters not triggered because in non-terminal state (queue not implemented yet):", len(deployResult.PendingClusters))) | ||
err := PrintClustersTable(deployResult.PendingClusters) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if len(deployResult.ProcessedClusters) > 0 { | ||
utils.Println(fmt.Sprintf("%d clusters deployed:", len(clusters))) | ||
err := PrintClustersTable(deployResult.ProcessedClusters) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package pkg | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/qovery/qovery-cli/utils" | ||
) | ||
|
||
func ListClusters(listService AdminClusterListService) error { | ||
clusters, err := listService.SelectClusters() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
utils.Println(fmt.Sprintf("Found %d clusters", len(clusters))) | ||
err = PrintClustersTable(clusters) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
Oops, something went wrong.