Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for the new Cluster State enum that contains INVALID_CREDENTIALS #203

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/cluster_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/cluster_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/container_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
29 changes: 29 additions & 0 deletions utils/qovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1402,6 +1424,13 @@ func IsTerminalState(state qovery.StateEnum) bool {
strings.HasSuffix(string(state), "ERROR")
}

func IsTerminalClusterState(state qovery.ClusterStateEnum) bool {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe having invalid credentials should be considered as a terminal state ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I didn't see the strings.HasSuffix(string(state), "ERROR")

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 ||
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) {
statuses, _, err := client.EnvironmentMainCallsApi.GetEnvironmentStatuses(context.Background(), envId).Execute()

Expand Down
Loading