Skip to content

Commit

Permalink
Address ui issues (#124)
Browse files Browse the repository at this point in the history
Signed-off-by: 6za <53096417+6za@users.noreply.github.com>
Signed-off-by: Thiago Pagotto <pagottoo@gmail.com>
  • Loading branch information
6za authored and pagottoo committed Jul 19, 2022
1 parent 432fbb2 commit ad2f749
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 59 deletions.
107 changes: 66 additions & 41 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {

var kPortForwardArgocd *exec.Cmd
progressPrinter.AddTracker("step-0", "Process Parameters", 1)
config := configs.ReadConfig()

Expand Down Expand Up @@ -106,17 +107,19 @@ to quickly create a Cobra application.`,
informUser("ArgoCD Ready")
progressPrinter.IncrementTracker("step-argo", 1)

var kPortForwardArgocdOutb, kPortForwardArgocdErrb bytes.Buffer
kPortForwardArgocd := exec.Command(config.KubectlClientPath, "--kubeconfig", config.KubeConfigPath, "-n", "argocd", "port-forward", "svc/argocd-server", "8080:80")
kPortForwardArgocd.Stdout = &kPortForwardArgocdOutb
kPortForwardArgocd.Stderr = &kPortForwardArgocdErrb
err = kPortForwardArgocd.Start()
defer kPortForwardArgocd.Process.Signal(syscall.SIGTERM)
if err != nil {
log.Printf("Commad Execution STDOUT: %s", kPortForwardArgocdOutb.String())
log.Printf("Commad Execution STDERR: %s", kPortForwardArgocdErrb.String())
log.Panicf("error: failed to port-forward to argocd in main thread %s", err)
}
if !dryRun {
var kPortForwardArgocdOutb, kPortForwardArgocdErrb bytes.Buffer
kPortForwardArgocd = exec.Command(config.KubectlClientPath, "--kubeconfig", config.KubeConfigPath, "-n", "argocd", "port-forward", "svc/argocd-server", "8080:80")
kPortForwardArgocd.Stdout = &kPortForwardArgocdOutb
kPortForwardArgocd.Stderr = &kPortForwardArgocdErrb
err = kPortForwardArgocd.Start()
defer kPortForwardArgocd.Process.Signal(syscall.SIGTERM)
if err != nil {
log.Printf("Commad Execution STDOUT: %s", kPortForwardArgocdOutb.String())
log.Printf("Commad Execution STDERR: %s", kPortForwardArgocdErrb.String())
log.Panicf("error: failed to port-forward to argocd in main thread %s", err)
}
}

// log.Println("sleeping for 45 seconds, hurry up jared")
// time.Sleep(45 * time.Second)
Expand All @@ -131,12 +134,13 @@ to quickly create a Cobra application.`,
informUser("Getting an argocd auth token")
token := argocd.GetArgocdAuthToken(dryRun)
progressPrinter.IncrementTracker("step-argo", 1)

_, _, err = pkg.ExecShellReturnStrings(config.KubectlClientPath, "--kubeconfig", config.KubeConfigPath, "-n", "argocd", "apply", "-f", fmt.Sprintf("%s/gitops/components/helpers/registry.yaml", config.K1FolderPath))
if err != nil {
log.Panicf("failed to call execute kubectl apply of argocd patch to adopt gitlab: %s", err)
if !dryRun {
_, _, err = pkg.ExecShellReturnStrings(config.KubectlClientPath, "--kubeconfig", config.KubeConfigPath, "-n", "argocd", "apply", "-f", fmt.Sprintf("%s/gitops/components/helpers/registry.yaml", config.K1FolderPath))
if err != nil {
log.Panicf("failed to call execute kubectl apply of argocd patch to adopt gitlab: %s", err)
}
time.Sleep(45 * time.Second)
}
time.Sleep(45 * time.Second)
//TODO: ensure argocd is in a good heathy state before syncing the registry application

informUser("Syncing the registry application")
Expand Down Expand Up @@ -236,9 +240,8 @@ to quickly create a Cobra application.`,
informUser("Vault secret created")
progressPrinter.IncrementTracker("step-vault", 1)
}

if !viper.GetBool("gitlab.oidc-created") {
progressPrinter.AddTracker("step-post-gitlab", "Finalize Gitlab updates", 5)
progressPrinter.AddTracker("step-post-gitlab", "Finalize Gitlab updates", 5)
if !viper.GetBool("gitlab.oidc-created") {
vault.AddGitlabOidcApplications(dryRun)
informUser("Added Gitlab OIDC")
progressPrinter.IncrementTracker("step-post-gitlab", 1)
Expand Down Expand Up @@ -306,20 +309,22 @@ to quickly create a Cobra application.`,

// informUser("Waiting for argocd host to resolve")
// gitlab.AwaitHost("argocd", dryRun)
cfg := configs.ReadConfig()
config, err := clientcmd.BuildConfigFromFlags("", cfg.KubeConfigPath)
if err != nil {
panic(err.Error())
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
if !dryRun {
cfg := configs.ReadConfig()
config, err := clientcmd.BuildConfigFromFlags("", cfg.KubeConfigPath)
if err != nil {
panic(err.Error())
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
argocdPodClient := clientset.CoreV1().Pods("argocd")
argocdPodName := k8s.GetPodNameByLabel(argocdPodClient, "app.kubernetes.io/name=argocd-server")
kPortForwardArgocd.Process.Signal(syscall.SIGTERM)
informUser("deleting argocd-server pod")
k8s.DeletePodByName(argocdPodClient, argocdPodName)
}
argocdPodClient := clientset.CoreV1().Pods("argocd")
argocdPodName := k8s.GetPodNameByLabel(argocdPodClient, "app.kubernetes.io/name=argocd-server")
kPortForwardArgocd.Process.Signal(syscall.SIGTERM)
informUser("deleting argocd-server pod")
k8s.DeletePodByName(argocdPodClient, argocdPodName)
informUser("waiting for argocd to be ready")
waitArgoCDToBeReady(dryRun)

Expand Down Expand Up @@ -353,30 +358,50 @@ to quickly create a Cobra application.`,
sendCompleteInstallTelemetry(dryRun)
time.Sleep(time.Millisecond * 100)

if dryRun {
log.Println("no handoff data on dry-run mode")
return
}


// prepare data for the handoff report
clusterData := reports.CreateHandOff{
ClusterName: viper.GetString("cluster-name"),
AwsAccountId: viper.GetString("aws.accountid"),
AwsHostedZoneName: viper.GetString("aws.hostedzonename"),
AwsRegion: viper.GetString("aws.region"),
ArgoCDUrl: viper.GetString("argocd.local.service"),
ClusterName: viper.GetString("cluster-name"),

GitlabURL: fmt.Sprintf("https://gitlab.%s", viper.GetString("aws.hostedzonename")),
GitlabUser: "root" ,
GitlabPassword: viper.GetString("gitlab.token") ,

RepoGitops: fmt.Sprintf("https://gitlab.%s/kubefirst/gitops", viper.GetString("aws.hostedzonename")),
RepoMetaphor: fmt.Sprintf("https://gitlab.%s/kubefirst/metaphor", viper.GetString("aws.hostedzonename")),


VaultUrl: fmt.Sprintf("https://vault.%s", viper.GetString("aws.hostedzonename")),
VaultToken: viper.GetString("vault.token"),


ArgoCDUrl: fmt.Sprintf("https://argocd.%s", viper.GetString("aws.hostedzonename")),
ArgoCDUsername: viper.GetString("argocd.admin.username"),
ArgoCDPassword: viper.GetString("argocd.admin.password"),
VaultUrl: viper.GetString("vault.local.service"),
VaultToken: viper.GetString("vault.token"),

ArgoWorkflowsUrl: fmt.Sprintf("https://argo.%s", viper.GetString("aws.hostedzonename")),
AtlantisUrl: fmt.Sprintf("https://atlantis.%s", viper.GetString("aws.hostedzonename")),
ChartMuseumUrl: fmt.Sprintf("https://chartmuseum.%s", viper.GetString("aws.hostedzonename")),

MetaphorDevUrl: fmt.Sprintf("https://metaphor-development.%s", viper.GetString("aws.hostedzonename")),
MetaphorStageUrl: fmt.Sprintf("https://metaphor-staging.%s", viper.GetString("aws.hostedzonename")),
MetaphorProductionUrl: fmt.Sprintf("https://metaphor-production.%s", viper.GetString("aws.hostedzonename")),

}

// build the string that will be sent to the report
handOffData := reports.BuildCreateHandOffReport(clusterData)

// call handoff report and apply style
reports.CommandSummary(handOffData)





},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,6 @@ func init() {
initCmd.Flags().Bool("dry-run", false, "set to dry-run mode, no changes done on cloud provider selected")
log.Println("init started")

initCmd.Flags().String("cluster-name", "k1st", "the cluster name, used to identify resources on cloud provider")
initCmd.Flags().String("cluster-name", "kubefirst", "the cluster name, used to identify resources on cloud provider")
initCmd.Flags().String("version-gitops", "main", "version/branch used on git clone")
}
91 changes: 74 additions & 17 deletions internal/reports/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,95 @@ type CreateHandOff struct {
AwsHostedZoneName string
AwsRegion string
ClusterName string

GitlabURL string
GitlabUser string
GitlabPassword string

RepoGitops string
RepoMetaphor string

VaultUrl string
VaultToken string

ArgoCDUrl string
ArgoCDUsername string
ArgoCDPassword string
VaultUrl string
VaultToken string

ArgoWorkflowsUrl string

AtlantisUrl string

ChartMuseumUrl string

MetaphorDevUrl string
MetaphorStageUrl string
MetaphorProductionUrl string


}

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!:\n", clusterData.ClusterName))
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(fmt.Sprintf("\nPress ESC to leave this screen and return to shell."))
//handOffData.WriteString(strings.Repeat("-", 70))

handOffData.WriteString("\n\n--- AWS ")
handOffData.WriteString("\n--- AWS ")
handOffData.WriteString(strings.Repeat("-", 62))
handOffData.WriteString(fmt.Sprintf("\n AWS Account Id: %s\n", clusterData.AwsAccountId))
handOffData.WriteString(fmt.Sprintf(" AWS hosted zone name: %s\n", clusterData.AwsHostedZoneName))
handOffData.WriteString(fmt.Sprintf(" AWS region: %s\n", clusterData.AwsRegion))
handOffData.WriteString(strings.Repeat("-", 70))
handOffData.WriteString(fmt.Sprintf("\n AWS Account Id: %s", clusterData.AwsAccountId))
handOffData.WriteString(fmt.Sprintf("\n AWS hosted zone name: %s", clusterData.AwsHostedZoneName))
handOffData.WriteString(fmt.Sprintf("\n AWS region: %s", clusterData.AwsRegion))
//handOffData.WriteString(strings.Repeat("-", 70))

handOffData.WriteString("\n\n--- ArgoCD ")
handOffData.WriteString("\n--- GitLab ")
handOffData.WriteString(strings.Repeat("-", 59))
handOffData.WriteString(fmt.Sprintf("\n URL: %s\n", clusterData.ArgoCDUrl))
handOffData.WriteString(fmt.Sprintf(" username: %s\n", clusterData.ArgoCDUsername))
handOffData.WriteString(fmt.Sprintf(" password: %s\n", clusterData.ArgoCDPassword))
handOffData.WriteString(strings.Repeat("-", 70))
handOffData.WriteString(fmt.Sprintf("\n username: %s", clusterData.GitlabUser))
handOffData.WriteString(fmt.Sprintf("\n password: %s", clusterData.GitlabPassword))
handOffData.WriteString("\n Repos: ")
handOffData.WriteString(fmt.Sprintf("\n %s",clusterData.RepoGitops))
handOffData.WriteString(fmt.Sprintf("\n %s",clusterData.RepoMetaphor))
//handOffData.WriteString(strings.Repeat("-", 70))

handOffData.WriteString("\n--- Vault ")
handOffData.WriteString(strings.Repeat("-", 60))
handOffData.WriteString(fmt.Sprintf("\n URL: %s", clusterData.VaultUrl))
handOffData.WriteString(fmt.Sprintf("\n token: %s", clusterData.VaultToken))
//handOffData.WriteString(strings.Repeat("-", 70))

handOffData.WriteString("\n\n--- Vault ")
handOffData.WriteString("\n--- ArgoCD ")
handOffData.WriteString(strings.Repeat("-", 59))
handOffData.WriteString(fmt.Sprintf("\n URL: %s\n", clusterData.VaultUrl))
handOffData.WriteString(fmt.Sprintf(" token: %s\n", clusterData.VaultToken))
handOffData.WriteString(fmt.Sprintf("\n URL: %s", clusterData.ArgoCDUrl))
handOffData.WriteString(fmt.Sprintf("\n username: %s", clusterData.ArgoCDUsername))
handOffData.WriteString(fmt.Sprintf("\n password: %s", clusterData.ArgoCDPassword))
//handOffData.WriteString(strings.Repeat("-", 70))

handOffData.WriteString("\n--- Argo Workflows ")
handOffData.WriteString(strings.Repeat("-", 51))
handOffData.WriteString(fmt.Sprintf("\n URL: %s", clusterData.ArgoWorkflowsUrl))
handOffData.WriteString("\n sso credentials only ")
handOffData.WriteString("\n * sso enabled ")
//handOffData.WriteString(strings.Repeat("-", 70))

handOffData.WriteString("\n--- Atlantis ")
handOffData.WriteString(strings.Repeat("-", 57))
handOffData.WriteString(fmt.Sprintf("\n URL: %s", clusterData.AtlantisUrl))
//handOffData.WriteString(strings.Repeat("-", 70))

handOffData.WriteString("\n--- Museum ")
handOffData.WriteString(strings.Repeat("-", 59))
handOffData.WriteString(fmt.Sprintf("\n URL: %s\n", clusterData.ChartMuseumUrl))
handOffData.WriteString(" see vault for credentials ")
//handOffData.WriteString(strings.Repeat("-", 70))

handOffData.WriteString("\n--- Metaphor ")
handOffData.WriteString(strings.Repeat("-", 57))
handOffData.WriteString(fmt.Sprintf("\n Development: %s", clusterData.MetaphorDevUrl))
handOffData.WriteString(fmt.Sprintf("\n Staging: %s", clusterData.MetaphorStageUrl))
handOffData.WriteString(fmt.Sprintf("\n Production: %s\n", clusterData.MetaphorProductionUrl))
handOffData.WriteString(strings.Repeat("-", 70))

return handOffData
Expand Down

0 comments on commit ad2f749

Please sign in to comment.