From faa39c8d62b41c75e7db9d0d522898f5511f2ef1 Mon Sep 17 00:00:00 2001 From: Pierre Gerbelot Date: Tue, 3 Oct 2023 16:18:27 +0200 Subject: [PATCH 1/2] fix: add CLI to new Cluster State enum --- cmd/cluster_deploy.go | 4 ++-- cmd/cluster_list.go | 2 +- cmd/cluster_stop.go | 4 ++-- cmd/container_update.go | 2 +- go.mod | 2 +- go.sum | 4 ++++ utils/qovery.go | 29 +++++++++++++++++++++++++++++ 7 files changed, 40 insertions(+), 7 deletions(-) diff --git a/cmd/cluster_deploy.go b/cmd/cluster_deploy.go index b914a8ed..6f839df6 100644 --- a/cmd/cluster_deploy.go +++ b/cmd/cluster_deploy.go @@ -74,11 +74,11 @@ var clusterDeployCmd = &cobra.Command{ utils.PrintlnError(err) } - if utils.IsTerminalState(*status.Status) { + if utils.IsTerminalClusterState(*status.Status) { break } - utils.Println(fmt.Sprintf("Cluster status: %s", utils.GetStatusTextWithColor(status.GetStatus()))) + utils.Println(fmt.Sprintf("Cluster status: %s", utils.GetClusterStatusTextWithColor(status.GetStatus()))) // sleep here to avoid too many requests time.Sleep(5 * time.Second) diff --git a/cmd/cluster_list.go b/cmd/cluster_list.go index e50176fd..6b106c11 100644 --- a/cmd/cluster_list.go +++ b/cmd/cluster_list.go @@ -50,7 +50,7 @@ var clusterListCmd = &cobra.Command{ for _, cluster := range clusters.GetResults() { data = append(data, []string{cluster.Id, cluster.Name, "cluster", - utils.GetStatusTextWithColor(*cluster.Status), cluster.UpdatedAt.String()}) + utils.GetClusterStatusTextWithColor(*cluster.Status), cluster.UpdatedAt.String()}) } err = utils.PrintTable([]string{"Id", "Name", "Type", "Status", "Last Update"}, data) diff --git a/cmd/cluster_stop.go b/cmd/cluster_stop.go index 83ae2096..47b03975 100644 --- a/cmd/cluster_stop.go +++ b/cmd/cluster_stop.go @@ -65,11 +65,11 @@ var clusterStopCmd = &cobra.Command{ utils.PrintlnError(err) } - if utils.IsTerminalState(*status.Status) { + if utils.IsTerminalClusterState(*status.Status) { break } - utils.Println(fmt.Sprintf("Cluster status: %s", utils.GetStatusTextWithColor(status.GetStatus()))) + utils.Println(fmt.Sprintf("Cluster status: %s", utils.GetClusterStatusTextWithColor(status.GetStatus()))) // sleep here to avoid too many requests time.Sleep(5 * time.Second) diff --git a/cmd/container_update.go b/cmd/container_update.go index 331ea8bb..1ffcd829 100644 --- a/cmd/container_update.go +++ b/cmd/container_update.go @@ -88,7 +88,7 @@ var containerUpdateCmd = &cobra.Command{ Ports: ports, Name: container.Name, Description: container.Description, - RegistryId: container.Registry.Id, + RegistryId: *container.Registry.Id, ImageName: imageName, Tag: tag, Arguments: container.Arguments, diff --git a/go.mod b/go.mod index 76dd1b5d..6be65c7d 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/posthog/posthog-go v0.0.0-20221221115252-24dfed35d71a github.com/pterm/pterm v0.12.55 - github.com/qovery/qovery-client-go v0.0.0-20230928091140-1cb795f1cb29 + github.com/qovery/qovery-client-go v0.0.0-20231003140602-a877ab9bdb9d github.com/sirupsen/logrus v1.9.0 github.com/spf13/cobra v1.6.1 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index d94f8361..4e92ad13 100644 --- a/go.sum +++ b/go.sum @@ -287,6 +287,10 @@ github.com/qovery/qovery-client-go v0.0.0-20230927121209-d25a62c3cc92 h1:Idy6l2r github.com/qovery/qovery-client-go v0.0.0-20230927121209-d25a62c3cc92/go.mod h1:7su0Zq+YniKNRSXNJsdrbR2/dGn7UHz3QJ2WpcxyP8k= github.com/qovery/qovery-client-go v0.0.0-20230928091140-1cb795f1cb29 h1:ZZ+VZYXfDG5ATLDirlxjO6mfCBvEkmFJdjWQl+mdXT4= github.com/qovery/qovery-client-go v0.0.0-20230928091140-1cb795f1cb29/go.mod h1:7su0Zq+YniKNRSXNJsdrbR2/dGn7UHz3QJ2WpcxyP8k= +github.com/qovery/qovery-client-go v0.0.0-20231003132450-36f1e524c6f8 h1:ZfXg+BdneX9yMIaHptFh3LZsB9SPi1GoFL1Ewf6gc4c= +github.com/qovery/qovery-client-go v0.0.0-20231003132450-36f1e524c6f8/go.mod h1:7su0Zq+YniKNRSXNJsdrbR2/dGn7UHz3QJ2WpcxyP8k= +github.com/qovery/qovery-client-go v0.0.0-20231003140602-a877ab9bdb9d h1:cUlEoJ2O9iAxb8aN8y9lmmZzcWb2edmXyW02/wF1qGM= +github.com/qovery/qovery-client-go v0.0.0-20231003140602-a877ab9bdb9d/go.mod h1:7su0Zq+YniKNRSXNJsdrbR2/dGn7UHz3QJ2WpcxyP8k= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= diff --git a/utils/qovery.go b/utils/qovery.go index c8c95abe..c263d64b 100644 --- a/utils/qovery.go +++ b/utils/qovery.go @@ -889,6 +889,28 @@ func GetStatusTextWithColor(s qovery.StateEnum) string { return statusMsg } +func GetClusterStatusTextWithColor(s qovery.ClusterStateEnum) string { + var statusMsg string + + if s == qovery.CLUSTERSTATEENUM_DEPLOYED || s == qovery.CLUSTERSTATEENUM_RESTARTED { + statusMsg = pterm.FgGreen.Sprintf(string(s)) + } else if strings.HasSuffix(string(s), "ERROR") || s == qovery.CLUSTERSTATEENUM_INVALID_CREDENTIALS { + statusMsg = pterm.FgRed.Sprintf(string(s)) + } else if strings.HasSuffix(string(s), "ING") { + statusMsg = pterm.FgLightBlue.Sprintf(string(s)) + } else if strings.HasSuffix(string(s), "QUEUED") { + statusMsg = pterm.FgLightYellow.Sprintf(string(s)) + } else if s == qovery.CLUSTERSTATEENUM_READY { + statusMsg = pterm.FgYellow.Sprintf(string(s)) + } else if s == qovery.CLUSTERSTATEENUM_STOPPED { + statusMsg = pterm.FgYellow.Sprintf(string(s)) + } else { + statusMsg = string(s) + } + + return statusMsg +} + func FindByOrganizationName(organizations []qovery.Organization, name string) *qovery.Organization { for _, o := range organizations { if o.Name == name { @@ -1402,6 +1424,13 @@ func IsTerminalState(state qovery.StateEnum) bool { strings.HasSuffix(string(state), "ERROR") } +func IsTerminalClusterState(state qovery.ClusterStateEnum) bool { + return state == qovery.CLUSTERSTATEENUM_DEPLOYED || state == qovery.CLUSTERSTATEENUM_DELETED || + state == qovery.CLUSTERSTATEENUM_STOPPED || state == qovery.CLUSTERSTATEENUM_CANCELED || + state == qovery.CLUSTERSTATEENUM_READY || state == qovery.CLUSTERSTATEENUM_RESTARTED || + strings.HasSuffix(string(state), "ERROR") +} + func CancelServiceDeployment(client *qovery.APIClient, envId string, serviceId string, serviceType ServiceType, watchFlag bool) (string, error) { statuses, _, err := client.EnvironmentMainCallsApi.GetEnvironmentStatuses(context.Background(), envId).Execute() From 5af40fe358673f43e6e91f4a8241cf209b88b94e Mon Sep 17 00:00:00 2001 From: Pierre Gerbelot Date: Tue, 3 Oct 2023 16:38:33 +0200 Subject: [PATCH 2/2] add CLUSTERSTATEENUM_INVALID_CREDENTIALS as terminal cluster state --- utils/qovery.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/qovery.go b/utils/qovery.go index c263d64b..8281b74b 100644 --- a/utils/qovery.go +++ b/utils/qovery.go @@ -1428,7 +1428,7 @@ func IsTerminalClusterState(state qovery.ClusterStateEnum) bool { return state == qovery.CLUSTERSTATEENUM_DEPLOYED || state == qovery.CLUSTERSTATEENUM_DELETED || state == qovery.CLUSTERSTATEENUM_STOPPED || state == qovery.CLUSTERSTATEENUM_CANCELED || state == qovery.CLUSTERSTATEENUM_READY || state == qovery.CLUSTERSTATEENUM_RESTARTED || - strings.HasSuffix(string(state), "ERROR") + state == qovery.CLUSTERSTATEENUM_INVALID_CREDENTIALS || strings.HasSuffix(string(state), "ERROR") } func CancelServiceDeployment(client *qovery.APIClient, envId string, serviceId string, serviceType ServiceType, watchFlag bool) (string, error) {