log: improve cmd logs
This commit is contained in:
@@ -69,6 +69,7 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
logAction("checking controllers")
|
||||
if !componentsCheck() {
|
||||
checkFailed = true
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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-",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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...))
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user