From cfa72ddb0b83f133dd5532ee13e43724ea5c5aca Mon Sep 17 00:00:00 2001
From: stefanprodan <stefan.prodan@gmail.com>
Date: Wed, 29 Apr 2020 09:35:49 +0300
Subject: [PATCH] log: improve cmd logs

---
 cmd/tk/check.go                |  1 +
 cmd/tk/create_kustomization.go |  3 ++-
 cmd/tk/create_source_git.go    | 13 +++++++++----
 cmd/tk/install.go              |  6 +++---
 cmd/tk/log.go                  |  4 ++++
 cmd/tk/uninstall.go            |  2 +-
 6 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/cmd/tk/check.go b/cmd/tk/check.go
index a5826ce2..5e3a04c2 100644
--- a/cmd/tk/check.go
+++ b/cmd/tk/check.go
@@ -69,6 +69,7 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
 		return nil
 	}
 
+	logAction("checking controllers")
 	if !componentsCheck() {
 		checkFailed = true
 	}
diff --git a/cmd/tk/create_kustomization.go b/cmd/tk/create_kustomization.go
index 54e6c5b2..b20c7487 100644
--- a/cmd/tk/create_kustomization.go
+++ b/cmd/tk/create_kustomization.go
@@ -95,7 +95,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
 		return err
 	}
 
-	logAction("generating %s kustomization", name)
+	logGenerate("generating kustomization")
 
 	emptyAPIGroup := ""
 	kustomization := kustomizev1.Kustomization{
@@ -154,6 +154,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
 		}
 	}
 
+	logAction("applying kustomization")
 	if err := upsertKustomization(ctx, kubeClient, kustomization); err != nil {
 		return err
 	}
diff --git a/cmd/tk/create_source_git.go b/cmd/tk/create_source_git.go
index 245c4d99..6c0a409b 100644
--- a/cmd/tk/create_source_git.go
+++ b/cmd/tk/create_source_git.go
@@ -113,7 +113,11 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
 		withAuth = true
 	}
 
-	logAction("generating git source %s in %s namespace", name, namespace)
+	if withAuth {
+		logSuccess("authentication configured")
+	}
+
+	logGenerate("generating source")
 
 	gitRepository := sourcev1.GitRepository{
 		ObjectMeta: metav1.ObjectMeta{
@@ -148,6 +152,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
 		return err
 	}
 
+	logAction("applying source")
 	if err := upsertGitRepository(ctx, kubeClient, gitRepository); err != nil {
 		return err
 	}
@@ -191,14 +196,14 @@ func generateBasicAuth(ctx context.Context, name string) error {
 }
 
 func generateSSH(ctx context.Context, name, host, tmpDir string) error {
-	logAction("generating host key for %s", host)
+	logGenerate("generating host key for %s", host)
 
 	command := fmt.Sprintf("ssh-keyscan %s > %s/known_hosts", host, tmpDir)
 	if _, err := utils.execCommand(ctx, ModeStderrOS, command); err != nil {
 		return fmt.Errorf("ssh-keyscan failed")
 	}
 
-	logAction("generating deploy key")
+	logGenerate("generating deploy key")
 
 	command = fmt.Sprintf("ssh-keygen -b 2048 -t rsa -f %s/identity -q -N \"\"", tmpDir)
 	if _, err := utils.execCommand(ctx, ModeStderrOS, command); err != nil {
@@ -220,7 +225,7 @@ func generateSSH(ctx context.Context, name, host, tmpDir string) error {
 		return fmt.Errorf("aborting")
 	}
 
-	logAction("saving deploy key")
+	logAction("saving keys")
 	files := fmt.Sprintf("--from-file=%s/identity --from-file=%s/identity.pub --from-file=%s/known_hosts",
 		tmpDir, tmpDir, tmpDir)
 	secret := fmt.Sprintf("kubectl -n %s create secret generic %s %s --dry-run=client -oyaml | kubectl apply -f-",
diff --git a/cmd/tk/install.go b/cmd/tk/install.go
index 04a093b2..021ef03a 100644
--- a/cmd/tk/install.go
+++ b/cmd/tk/install.go
@@ -63,7 +63,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
 	}
 	defer os.RemoveAll(tmpDir)
 
-	logAction("generating install manifests")
+	logGenerate("generating manifests")
 	if kustomizePath == "" {
 		err = genInstallManifests(installVersion, namespace, components, tmpDir)
 		if err != nil {
@@ -86,9 +86,9 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
 			fmt.Print(yaml)
 		}
 	}
-	logSuccess("build completed")
+	logSuccess("manifests build completed")
 
-	logWaiting("installing components in %s namespace", namespace)
+	logAction("installing components in %s namespace", namespace)
 	applyOutput := ModeStderrOS
 	if verbose {
 		applyOutput = ModeOS
diff --git a/cmd/tk/log.go b/cmd/tk/log.go
index c06f3b59..b2be7feb 100644
--- a/cmd/tk/log.go
+++ b/cmd/tk/log.go
@@ -3,6 +3,10 @@ package main
 import "fmt"
 
 func logAction(format string, a ...interface{}) {
+	fmt.Println(`►`, fmt.Sprintf(format, a...))
+}
+
+func logGenerate(format string, a ...interface{}) {
 	fmt.Println(`✚`, fmt.Sprintf(format, a...))
 }
 
diff --git a/cmd/tk/uninstall.go b/cmd/tk/uninstall.go
index 12f0411d..85adaee6 100644
--- a/cmd/tk/uninstall.go
+++ b/cmd/tk/uninstall.go
@@ -17,7 +17,7 @@ cluster role bindings and CRDs.`,
 	Example: `  # Dry-run uninstall of all components
    uninstall --dry-run --namespace=gitops-system
 
-  # Uninstall all components and custom resource definitions
+  # Uninstall all components and delete custom resource definitions
   uninstall --crds --namespace=gitops-system
 `,
 	RunE: uninstallCmdRun,
-- 
GitLab