-
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.
feat: add helm cancel and helm deploy cmd
- Loading branch information
Showing
6 changed files
with
345 additions
and
2 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
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,77 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/pterm/pterm" | ||
"github.com/qovery/qovery-cli/utils" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var helmCancelCmd = &cobra.Command{ | ||
Use: "cancel", | ||
Short: "Cancel a helm deployment", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
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) | ||
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client) | ||
|
||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
helms, _, err := client.HelmsAPI.ListHelms(context.Background(), envId).Execute() | ||
|
||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
helm := utils.FindByHelmName(helms.GetResults(), helmName) | ||
|
||
if helm == nil { | ||
utils.PrintlnError(fmt.Errorf("helm %s not found", helmName)) | ||
utils.PrintlnInfo("You can list all helms with: qovery helm list") | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
msg, err := utils.CancelServiceDeployment(client, envId, helm.Id, utils.HelmType, watchFlag) | ||
|
||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
if msg != "" { | ||
utils.PrintlnInfo(msg) | ||
return | ||
} | ||
|
||
utils.Println(fmt.Sprintf("helm %s deployment cancelled!", pterm.FgBlue.Sprintf(helmName))) | ||
}, | ||
} | ||
|
||
func init() { | ||
helmCmd.AddCommand(helmCancelCmd) | ||
helmCancelCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name") | ||
helmCancelCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name") | ||
helmCancelCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name") | ||
helmCancelCmd.Flags().StringVarP(&helmName, "helm", "n", "", "Helm Name") | ||
helmCancelCmd.Flags().BoolVarP(&watchFlag, "watch", "w", false, "Watch cancel until it's done or an error occurs") | ||
|
||
_ = helmCancelCmd.MarkFlagRequired("helm") | ||
} |
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,149 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/pterm/pterm" | ||
"github.com/qovery/qovery-client-go" | ||
"time" | ||
|
||
"github.com/qovery/qovery-cli/utils" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var helmDeployCmd = &cobra.Command{ | ||
Use: "deploy", | ||
Short: "Deploy a helm", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
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 | ||
} | ||
|
||
if helmName == "" && helmNames == "" { | ||
utils.PrintlnError(fmt.Errorf("use either --helm \"<helm name>\" or --helms \"<helm1 name>, <helm2 name>\" but not both at the same time")) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
if helmName != "" && helmNames != "" { | ||
utils.PrintlnError(fmt.Errorf("you can't use --helm and --helms at the same time")) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
client := utils.GetQoveryClient(tokenType, token) | ||
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client) | ||
|
||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
if helmNames != "" { | ||
// wait until service is ready | ||
for { | ||
if utils.IsEnvironmentInATerminalState(envId, client) { | ||
break | ||
} | ||
|
||
utils.Println(fmt.Sprintf("Waiting for environment %s to be ready..", pterm.FgBlue.Sprintf(envId))) | ||
time.Sleep(5 * time.Second) | ||
} | ||
|
||
// deploy multiple services | ||
err := utils.DeployHelms(client, envId, helmNames, chartVersion, chartGitCommitId, valuesOverrideCommitId) | ||
|
||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
utils.Println(fmt.Sprintf("Deploying helms %s in progress..", pterm.FgBlue.Sprintf(helmNames))) | ||
|
||
if watchFlag { | ||
utils.WatchEnvironment(envId, "unused", client) | ||
} | ||
|
||
return | ||
} | ||
|
||
helms, _, err := client.HelmsAPI.ListHelms(context.Background(), envId).Execute() | ||
|
||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
helm := utils.FindByHelmName(helms.GetResults(), helmName) | ||
|
||
if helm == nil { | ||
utils.PrintlnError(fmt.Errorf("helm %s not found", helmName)) | ||
utils.PrintlnInfo("You can list all helms with: qovery helm list") | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
var mCommitId *string | ||
var mChartVersion *string | ||
var mValuesOverrideCommitId *string | ||
if chartGitCommitId != "" { | ||
mCommitId = &chartGitCommitId | ||
} | ||
|
||
if chartVersion != "" { | ||
mChartVersion = &chartVersion | ||
} | ||
|
||
if valuesOverrideCommitId != "" { | ||
mValuesOverrideCommitId = &valuesOverrideCommitId | ||
} | ||
|
||
|
||
req := qovery.HelmDeployRequest{ | ||
ChartVersion: mChartVersion, | ||
GitCommitId: mCommitId, | ||
ValuesOverrideGitCommitId: mValuesOverrideCommitId, | ||
} | ||
|
||
msg, err := utils.DeployService(client, envId, helm.Id, utils.HelmType, req, watchFlag) | ||
|
||
if err != nil { | ||
utils.PrintlnError(err) | ||
os.Exit(1) | ||
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 | ||
} | ||
|
||
if msg != "" { | ||
utils.PrintlnInfo(msg) | ||
return | ||
} | ||
|
||
if watchFlag { | ||
utils.Println(fmt.Sprintf("helm %s deployed!", pterm.FgBlue.Sprintf(helmName))) | ||
} else { | ||
utils.Println(fmt.Sprintf("Deploying helm %s in progress..", pterm.FgBlue.Sprintf(helmName))) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
helmCmd.AddCommand(helmDeployCmd) | ||
helmDeployCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name") | ||
helmDeployCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name") | ||
helmDeployCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name") | ||
helmDeployCmd.Flags().StringVarP(&helmName, "helm", "n", "", "helm Name") | ||
helmDeployCmd.Flags().StringVarP(&helmNames, "helms", "", "", "helm Names (comma separated) (ex: --helms \"helm1,helm2\")") | ||
helmDeployCmd.Flags().StringVarP(&chartVersion, "chart_version", "", "", "helm chart version") | ||
helmDeployCmd.Flags().StringVarP(&chartGitCommitId, "chart_git_commit_id", "", "", "helm chart git commit id") | ||
helmDeployCmd.Flags().StringVarP(&valuesOverrideCommitId, "values_override_git_commit_id", "", "", "helm values override git commit id") | ||
helmDeployCmd.Flags().BoolVarP(&watchFlag, "watch", "w", false, "Watch helm status until it's ready or an error occurs") | ||
} |
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
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
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