log: improve cmd logs
This commit is contained in:
@@ -69,6 +69,7 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logAction("checking controllers")
|
||||||
if !componentsCheck() {
|
if !componentsCheck() {
|
||||||
checkFailed = true
|
checkFailed = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
logAction("generating %s kustomization", name)
|
logGenerate("generating kustomization")
|
||||||
|
|
||||||
emptyAPIGroup := ""
|
emptyAPIGroup := ""
|
||||||
kustomization := kustomizev1.Kustomization{
|
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 {
|
if err := upsertKustomization(ctx, kubeClient, kustomization); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,11 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
withAuth = true
|
withAuth = true
|
||||||
}
|
}
|
||||||
|
|
||||||
logAction("generating git source %s in %s namespace", name, namespace)
|
if withAuth {
|
||||||
|
logSuccess("authentication configured")
|
||||||
|
}
|
||||||
|
|
||||||
|
logGenerate("generating source")
|
||||||
|
|
||||||
gitRepository := sourcev1.GitRepository{
|
gitRepository := sourcev1.GitRepository{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
@@ -148,6 +152,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logAction("applying source")
|
||||||
if err := upsertGitRepository(ctx, kubeClient, gitRepository); err != nil {
|
if err := upsertGitRepository(ctx, kubeClient, gitRepository); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -191,14 +196,14 @@ func generateBasicAuth(ctx context.Context, name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func generateSSH(ctx context.Context, name, host, tmpDir 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)
|
command := fmt.Sprintf("ssh-keyscan %s > %s/known_hosts", host, tmpDir)
|
||||||
if _, err := utils.execCommand(ctx, ModeStderrOS, command); err != nil {
|
if _, err := utils.execCommand(ctx, ModeStderrOS, command); err != nil {
|
||||||
return fmt.Errorf("ssh-keyscan failed")
|
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)
|
command = fmt.Sprintf("ssh-keygen -b 2048 -t rsa -f %s/identity -q -N \"\"", tmpDir)
|
||||||
if _, err := utils.execCommand(ctx, ModeStderrOS, command); err != nil {
|
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")
|
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",
|
files := fmt.Sprintf("--from-file=%s/identity --from-file=%s/identity.pub --from-file=%s/known_hosts",
|
||||||
tmpDir, tmpDir, tmpDir)
|
tmpDir, tmpDir, tmpDir)
|
||||||
secret := fmt.Sprintf("kubectl -n %s create secret generic %s %s --dry-run=client -oyaml | kubectl apply -f-",
|
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)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
logAction("generating install manifests")
|
logGenerate("generating manifests")
|
||||||
if kustomizePath == "" {
|
if kustomizePath == "" {
|
||||||
err = genInstallManifests(installVersion, namespace, components, tmpDir)
|
err = genInstallManifests(installVersion, namespace, components, tmpDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -86,9 +86,9 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
fmt.Print(yaml)
|
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
|
applyOutput := ModeStderrOS
|
||||||
if verbose {
|
if verbose {
|
||||||
applyOutput = ModeOS
|
applyOutput = ModeOS
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func logAction(format string, a ...interface{}) {
|
func logAction(format string, a ...interface{}) {
|
||||||
|
fmt.Println(`►`, fmt.Sprintf(format, a...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func logGenerate(format string, a ...interface{}) {
|
||||||
fmt.Println(`✚`, fmt.Sprintf(format, a...))
|
fmt.Println(`✚`, fmt.Sprintf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ cluster role bindings and CRDs.`,
|
|||||||
Example: ` # Dry-run uninstall of all components
|
Example: ` # Dry-run uninstall of all components
|
||||||
uninstall --dry-run --namespace=gitops-system
|
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
|
uninstall --crds --namespace=gitops-system
|
||||||
`,
|
`,
|
||||||
RunE: uninstallCmdRun,
|
RunE: uninstallCmdRun,
|
||||||
|
|||||||
Reference in New Issue
Block a user