-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redirect command Stdout & Stderr for command_runner #2448
Conversation
Can one of the admins verify this patch? |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lichen2013 Assign the PR to them by writing The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
@minikube-bot ok to test |
@@ -48,11 +48,26 @@ func (*ExecRunner) Run(cmd string) error { | |||
func (*ExecRunner) CombinedOutput(cmd string) (string, error) { | |||
glog.Infoln("Run with output:", cmd) | |||
c := exec.Command("/bin/bash", "-c", cmd) | |||
out, err := c.CombinedOutput() | |||
out, err := c.StdoutPipe() | |||
defer out.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CombinedOutput also gets us Stderr, right? I think if you add that this should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated with another approach, and redirected both Stdout & Stderr
Did a little more check, I have a guess that issue #2447 might not only exists for exec_runner.
|
} | ||
return string(out), nil | ||
|
||
return "", nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is meant to return the combined output. That's the string parameter in the output.
I think we need to do something like you had before, where we capture both stdout and stderr as variables, then run the command and return the combined strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a long running command, like continues printing new logs, it is not possible to get the return strings.
I would like to propose the change like this:
func (*ExecRunner) CombinedOutputTo(cmd string, out io.Writer) error {
glog.Infoln("Run with output:", cmd)
c := exec.Command("/bin/bash", "-c", cmd)
c.Stdout = out
c.Stderr = out
err := c.Run()
if err != nil {
return errors.Wrapf(err, "running command: %s\n.", cmd)
}
return nil
}
func (e *ExecRunner) CombinedOutput(cmd string) (string, error) {
var b bytes.Buffer
err := e.CombinedOutputTo(cmd, &b)
if err != nil {
return "", errors.Wrapf(err, "running command: %s\n output: %s", cmd, b.Bytes())
}
return b.Bytes(), nil
}
For command like minikube logs -f
, it should call CombinedOutputTo
directly:
CombinedOutputTo(cmd, os.Stdout)
I actually think the issue is with the SSHRunner implementation rather than the ExecRunner. Both implement the CommandRunner interface. Neither support streaming. I agree the interface should probably be changed to accommodate it. |
Tested with vm-driver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for spending the time on this!
@minikube-bot test this please |
D'oh, looks like a small build error still: pkg/minikube/bootstrapper/localkube/localkube_test.go:209:15: l.GetClusterLogs undefined (type LocalkubeBootstrapper has no field or method GetClusterLogs) |
CombinedOutput function return after command complete. When we run a long run command, such as continuously get new log entries, it failed to get run results. Fixes: kubernetes#2447
@minikube-bot test this please |
CombinedOutput waits command complete. When we run a long run command, such as continuously get new log entries, it failed to get run results.
Fixes: #2447