fix Docker tunnel failing

pull/15560/head
Steven Powell 2022-12-29 07:58:42 -08:00
parent 9c2840b93c
commit 3ff8798094
1 changed files with 15 additions and 0 deletions

View File

@ -17,13 +17,16 @@ limitations under the License.
package kic
import (
"bufio"
"fmt"
"io"
"os"
"os/exec"
"runtime"
"github.com/phayes/freeport"
v1 "k8s.io/api/core/v1"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/style"
@ -116,6 +119,7 @@ func createSSHConnWithRandomPorts(name, sshPort, sshKey string, svc *v1.Service)
// TODO: document the options here
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
"-o", "IdentitiesOnly=yes",
"-N",
"docker@127.0.0.1",
"-p", sshPort,
@ -157,10 +161,14 @@ func (c *sshConn) startAndWait() error {
out.Step(style.Running, "Starting tunnel for service {{.service}}.", out.V{"service": c.service})
}
r, w := io.Pipe()
c.cmd.Stdout = w
c.cmd.Stderr = w
err := c.cmd.Start()
if err != nil {
return err
}
go logOutput(r, c.service)
c.activeConn = true
// we ignore wait error because the process will be killed
@ -172,6 +180,13 @@ func (c *sshConn) startAndWait() error {
return nil
}
func logOutput(r io.Reader, service string) {
s := bufio.NewScanner(r)
for s.Scan() {
klog.Infof("%s tunnel: %s", service, s.Text())
}
}
func (c *sshConn) stop() error {
if c.activeConn {
c.activeConn = false