From 40efc0fb33b7c33e059d2e71b798db31076b2821 Mon Sep 17 00:00:00 2001 From: Euan Kemp Date: Wed, 1 Jun 2016 11:39:40 -0700 Subject: [PATCH] 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. --- pkg/kubelet/rkt/rkt.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/kubelet/rkt/rkt.go b/pkg/kubelet/rkt/rkt.go index d67b3a8cdfc..1c9e1214ac3 100644 --- a/pkg/kubelet/rkt/rkt.go +++ b/pkg/kubelet/rkt/rkt.go @@ -1857,6 +1857,13 @@ func (r *rktExitError) ExitStatus() int { 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 { return fmt.Errorf("unimplemented") } @@ -1891,7 +1898,7 @@ func (r *Runtime) ExecInContainer(containerID kubecontainer.ContainerID, cmd []s if stdout != nil { go io.Copy(stdout, p) } - return command.Wait() + return newRktExitError(command.Wait()) } if stdin != nil { // 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. r, w, err := r.os.Pipe() if err != nil { - return err + return newRktExitError(err) } go io.Copy(w, stdin) @@ -1912,7 +1919,7 @@ func (r *Runtime) ExecInContainer(containerID kubecontainer.ContainerID, cmd []s if stderr != nil { command.Stderr = stderr } - return command.Run() + return newRktExitError(command.Run()) } // PortForward executes socat in the pod's network namespace and copies