From b265bfbe93a1517db935903a57af182cfb2e43a9 Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Fri, 2 Jun 2023 15:59:08 +0200 Subject: [PATCH] Hide spinner and std output since outputs are displayed --- pkg/component/execute_terminating.go | 22 +++++++++++++++------- pkg/exec/exec.go | 9 +++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/pkg/component/execute_terminating.go b/pkg/component/execute_terminating.go index a4a907641e9..1527a768831 100644 --- a/pkg/component/execute_terminating.go +++ b/pkg/component/execute_terminating.go @@ -18,7 +18,7 @@ import ( const ShellExecutable string = "/bin/sh" -func ExecuteTerminatingCommand(ctx context.Context, execClient exec.Client, platformClient platform.Client, command devfilev1.Command, componentExists bool, podName string, appName string, componentName string, msg string, show bool) error { +func ExecuteTerminatingCommand(ctx context.Context, execClient exec.Client, platformClient platform.Client, command devfilev1.Command, componentExists bool, podName string, appName string, componentName string, msg string, showOutputs bool) error { if componentExists && command.Exec != nil && pointer.BoolDeref(command.Exec.HotReloadCapable, false) { klog.V(2).Infof("command is hot-reload capable, not executing %q again", command.Id) @@ -30,19 +30,27 @@ func ExecuteTerminatingCommand(ctx context.Context, execClient exec.Client, plat } else { msg += " (command: " + command.Id + ")" } - spinner := log.Spinner(msg) - defer spinner.End(false) + + // Spinner is displayed only if no outputs are displayed + var spinner *log.Status + if !showOutputs { + spinner = log.Spinner(msg) + defer spinner.End(false) + } logger := machineoutput.NewMachineEventLoggingClient() stdoutWriter, stdoutChannel, stderrWriter, stderrChannel := logger.CreateContainerOutputWriter() - cmdline := getCmdline(command, !show) - _, _, err := execClient.ExecuteCommand(ctx, cmdline, podName, command.Exec.Component, show, stdoutWriter, stderrWriter) + cmdline := getCmdline(command, !showOutputs) + _, _, err := execClient.ExecuteCommand(ctx, cmdline, podName, command.Exec.Component, showOutputs, stdoutWriter, stderrWriter) closeWriterAndWaitForAck(stdoutWriter, stdoutChannel, stderrWriter, stderrChannel) - spinner.End(err == nil) - if err != nil { + if !showOutputs { + spinner.End(err == nil) + } + // Complete logs are displayed only if no outputs are displayed + if err != nil && !showOutputs { rd, errLog := Log(platformClient, componentName, appName, false, command) if errLog != nil { return fmt.Errorf("unable to log error %v: %w", err, errLog) diff --git a/pkg/exec/exec.go b/pkg/exec/exec.go index 49e32c52bc9..77cf943940a 100644 --- a/pkg/exec/exec.go +++ b/pkg/exec/exec.go @@ -26,15 +26,15 @@ func NewExecClient(platformClient platform.Client) *ExecClient { // ExecuteCommand executes the given command in the pod's container, // writing the output to the specified respective pipe writers -func (o ExecClient) ExecuteCommand(ctx context.Context, command []string, podName string, containerName string, show bool, stdoutWriter *io.PipeWriter, stderrWriter *io.PipeWriter) (stdout []string, stderr []string, err error) { +func (o ExecClient) ExecuteCommand(ctx context.Context, command []string, podName string, containerName string, showOutputs bool, stdoutWriter *io.PipeWriter, stderrWriter *io.PipeWriter) (stdout []string, stderr []string, err error) { soutReader, soutWriter := io.Pipe() serrReader, serrWriter := io.Pipe() klog.V(2).Infof("Executing command %v for pod: %v in container: %v", command, podName, containerName) // Read stdout and stderr, store their output in cmdOutput, and also pass output to consoleOutput Writers (if non-nil) - stdoutCompleteChannel := startReaderGoroutine(soutReader, show, &stdout, stdoutWriter) - stderrCompleteChannel := startReaderGoroutine(serrReader, show, &stderr, stderrWriter) + stdoutCompleteChannel := startReaderGoroutine(soutReader, showOutputs, &stdout, stdoutWriter) + stderrCompleteChannel := startReaderGoroutine(serrReader, showOutputs, &stderr, stderrWriter) err = o.platformClient.ExecCMDInContainer(ctx, containerName, podName, command, soutWriter, serrWriter, nil, false) @@ -44,7 +44,8 @@ func (o ExecClient) ExecuteCommand(ctx context.Context, command []string, podNam _ = serrWriter.Close() <-stderrCompleteChannel - if err != nil { + // Details are displayed only if no outputs are displayed + if err != nil && !showOutputs { // It is safe to read from stdout and stderr here, as the goroutines are guaranteed to have terminated at this point. klog.V(2).Infof("ExecuteCommand returned an an err: %v. for command '%v'\nstdout: %v\nstderr: %v", err, command, stdout, stderr)