From d6820df2511f41718706666c18b67509f9a9f086 Mon Sep 17 00:00:00 2001 From: Jared Edwards Date: Sun, 23 Oct 2022 07:33:37 -0600 Subject: [PATCH 1/4] initial commit for url updates --- cmd/postInstall.go | 20 ++++++--- internal/argocd/argocd_test.go | 20 +++++++-- internal/chartMuseum/chartChecker.go | 1 + internal/gitClient/git.go | 2 +- internal/gitlab/gitlab_test.go | 9 ++-- internal/repo/kubefirstTemplate.go | 1 + internal/reports/section.go | 66 ++++++++++++++++++++++++++-- 7 files changed, 99 insertions(+), 20 deletions(-) diff --git a/cmd/postInstall.go b/cmd/postInstall.go index 7ee2ddedc..31d639523 100644 --- a/cmd/postInstall.go +++ b/cmd/postInstall.go @@ -1,17 +1,18 @@ package cmd import ( + "fmt" "log" - "fmt" - "time" "runtime" + "time" "github.com/kubefirst/kubefirst/internal/flagset" "github.com/kubefirst/kubefirst/internal/reports" - - "github.com/kubefirst/kubefirst/pkg" + + "github.com/kubefirst/kubefirst/pkg" "github.com/spf13/cobra" + "github.com/spf13/viper" ) var postInstallCmd = &cobra.Command{ @@ -29,7 +30,6 @@ var postInstallCmd = &cobra.Command{ return err } - if createFlags.EnableConsole { log.Println("Starting the presentation of console and api for the handoff screen") go func() { @@ -50,8 +50,14 @@ var postInstallCmd = &cobra.Command{ log.Println("Skipping the presentation of console and api for the handoff screen") } - openbrowser("http://localhost:9094") - reports.HandoffScreen(globalFlags.DryRun, globalFlags.SilentMode) + openbrowser("http://localhost:9094") + + if viper.GetString("cloud") == flagset.CloudK3d { + reports.HandoffLocalScreen(globalFlags.DryRun, globalFlags.SilentMode) + } else { + reports.HandoffScreen(globalFlags.DryRun, globalFlags.SilentMode) + } + time.Sleep(time.Millisecond * 2000) return nil }, diff --git a/internal/argocd/argocd_test.go b/internal/argocd/argocd_test.go index 26a0014e2..c97e5cf5f 100644 --- a/internal/argocd/argocd_test.go +++ b/internal/argocd/argocd_test.go @@ -2,11 +2,13 @@ package argocd_test import ( "fmt" + "net/http" + "testing" + "github.com/kubefirst/kubefirst/configs" + "github.com/kubefirst/kubefirst/internal/flagset" "github.com/kubefirst/kubefirst/pkg" "github.com/spf13/viper" - "net/http" - "testing" ) // this is called when ArgoCD is up and running @@ -22,7 +24,12 @@ func TestArgoCDLivenessIntegration(t *testing.T) { t.Error(err) } - argoURL := fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename")) + var argoURL string + if viper.GetString("cloud") == flagset.CloudK3d { + argoURL = "http://localhost:8080" + } else { + argoURL = fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename")) + } req, err := http.NewRequest(http.MethodGet, argoURL, nil) if err != nil { @@ -52,7 +59,12 @@ func TestArgoWorkflowLivenessIntegration(t *testing.T) { t.Error(err) } - argoURL := fmt.Sprintf("https://argo.%s", viper.GetString("aws.hostedzonename")) + var argoURL string + if viper.GetString("cloud") == flagset.CloudK3d { + argoURL = "http://localhost:8080" + } else { + argoURL = fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename")) + } req, err := http.NewRequest(http.MethodGet, argoURL, nil) if err != nil { diff --git a/internal/chartMuseum/chartChecker.go b/internal/chartMuseum/chartChecker.go index ce3de7921..9612cc8f7 100644 --- a/internal/chartMuseum/chartChecker.go +++ b/internal/chartMuseum/chartChecker.go @@ -12,6 +12,7 @@ import ( // IsChartMuseumReady - check is current instance of ChartMuseum is ready to receive deployments // refers to: https://github.com/kubefirst/kubefirst/issues/386 func IsChartMuseumReady() (bool, error) { + // todo local uses a different function pkg.AwaitHostNTimes url := fmt.Sprintf("https://chartmuseum.%s/index.yaml", viper.GetString("aws.hostedzonename")) response, err := httpCommon.CustomHttpClient(false).Get(url) diff --git a/internal/gitClient/git.go b/internal/gitClient/git.go index c08010d86..e4a7349d3 100644 --- a/internal/gitClient/git.go +++ b/internal/gitClient/git.go @@ -211,7 +211,7 @@ func PushGitopsToSoftServe() { // In the absence of matching tag/branch function will fail func CloneTemplateRepoWithFallBack(githubOrg string, repoName string, directory string, branch string, fallbackTag string) error { defer viper.WriteConfig() - + // todo need to refactor this and have the repoName include -template repoURL := fmt.Sprintf("https://github.com/%s/%s-template", githubOrg, repoName) isMainBranch := true diff --git a/internal/gitlab/gitlab_test.go b/internal/gitlab/gitlab_test.go index 707c8a08f..d820bc577 100644 --- a/internal/gitlab/gitlab_test.go +++ b/internal/gitlab/gitlab_test.go @@ -2,9 +2,10 @@ package gitlab_test import ( "fmt" - "github.com/kubefirst/kubefirst/configs" "net/http" "testing" + + "github.com/kubefirst/kubefirst/configs" ) // this is called when GitLab should be up and running @@ -19,10 +20,10 @@ func TestGitLabLivenessIntegration(t *testing.T) { t.Error("HOSTED_ZONE_NAME environment variable is not set") return } + // todo local we don't call this function + gitlabUrl := fmt.Sprintf("https://gitlab.%s", config.HostedZoneName) - argoURL := fmt.Sprintf("https://gitlab.%s", config.HostedZoneName) - - req, err := http.NewRequest(http.MethodGet, argoURL, nil) + req, err := http.NewRequest(http.MethodGet, gitlabUrl, nil) if err != nil { t.Error(err) } diff --git a/internal/repo/kubefirstTemplate.go b/internal/repo/kubefirstTemplate.go index b6d7a9f28..62f37e828 100644 --- a/internal/repo/kubefirstTemplate.go +++ b/internal/repo/kubefirstTemplate.go @@ -71,6 +71,7 @@ func PrepareKubefirstTemplateRepo(dryRun bool, config *configs.Config, githubOrg repo, err := git.PlainOpen(directory) + // todo these values should be constructed upfront on init when we get the users info if viper.GetBool("github.enabled") { githubHost := viper.GetString("github.host") githubOwner := viper.GetString("github.owner") diff --git a/internal/reports/section.go b/internal/reports/section.go index 2d9cc409c..1faa7e28c 100644 --- a/internal/reports/section.go +++ b/internal/reports/section.go @@ -6,12 +6,14 @@ import ( "log" "strings" + "github.com/kubefirst/kubefirst/internal/flagset" "github.com/spf13/viper" ) func PrintSectionRepoGithub() []byte { var handOffData bytes.Buffer + // todo construct these urls upfront on init handOffData.WriteString("\n--- Github ") handOffData.WriteString(strings.Repeat("-", 59)) handOffData.WriteString(fmt.Sprintf("\n owner: %s", viper.GetString("github.owner"))) @@ -58,19 +60,35 @@ func PrintSectionAws() []byte { } func PrintSectionVault() []byte { + + var vaultURL string + if viper.GetString("cloud") == flagset.CloudK3d { + vaultURL = "http://localhost:8200" + } else { + vaultURL = fmt.Sprintf("https://vault.%s", viper.GetString("aws.hostedzonename")) + } + var handOffData bytes.Buffer handOffData.WriteString("\n--- Vault ") handOffData.WriteString(strings.Repeat("-", 60)) - handOffData.WriteString(fmt.Sprintf("\n URL: %s", fmt.Sprintf("https://vault.%s", viper.GetString("aws.hostedzonename")))) + handOffData.WriteString(fmt.Sprintf("\n URL: %s", vaultURL)) handOffData.WriteString(fmt.Sprintf("\n token: %s", viper.GetString("vault.token"))) return handOffData.Bytes() } func PrintSectionArgoCD() []byte { + + var argoCdURL string + if viper.GetString("cloud") == flagset.CloudK3d { + argoCdURL = "http://localhost:8080" + } else { + argoCdURL = fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename")) + } + var handOffData bytes.Buffer handOffData.WriteString("\n--- ArgoCD ") handOffData.WriteString(strings.Repeat("-", 59)) - handOffData.WriteString(fmt.Sprintf("\n URL: %s", fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename")))) + handOffData.WriteString(fmt.Sprintf("\n URL: %s", argoCdURL)) handOffData.WriteString(fmt.Sprintf("\n username: %s", viper.GetString("argocd.admin.username"))) handOffData.WriteString(fmt.Sprintf("\n password: %s", viper.GetString("argocd.admin.password"))) @@ -78,11 +96,18 @@ func PrintSectionArgoCD() []byte { } func PrintSectionArgoWorkflows() []byte { - var handOffData bytes.Buffer + var argoWorkflowsURL string + if viper.GetString("cloud") == flagset.CloudK3d { + argoWorkflowsURL = "http://localhost:8080" + } else { + argoWorkflowsURL = fmt.Sprintf("https://argo.%s", viper.GetString("aws.hostedzonename")) + } + + var handOffData bytes.Buffer handOffData.WriteString("\n--- Argo Workflows ") handOffData.WriteString(strings.Repeat("-", 51)) - handOffData.WriteString(fmt.Sprintf("\n URL: %s", fmt.Sprintf("https://argo.%s", viper.GetString("aws.hostedzonename")))) + handOffData.WriteString(fmt.Sprintf("\n URL: %s", argoWorkflowsURL)) handOffData.WriteString("\n sso credentials only ") handOffData.WriteString("\n * sso enabled ") @@ -182,6 +207,39 @@ func HandoffScreen(dryRun bool, silentMode bool) { } +//HandoffScreen - prints the handoff screen +func LocalHandoffScreen(dryRun bool, silentMode bool) { + // prepare data for the handoff report + if dryRun { + log.Printf("[#99] Dry-run mode, LocalHandoffScreen skipped.") + return + } + + if silentMode { + log.Printf("[#99] Silent mode enabled, LocalHandoffScreen skipped, please check ~/.kubefirst file for your cluster and service credentials.") + return + } + + var handOffData bytes.Buffer + handOffData.Write(PrintSectionOverview()) + if viper.GetBool("github.enabled") { + handOffData.Write(PrintSectionRepoGithub()) + } else { + handOffData.Write(PrintSectionRepoGitlab()) + } + handOffData.Write(PrintSectionVault()) + handOffData.Write(PrintSectionArgoCD()) + handOffData.Write(PrintSectionArgoWorkflows()) + handOffData.Write(PrintSectionAtlantis()) + handOffData.Write(PrintSectionMuseum()) + handOffData.Write(PrintSectionMetaphorFrontend()) + handOffData.Write(PrintSectionMetaphorGo()) + handOffData.Write(PrintSectionMetaphor()) + + CommandSummary(handOffData) + +} + func GitHubAuthToken(userCode, verificationUri string) string { var gitHubTokenReport bytes.Buffer gitHubTokenReport.WriteString(strings.Repeat("-", 69)) From ab9384585f5e8c009e43d8046a6fb82f0c6c9583 Mon Sep 17 00:00:00 2001 From: Jared Edwards Date: Sun, 23 Oct 2022 09:20:15 -0600 Subject: [PATCH 2/4] tweaks to local handoff screen --- cmd/postInstall.go | 2 +- internal/reports/create.go | 2 +- internal/reports/section.go | 94 +++++++++++++++++++++++++------------ 3 files changed, 66 insertions(+), 32 deletions(-) diff --git a/cmd/postInstall.go b/cmd/postInstall.go index 31d639523..3d13a29ee 100644 --- a/cmd/postInstall.go +++ b/cmd/postInstall.go @@ -53,7 +53,7 @@ var postInstallCmd = &cobra.Command{ openbrowser("http://localhost:9094") if viper.GetString("cloud") == flagset.CloudK3d { - reports.HandoffLocalScreen(globalFlags.DryRun, globalFlags.SilentMode) + reports.LocalHandoffScreen(globalFlags.DryRun, globalFlags.SilentMode) } else { reports.HandoffScreen(globalFlags.DryRun, globalFlags.SilentMode) } diff --git a/internal/reports/create.go b/internal/reports/create.go index 4eea9b7bf..8cfb464b6 100644 --- a/internal/reports/create.go +++ b/internal/reports/create.go @@ -42,7 +42,7 @@ func BuildCreateHandOffReport(clusterData CreateHandOff) bytes.Buffer { var handOffData bytes.Buffer handOffData.WriteString(strings.Repeat("-", 70)) handOffData.WriteString(fmt.Sprintf("\nCluster %q is up and running!:", clusterData.ClusterName)) - handOffData.WriteString(fmt.Sprintf("\nSave this information for future use, once you leave this screen some of this information is lost. ")) + handOffData.WriteString("\nThis information is available at $HOME/.kubefirst ") handOffData.WriteString(fmt.Sprintf("\nPress ESC to leave this screen and return to shell.")) //handOffData.WriteString(strings.Repeat("-", 70)) diff --git a/internal/reports/section.go b/internal/reports/section.go index 1faa7e28c..045feccad 100644 --- a/internal/reports/section.go +++ b/internal/reports/section.go @@ -42,9 +42,9 @@ func PrintSectionOverview() []byte { var handOffData bytes.Buffer handOffData.WriteString(strings.Repeat("-", 70)) handOffData.WriteString(fmt.Sprintf("\nCluster %q is up and running!:", viper.GetString("cluster-name"))) - handOffData.WriteString(fmt.Sprintf("\nSave this information for future use, once you leave this screen some of this information is lost. ")) - handOffData.WriteString(fmt.Sprintf("\n\nAccess the Console on your Browser at: http://localhost:9094\n")) - handOffData.WriteString(fmt.Sprintf("\nPress ESC to leave this screen and return to shell.")) + handOffData.WriteString("\nThis information is available at $HOME/.kubefirst ") + handOffData.WriteString("\n\nAccess the kubefirst-console from your browser at:\n http://localhost:9094\n") + handOffData.WriteString("\nPress ESC to leave this screen and return to your shell.") return handOffData.Bytes() } @@ -99,7 +99,7 @@ func PrintSectionArgoWorkflows() []byte { var argoWorkflowsURL string if viper.GetString("cloud") == flagset.CloudK3d { - argoWorkflowsURL = "http://localhost:8080" + argoWorkflowsURL = "http://localhost:2746" } else { argoWorkflowsURL = fmt.Sprintf("https://argo.%s", viper.GetString("aws.hostedzonename")) } @@ -108,31 +108,56 @@ func PrintSectionArgoWorkflows() []byte { handOffData.WriteString("\n--- Argo Workflows ") handOffData.WriteString(strings.Repeat("-", 51)) handOffData.WriteString(fmt.Sprintf("\n URL: %s", argoWorkflowsURL)) - handOffData.WriteString("\n sso credentials only ") - handOffData.WriteString("\n * sso enabled ") - return handOffData.Bytes() + if viper.GetString("cloud") == flagset.CloudK3d { + return handOffData.Bytes() + } else { + handOffData.WriteString("\n sso credentials only ") + handOffData.WriteString("\n * sso enabled ") + + return handOffData.Bytes() + } } func PrintSectionAtlantis() []byte { - var handOffData bytes.Buffer + var atlantisUrl string + if viper.GetString("cloud") == flagset.CloudK3d { + atlantisUrl = "http://localhost:4141" + } else { + atlantisUrl = fmt.Sprintf("https://atlantis.%s", viper.GetString("aws.hostedzonename")) + } + + var handOffData bytes.Buffer handOffData.WriteString("\n--- Atlantis ") handOffData.WriteString(strings.Repeat("-", 57)) - handOffData.WriteString(fmt.Sprintf("\n URL: %s", fmt.Sprintf("https://atlantis.%s", viper.GetString("aws.hostedzonename")))) + handOffData.WriteString(fmt.Sprintf("\n URL: %s", atlantisUrl)) return handOffData.Bytes() } func PrintSectionMuseum() []byte { + + var chartmuseumURL string + if viper.GetString("cloud") == flagset.CloudK3d { + chartmuseumURL = "http://localhost:8181" + } else { + chartmuseumURL = fmt.Sprintf("https://chartmuseum.%s", viper.GetString("aws.hostedzonename")) + } + var handOffData bytes.Buffer + handOffData.WriteString("\n--- Chartmuseum ") + handOffData.WriteString(strings.Repeat("-", 54)) + handOffData.WriteString(fmt.Sprintf("\n URL: %s", chartmuseumURL)) - handOffData.WriteString("\n--- Museum ") - handOffData.WriteString(strings.Repeat("-", 59)) - handOffData.WriteString(fmt.Sprintf("\n URL: %s\n", fmt.Sprintf("https://chartmuseum.%s", viper.GetString("aws.hostedzonename")))) - handOffData.WriteString(" see vault for credentials ") + if viper.GetString("cloud") == flagset.CloudK3d { + return handOffData.Bytes() + } else { + handOffData.WriteString("\n see vault for credentials ") + + return handOffData.Bytes() + } - return handOffData.Bytes() } func PrintSectionMetaphor() []byte { @@ -162,15 +187,30 @@ func PrintSectionMetaphorGo() []byte { func PrintSectionMetaphorFrontend() []byte { var handOffData bytes.Buffer - - handOffData.WriteString("\n--- Metaphor Frontend") - handOffData.WriteString(strings.Repeat("-", 49)) - handOffData.WriteString(fmt.Sprintf("\n Development: %s", fmt.Sprintf("https://metaphor-frontend-development.%s", viper.GetString("aws.hostedzonename")))) - handOffData.WriteString(fmt.Sprintf("\n Staging: %s", fmt.Sprintf("https://metaphor-frontend-staging.%s", viper.GetString("aws.hostedzonename")))) - handOffData.WriteString(fmt.Sprintf("\n Production: %s\n", fmt.Sprintf("https://metaphor-frontend-production.%s", viper.GetString("aws.hostedzonename")))) - handOffData.WriteString(strings.Repeat("-", 70)) - - return handOffData.Bytes() + if viper.GetString("cloud") == flagset.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") + handOffData.WriteString("\n\n kubectl -n development port-forward svc/metaphor-frontend-development 3000:443") + handOffData.WriteString("\n http://localhost:3000\n") + handOffData.WriteString("\n kubectl -n staging port-forward svc/metaphor-frontend-staging 3001:443") + handOffData.WriteString("\n http://localhost:3001\n") + handOffData.WriteString("\n kubectl -n production port-forward svc/metaphor-frontend-production 3002:443") + handOffData.WriteString("\n http://localhost:3002\n") + handOffData.WriteString(strings.Repeat("-", 70)) + + return handOffData.Bytes() + } else { + var handOffData bytes.Buffer + handOffData.WriteString("\n--- Metaphor Frontend") + handOffData.WriteString(strings.Repeat("-", 57)) + handOffData.WriteString(fmt.Sprintf("\n Development: %s", fmt.Sprintf("https://metaphor-frontend-development.%s", viper.GetString("aws.hostedzonename")))) + handOffData.WriteString(fmt.Sprintf("\n Staging: %s", fmt.Sprintf("https://metaphor-frontend-staging.%s", viper.GetString("aws.hostedzonename")))) + handOffData.WriteString(fmt.Sprintf("\n Production: %s\n", fmt.Sprintf("https://metaphor-frontend-production.%s", viper.GetString("aws.hostedzonename")))) + handOffData.WriteString(strings.Repeat("-", 70)) + + return handOffData.Bytes() + } } //HandoffScreen - prints the handoff screen @@ -222,19 +262,13 @@ func LocalHandoffScreen(dryRun bool, silentMode bool) { var handOffData bytes.Buffer handOffData.Write(PrintSectionOverview()) - if viper.GetBool("github.enabled") { - handOffData.Write(PrintSectionRepoGithub()) - } else { - handOffData.Write(PrintSectionRepoGitlab()) - } + handOffData.Write(PrintSectionRepoGithub()) handOffData.Write(PrintSectionVault()) handOffData.Write(PrintSectionArgoCD()) handOffData.Write(PrintSectionArgoWorkflows()) handOffData.Write(PrintSectionAtlantis()) handOffData.Write(PrintSectionMuseum()) handOffData.Write(PrintSectionMetaphorFrontend()) - handOffData.Write(PrintSectionMetaphorGo()) - handOffData.Write(PrintSectionMetaphor()) CommandSummary(handOffData) From 455a2ce2c02dc0b88d64d2a4da503a9dde38a5d9 Mon Sep 17 00:00:00 2001 From: Jared Edwards Date: Mon, 24 Oct 2022 12:45:55 -0600 Subject: [PATCH 3/4] Update internal/argocd/argocd_test.go --- internal/argocd/argocd_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/argocd/argocd_test.go b/internal/argocd/argocd_test.go index c97e5cf5f..df9b38d1e 100644 --- a/internal/argocd/argocd_test.go +++ b/internal/argocd/argocd_test.go @@ -61,7 +61,7 @@ func TestArgoWorkflowLivenessIntegration(t *testing.T) { var argoURL string if viper.GetString("cloud") == flagset.CloudK3d { - argoURL = "http://localhost:8080" + argoURL = "http://localhost:2746" } else { argoURL = fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename")) } From e82efd04330be93a0bd1055e69f114f67315c62a Mon Sep 17 00:00:00 2001 From: Jared Edwards Date: Mon, 24 Oct 2022 12:46:30 -0600 Subject: [PATCH 4/4] Update internal/argocd/argocd_test.go --- internal/argocd/argocd_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/argocd/argocd_test.go b/internal/argocd/argocd_test.go index df9b38d1e..1d431427b 100644 --- a/internal/argocd/argocd_test.go +++ b/internal/argocd/argocd_test.go @@ -63,7 +63,7 @@ func TestArgoWorkflowLivenessIntegration(t *testing.T) { if viper.GetString("cloud") == flagset.CloudK3d { argoURL = "http://localhost:2746" } else { - argoURL = fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename")) + argoURL = fmt.Sprintf("https://argo.%s", viper.GetString("aws.hostedzonename")) } req, err := http.NewRequest(http.MethodGet, argoURL, nil)