From 86ae623a09b484353c09b75ddca638ccdaf6cafc Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Thu, 28 Jan 2016 15:28:40 -0500 Subject: [PATCH] Help debug port forward flakes --- pkg/kubelet/dockertools/manager.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/kubelet/dockertools/manager.go b/pkg/kubelet/dockertools/manager.go index 0e31d28d4f..2ed49dcdfb 100644 --- a/pkg/kubelet/dockertools/manager.go +++ b/pkg/kubelet/dockertools/manager.go @@ -1215,9 +1215,15 @@ func (dm *DockerManager) PortForward(pod *kubecontainer.Pod, port uint16, stream return fmt.Errorf("unable to do port forwarding: nsenter not found.") } + commandString := fmt.Sprintf("%s %s", nsenterPath, strings.Join(args, " ")) + glog.V(4).Infof("executing port forwarding command: %s", commandString) + command := exec.Command(nsenterPath, args...) command.Stdout = stream + stderr := new(bytes.Buffer) + command.Stderr = stderr + // If we use Stdin, command.Run() won't return until the goroutine that's copying // from stream finishes. Unfortunately, if you have a client like telnet connected // via port forwarding, as long as the user's telnet client is connected to the user's @@ -1236,7 +1242,11 @@ func (dm *DockerManager) PortForward(pod *kubecontainer.Pod, port uint16, stream inPipe.Close() }() - return command.Run() + if err := command.Run(); err != nil { + return fmt.Errorf("%v: %s", err, stderr.String()) + } + + return nil } // Get the IP address of a container's interface using nsenter