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

Draft: initial commit for url updates #606

Merged
merged 6 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
20 changes: 13 additions & 7 deletions cmd/postInstall.go
Original file line number Diff line number Diff line change
@@ -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{
Expand All @@ -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() {
Expand All @@ -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.LocalHandoffScreen(globalFlags.DryRun, globalFlags.SilentMode)
} else {
reports.HandoffScreen(globalFlags.DryRun, globalFlags.SilentMode)
}

time.Sleep(time.Millisecond * 2000)
return nil
},
Expand Down
20 changes: 16 additions & 4 deletions internal/argocd/argocd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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:2746"
jarededwards marked this conversation as resolved.
Show resolved Hide resolved
} else {
argoURL = fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename"))
jarededwards marked this conversation as resolved.
Show resolved Hide resolved
}

req, err := http.NewRequest(http.MethodGet, argoURL, nil)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/chartMuseum/chartChecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/gitClient/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions internal/gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/repo/kubefirstTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func UpdateForLocalMode(directory string) error {

},
}
err := cp.Copy(directory + "/localhost", directory, opt)
err := cp.Copy(directory+"/localhost", directory, opt)
if err != nil {
log.Println("Error populating gitops with local setup:", err)
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/reports/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
144 changes: 118 additions & 26 deletions internal/reports/section.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down Expand Up @@ -40,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()
}
Expand All @@ -58,56 +60,104 @@ 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")))

return handOffData.Bytes()
}

func PrintSectionArgoWorkflows() []byte {
var handOffData bytes.Buffer

var argoWorkflowsURL string
if viper.GetString("cloud") == flagset.CloudK3d {
argoWorkflowsURL = "http://localhost:2746"
} 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("\n sso credentials only ")
handOffData.WriteString("\n * sso enabled ")
handOffData.WriteString(fmt.Sprintf("\n URL: %s", argoWorkflowsURL))

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 {
Expand Down Expand Up @@ -137,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
Expand Down Expand Up @@ -182,6 +247,33 @@ 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())
handOffData.Write(PrintSectionRepoGithub())
handOffData.Write(PrintSectionVault())
handOffData.Write(PrintSectionArgoCD())
handOffData.Write(PrintSectionArgoWorkflows())
handOffData.Write(PrintSectionAtlantis())
handOffData.Write(PrintSectionMuseum())
handOffData.Write(PrintSectionMetaphorFrontend())

CommandSummary(handOffData)

}

func GitHubAuthToken(userCode, verificationUri string) string {
var gitHubTokenReport bytes.Buffer
gitHubTokenReport.WriteString(strings.Repeat("-", 69))
Expand Down