From 93ff33509a81beead39bc0bd3eec6fba040f21d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Vanzuita?= Date: Wed, 16 Nov 2022 08:33:08 -0300 Subject: [PATCH] feat: add single source of truth for k3d cloud flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Vanzuita --- cmd/destroy.go | 3 ++- cmd/init.go | 2 +- cmd/postInstall.go | 4 ++-- internal/argocd/argocd_test.go | 5 ++--- internal/flagset/installer.go | 7 +++---- internal/repo/kubefirstTemplate.go | 5 ++--- internal/reports/section.go | 17 ++++++++--------- internal/terraform/terraform.go | 3 +-- 8 files changed, 21 insertions(+), 25 deletions(-) diff --git a/cmd/destroy.go b/cmd/destroy.go index f6f4cb4fc..ac06e48e5 100644 --- a/cmd/destroy.go +++ b/cmd/destroy.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/kubefirst/kubefirst/pkg" "log" "time" @@ -19,7 +20,7 @@ var destroyCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { //Destroy is implemented based on the flavor selected. - if viper.GetString("cloud") == flagset.CloudK3d { + if viper.GetString("cloud") == pkg.CloudK3d { err := destroyLocalGithubCmd.RunE(cmd, args) if err != nil { log.Println("Erroring destroying local+github:", err) diff --git a/cmd/init.go b/cmd/init.go index 24fd6b6e2..10ace0e19 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -200,7 +200,7 @@ validated and configured.`, } log.Println("dependency installation complete") progressPrinter.IncrementTracker("step-download", 1) - if installerFlags.Cloud == flagset.CloudLocal { + if installerFlags.Cloud == pkg.CloudK3d { err = downloadManager.DownloadLocalTools(config) if err != nil { return err diff --git a/cmd/postInstall.go b/cmd/postInstall.go index f8ea733e4..4cf7e79f3 100644 --- a/cmd/postInstall.go +++ b/cmd/postInstall.go @@ -22,7 +22,7 @@ var postInstallCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { // todo: temporary //flagset.DefineGlobalFlags(cmd) - if viper.GetString("cloud") == flagset.CloudLocal { + if viper.GetString("cloud") == pkg.CloudK3d { cmd.Flags().Bool("enable-console", true, "If hand-off screen will be presented on a browser UI") } //globalFlags, err := flagset.ProcessGlobalFlags(cmd) @@ -74,7 +74,7 @@ var postInstallCmd = &cobra.Command{ } } - if viper.GetString("cloud") == flagset.CloudK3d { + if viper.GetString("cloud") == pkg.CloudK3d { reports.LocalHandoffScreen(globalFlags.DryRun, globalFlags.SilentMode) } else { reports.HandoffScreen(globalFlags.DryRun, globalFlags.SilentMode) diff --git a/internal/argocd/argocd_test.go b/internal/argocd/argocd_test.go index 1d431427b..3eaeffae3 100644 --- a/internal/argocd/argocd_test.go +++ b/internal/argocd/argocd_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/kubefirst/kubefirst/configs" - "github.com/kubefirst/kubefirst/internal/flagset" "github.com/kubefirst/kubefirst/pkg" "github.com/spf13/viper" ) @@ -25,7 +24,7 @@ func TestArgoCDLivenessIntegration(t *testing.T) { } var argoURL string - if viper.GetString("cloud") == flagset.CloudK3d { + if viper.GetString("cloud") == pkg.CloudK3d { argoURL = "http://localhost:8080" } else { argoURL = fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename")) @@ -60,7 +59,7 @@ func TestArgoWorkflowLivenessIntegration(t *testing.T) { } var argoURL string - if viper.GetString("cloud") == flagset.CloudK3d { + if viper.GetString("cloud") == pkg.CloudK3d { argoURL = "http://localhost:2746" } else { argoURL = fmt.Sprintf("https://argo.%s", viper.GetString("aws.hostedzonename")) diff --git a/internal/flagset/installer.go b/internal/flagset/installer.go index da4771636..dc7625a9d 100644 --- a/internal/flagset/installer.go +++ b/internal/flagset/installer.go @@ -2,6 +2,7 @@ package flagset import ( "errors" + "github.com/kubefirst/kubefirst/pkg" "log" "github.com/kubefirst/kubefirst/configs" @@ -11,8 +12,6 @@ import ( ) const CloudAws = "aws" -const CloudLocal = "k3d" -const CloudK3d = "k3d" // DefineInstallerGenericFlags - define installer flags for CLI type InstallerGenericFlags struct { @@ -162,7 +161,7 @@ func ProcessInstallerGenericFlags(cmd *cobra.Command) (InstallerGenericFlags, er //Adds mandatory addon for non-local install addon.AddAddon("cloud") } - if flags.Cloud == CloudK3d { + if flags.Cloud == pkg.CloudK3d { //Adds mandatory addon for local install addon.AddAddon("k3d") } @@ -221,7 +220,7 @@ func validateInstallationFlags() error { // return errors.New(message) // } if len(viper.GetString("cloud")) < 1 { - message := "missing flag --cloud, supported values: " + CloudAws + ", " + CloudK3d + message := "missing flag --cloud, supported values: " + CloudAws + ", " + pkg.CloudK3d log.Println(message) return errors.New(message) } diff --git a/internal/repo/kubefirstTemplate.go b/internal/repo/kubefirstTemplate.go index 06a3e1d10..d60662334 100644 --- a/internal/repo/kubefirstTemplate.go +++ b/internal/repo/kubefirstTemplate.go @@ -11,7 +11,6 @@ import ( gitConfig "github.com/go-git/go-git/v5/config" "github.com/go-git/go-git/v5/plumbing/object" "github.com/kubefirst/kubefirst/configs" - "github.com/kubefirst/kubefirst/internal/flagset" "github.com/kubefirst/kubefirst/internal/gitClient" "github.com/kubefirst/kubefirst/pkg" cp "github.com/otiai10/copy" @@ -41,10 +40,10 @@ func PrepareKubefirstTemplateRepo(dryRun bool, config *configs.Config, githubOrg viper.WriteConfig() log.Printf("cloned %s-template repository to directory %s/%s", repoName, config.K1FolderPath, repoName) - if viper.GetString("cloud") == flagset.CloudK3d && !viper.GetBool("github.gitops.hydrated") { + if viper.GetString("cloud") == pkg.CloudK3d && !viper.GetBool("github.gitops.hydrated") { UpdateForLocalMode(directory) } - if viper.GetString("cloud") == flagset.CloudK3d && strings.Contains(repoName, "metaphor") { + if viper.GetString("cloud") == pkg.CloudK3d && strings.Contains(repoName, "metaphor") { os.RemoveAll(fmt.Sprintf("%s/.argo", directory)) os.RemoveAll(fmt.Sprintf("%s/.github", directory)) opt := cp.Options{ diff --git a/internal/reports/section.go b/internal/reports/section.go index 4ef9e46e6..c472cf458 100644 --- a/internal/reports/section.go +++ b/internal/reports/section.go @@ -7,7 +7,6 @@ import ( "log" "strings" - "github.com/kubefirst/kubefirst/internal/flagset" "github.com/spf13/viper" ) @@ -63,7 +62,7 @@ func PrintSectionAws() []byte { func PrintSectionVault() []byte { var vaultURL string - if viper.GetString("cloud") == flagset.CloudK3d { + if viper.GetString("cloud") == pkg.CloudK3d { vaultURL = "http://localhost:8200" } else { vaultURL = fmt.Sprintf("https://vault.%s", viper.GetString("aws.hostedzonename")) @@ -80,7 +79,7 @@ func PrintSectionVault() []byte { func PrintSectionArgoCD() []byte { var argoCdURL string - if viper.GetString("cloud") == flagset.CloudK3d { + if viper.GetString("cloud") == pkg.CloudK3d { argoCdURL = "http://localhost:8080" } else { argoCdURL = fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename")) @@ -99,7 +98,7 @@ func PrintSectionArgoCD() []byte { func PrintSectionArgoWorkflows() []byte { var argoWorkflowsURL string - if viper.GetString("cloud") == flagset.CloudK3d { + if viper.GetString("cloud") == pkg.CloudK3d { argoWorkflowsURL = "http://localhost:2746" } else { argoWorkflowsURL = fmt.Sprintf("https://argo.%s", viper.GetString("aws.hostedzonename")) @@ -110,7 +109,7 @@ func PrintSectionArgoWorkflows() []byte { handOffData.WriteString(strings.Repeat("-", 51)) handOffData.WriteString(fmt.Sprintf("\n URL: %s", argoWorkflowsURL)) - if viper.GetString("cloud") == flagset.CloudK3d { + if viper.GetString("cloud") == pkg.CloudK3d { return handOffData.Bytes() } else { handOffData.WriteString("\n sso credentials only ") @@ -123,7 +122,7 @@ func PrintSectionArgoWorkflows() []byte { func PrintSectionAtlantis() []byte { var atlantisUrl string - if viper.GetString("cloud") == flagset.CloudK3d { + if viper.GetString("cloud") == pkg.CloudK3d { atlantisUrl = "http://localhost:4141" } else { atlantisUrl = fmt.Sprintf("https://atlantis.%s", viper.GetString("aws.hostedzonename")) @@ -140,7 +139,7 @@ func PrintSectionAtlantis() []byte { func PrintSectionMuseum() []byte { var chartmuseumURL string - if viper.GetString("cloud") == flagset.CloudK3d { + if viper.GetString("cloud") == pkg.CloudK3d { chartmuseumURL = "http://localhost:8181" } else { chartmuseumURL = fmt.Sprintf("https://chartmuseum.%s", viper.GetString("aws.hostedzonename")) @@ -151,7 +150,7 @@ func PrintSectionMuseum() []byte { handOffData.WriteString(strings.Repeat("-", 54)) handOffData.WriteString(fmt.Sprintf("\n URL: %s", chartmuseumURL)) - if viper.GetString("cloud") == flagset.CloudK3d { + if viper.GetString("cloud") == pkg.CloudK3d { return handOffData.Bytes() } else { handOffData.WriteString("\n see vault for credentials ") @@ -188,7 +187,7 @@ func PrintSectionMetaphorGo() []byte { func PrintSectionMetaphorFrontend() []byte { var handOffData bytes.Buffer - if viper.GetString("cloud") == flagset.CloudK3d { + if viper.GetString("cloud") == pkg.CloudK3d { handOffData.WriteString("\n--- Metaphor ") handOffData.WriteString(strings.Repeat("-", 57)) handOffData.WriteString("\n To access the metaphor applications you'll need to \n`kubectl port-forward` to the kubernetes service") diff --git a/internal/terraform/terraform.go b/internal/terraform/terraform.go index f29140e07..c220c0277 100644 --- a/internal/terraform/terraform.go +++ b/internal/terraform/terraform.go @@ -12,7 +12,6 @@ import ( "github.com/kubefirst/kubefirst/configs" "github.com/kubefirst/kubefirst/internal/aws" - "github.com/kubefirst/kubefirst/internal/flagset" "github.com/kubefirst/kubefirst/pkg" "github.com/spf13/viper" ) @@ -41,7 +40,7 @@ func terraformConfig(terraformEntryPoint string) map[string]string { return envs case "vault": - if viper.GetString("cloud") == flagset.CloudLocal { + if viper.GetString("cloud") == pkg.CloudK3d { envs["TF_VAR_email_address"] = viper.GetString("adminemail") envs["TF_VAR_github_token"] = os.Getenv("KUBEFIRST_GITHUB_AUTH_TOKEN") envs["TF_VAR_vault_addr"] = viper.GetString("vault.local.service")