Skip to content

Commit

Permalink
Update cluster install cli
Browse files Browse the repository at this point in the history
  • Loading branch information
erebe committed May 22, 2024
1 parent 4c7304e commit 569f829
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions cmd/cluster_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var clusterInstallCmd = &cobra.Command{
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)
Expand All @@ -38,37 +37,46 @@ var clusterInstallCmd = &cobra.Command{
// if Local Machine, quit and print message to use the `qovery demo up` on the local machine
utils.Println("Cluster Type:")
clusterTypePrompt := promptui.Select{
Label: "Select where you want to install Qovery on:",
Items: []string{"Your Kubernetes Cluster", "Your Local Machine"},
Label: "Select where you want to install Qovery on",
Items: []string{
"Your AWS Cluster",
"Your GCP Cluster",
"Your Scaleway Cluster",
"Your own Kubernetes Cluster",
"Your Local Machine",
},
}

_, kubernetesType, err := clusterTypePrompt.Run()

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

if kubernetesType == "Local Machine" {
cloudProviderType := qovery.CLOUDPROVIDERENUM_AWS
if strings.Contains(kubernetesType, "AWS") {
cloudProviderType = qovery.CLOUDPROVIDERENUM_AWS
} else if strings.Contains(kubernetesType, "GCP") {
cloudProviderType = qovery.CLOUDPROVIDERENUM_GCP
} else if strings.Contains(kubernetesType, "Scaleway") {
cloudProviderType = qovery.CLOUDPROVIDERENUM_SCW
} else if strings.Contains(kubernetesType, "Local Machine") {
utils.PrintlnInfo("Please use `qovery demo up` to create a demo cluster on your local machine")
os.Exit(0)
} else {
cloudProviderType = qovery.CLOUDPROVIDERENUM_ON_PREMISE
}

// if Self Managed, continue with the installation process

organization, err := utils.SelectOrganization()

if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

if organization == nil {
utils.PrintlnError(fmt.Errorf("organizations not found, please create one on https://console.qovery.com"))
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

// check that the cluster name is unique
Expand All @@ -77,12 +85,11 @@ var clusterInstallCmd = &cobra.Command{
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

var selfManagedClusters []qovery.Cluster
for _, cluster := range clusters.GetResults() {
if cluster.CloudProvider == qovery.CLOUDPROVIDERENUM_ON_PREMISE {
if *cluster.Kubernetes == qovery.KUBERNETESENUM_SELF_MANAGED && cluster.CloudProvider == cloudProviderType {
selfManagedClusters = append(selfManagedClusters, cluster)
}
}
Expand All @@ -102,7 +109,6 @@ var clusterInstallCmd = &cobra.Command{
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

if reuseOrCreateNewCluster == "Reuse a Cluster" {
Expand All @@ -124,7 +130,6 @@ var clusterInstallCmd = &cobra.Command{
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

cluster = utils.FindByClusterName(selfManagedClusters, reuseClusterName)
Expand Down Expand Up @@ -153,7 +158,6 @@ var clusterInstallCmd = &cobra.Command{
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

kubernetesTypeOther := ""
Expand All @@ -168,7 +172,6 @@ var clusterInstallCmd = &cobra.Command{
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

kubernetesTypeOther = kubernetesType
Expand Down Expand Up @@ -209,7 +212,7 @@ var clusterInstallCmd = &cobra.Command{
}

// API call to create the self-managed cluster and link it to the on-premise account
description := fmt.Sprintf("Cluster running on %s (%s)", kubernetesType, kubernetesTypeOther)
description := fmt.Sprintf("Cluster running on %s (%s)", cloudProviderType, kubernetesTypeOther)

k := qovery.KUBERNETESENUM_SELF_MANAGED
cp := qovery.CLOUDPROVIDERENUM_ON_PREMISE
Expand Down

0 comments on commit 569f829

Please sign in to comment.