Skip to content

Commit

Permalink
Hide spinner and std output since outputs are displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jun 2, 2023
1 parent 3e5259a commit b265bfb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
22 changes: 15 additions & 7 deletions pkg/component/execute_terminating.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions pkg/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit b265bfb

Please sign in to comment.