rkt: Wrap exec errors as utilexec.ExitError

This is needed by the exec prober to distinguish error types and exit
codes correctly.

An alternative, and preferable solution would be to use utilexec
everywhere, but that change is much more involved and should come at a
later date. Unfortunately, until that change is made, writing tests for
this is quite difficult.
This commit is contained in:
Euan Kemp 2016-06-01 11:39:40 -07:00
parent c1c0567e37
commit 40efc0fb33

View File

@ -1857,6 +1857,13 @@ func (r *rktExitError) ExitStatus() int {
return 0 return 0
} }
func newRktExitError(e error) error {
if exitErr, ok := e.(*exec.ExitError); ok {
return &rktExitError{exitErr}
}
return e
}
func (r *Runtime) AttachContainer(containerID kubecontainer.ContainerID, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error { func (r *Runtime) AttachContainer(containerID kubecontainer.ContainerID, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error {
return fmt.Errorf("unimplemented") return fmt.Errorf("unimplemented")
} }
@ -1891,7 +1898,7 @@ func (r *Runtime) ExecInContainer(containerID kubecontainer.ContainerID, cmd []s
if stdout != nil { if stdout != nil {
go io.Copy(stdout, p) go io.Copy(stdout, p)
} }
return command.Wait() return newRktExitError(command.Wait())
} }
if stdin != nil { if stdin != nil {
// Use an os.Pipe here as it returns true *os.File objects. // Use an os.Pipe here as it returns true *os.File objects.
@ -1900,7 +1907,7 @@ func (r *Runtime) ExecInContainer(containerID kubecontainer.ContainerID, cmd []s
// of the pipe. // of the pipe.
r, w, err := r.os.Pipe() r, w, err := r.os.Pipe()
if err != nil { if err != nil {
return err return newRktExitError(err)
} }
go io.Copy(w, stdin) go io.Copy(w, stdin)
@ -1912,7 +1919,7 @@ func (r *Runtime) ExecInContainer(containerID kubecontainer.ContainerID, cmd []s
if stderr != nil { if stderr != nil {
command.Stderr = stderr command.Stderr = stderr
} }
return command.Run() return newRktExitError(command.Run())
} }
// PortForward executes socat in the pod's network namespace and copies // PortForward executes socat in the pod's network namespace and copies