-
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
8 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,33 @@ | ||
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) handle parameters to be split, e.g --filters ["CurrentStatus"]="FAILED,INVALID_CREDENTIALS" | ||
// TODO (mzo) handle parameter to compare last_deployed_at, e.g "--before-last-deployed-date" | ||
// TODO (mzo) enable processing deployments by "order by" org plans, e.g FREE then TEAM then ... | ||
// TODO (mzo) add parameter to random deploy clusters | ||
// TODO (mzo) handle progression in a file | ||
) | ||
|
||
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,65 @@ | ||
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 | ||
) | ||
|
||
func init() { | ||
adminClusterDeployCmd.Flags().BoolVarP(&dryRun, "disable-dry-run", "y", false, "Disable dry run mode") | ||
adminClusterDeployCmd.Flags().IntVarP(¶llelRun, "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, parallelRun, 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,46 @@ | ||
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 | ||
} | ||
|
||
// TODO (mzo) print every input values before asking to deploy | ||
|
||
utils.Println(fmt.Sprintf("Do you want to deploy those clusters ?")) | ||
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 { | ||
// TODO (mzo) handle the pending queue | ||
utils.Println(fmt.Sprintf("%d clusters not triggered because in non-terminal state (queue not implemented yet):", len(deployResult.PendingClusters))) | ||
} | ||
|
||
if len(deployResult.ProcessedClusters) > 0 { | ||
utils.Println(fmt.Sprintf("%d clusters deployed:", len(clusters))) | ||
PrintClustersTable(deployResult.ProcessedClusters) | ||
} | ||
|
||
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,16 @@ | ||
package pkg | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestAdminClusterDeploy(t *testing.T) { | ||
var filters = make(map[string]string) | ||
|
||
filters["OrganizationName"] = "Qovery tests AWS" | ||
|
||
listService, _ := NewAdminClusterListServiceImpl(filters) | ||
deployService, _ := NewAdminClusterBatchDeployServiceImpl(false, 1, 30, "batch", "") | ||
|
||
DeployClustersByBatch(listService, deployService) | ||
} |
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 | ||
} |
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,15 @@ | ||
package pkg | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestAdminClusterList(t *testing.T) { | ||
var filters = make(map[string]string) | ||
|
||
filters["OrganizationName"] = "Qovery tests AWS" | ||
|
||
listService, _ := NewAdminClusterListServiceImpl(filters) | ||
|
||
ListClusters(listService) | ||
} |
Oops, something went wrong.