Skip to content

Commit

Permalink
feat: Add no-confirm option to the cli (#393)
Browse files Browse the repository at this point in the history
Useful when used in the CI
  • Loading branch information
erebe authored Nov 28, 2024
1 parent 2a52d67 commit 9e4c66d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
lockReason string
orgaErr error
dryRun bool
noConfirm bool
version string
versionErr error
ageInDay int
Expand Down
5 changes: 3 additions & 2 deletions cmd/admin_cluster_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ qovery admin cluster deploy -f ClusterType=GCP --parallel-run=9 -f ClusterK8sVer
)

func init() {
adminClusterDeployCmd.Flags().BoolVarP(&noConfirm, "no-confirm", "c", false, "Do not prompt for confirmation")
adminClusterDeployCmd.Flags().BoolVarP(&dryRun, "disable-dry-run", "y", false, "Disable dry run mode")
adminClusterDeployCmd.Flags().IntVarP(&parallelRuns, "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]")
Expand All @@ -111,14 +112,14 @@ func deployClusters() {
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
deployService, err := pkg.NewAdminClusterBatchDeployServiceImpl(dryRun, parallelRuns, refreshDelay, executionMode, newK8sVersion)
deployService, err := pkg.NewAdminClusterBatchDeployServiceImpl(dryRun, parallelRuns, refreshDelay, executionMode, newK8sVersion, noConfirm)
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)
err = pkg.DeployClustersByBatch(listService, deployService, noConfirm)
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
Expand Down
14 changes: 8 additions & 6 deletions pkg/admin_cluster_deploy_by_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/qovery/qovery-cli/utils"
)

func DeployClustersByBatch(listService AdminClusterListService, deployService AdminClusterBatchDeployService) error {
func DeployClustersByBatch(listService AdminClusterListService, deployService AdminClusterBatchDeployService, noConfirm bool) error {
clusters, err := listService.SelectClusters()
if err != nil {
return err
Expand All @@ -20,11 +20,13 @@ func DeployClustersByBatch(listService AdminClusterListService, deployService Ad

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
if !noConfirm {
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)
Expand Down
5 changes: 4 additions & 1 deletion pkg/admin_cluster_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ type AdminClusterBatchDeployServiceImpl struct {
UpgradeClusterNewK8sVersion *string
// UpgradeMode indicates if the cluster needs to be upgraded
UpgradeMode bool
// NoConfirm do not prompt for any confirmation
NoConfirm bool
}

func NewAdminClusterBatchDeployServiceImpl(
Expand All @@ -249,6 +251,7 @@ func NewAdminClusterBatchDeployServiceImpl(
refreshDelay int,
executionMode string,
newK8sversionStr string,
noConfirm bool,
) (*AdminClusterBatchDeployServiceImpl, error) {
// set at least 1 parallel run
if parallelRun < 1 {
Expand All @@ -258,7 +261,7 @@ func NewAdminClusterBatchDeployServiceImpl(
if parallelRun > 100 {
parallelRun = 100
}
if parallelRun > 20 {
if parallelRun > 20 && !noConfirm {
utils.Println("")
utils.Println(fmt.Sprintf("Please increase the cluster engine autoscaler to %d, then type 'yes' to continue", parallelRun))
validated := utils.Validate("autoscaler-increase")
Expand Down

0 comments on commit 9e4c66d

Please sign in to comment.