fix Docker tunnel failing
parent
9c2840b93c
commit
3ff8798094
|
@ -17,13 +17,16 @@ limitations under the License.
|
||||||
package kic
|
package kic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/phayes/freeport"
|
"github.com/phayes/freeport"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
|
"k8s.io/klog/v2"
|
||||||
|
|
||||||
"k8s.io/minikube/pkg/minikube/out"
|
"k8s.io/minikube/pkg/minikube/out"
|
||||||
"k8s.io/minikube/pkg/minikube/style"
|
"k8s.io/minikube/pkg/minikube/style"
|
||||||
|
@ -116,6 +119,7 @@ func createSSHConnWithRandomPorts(name, sshPort, sshKey string, svc *v1.Service)
|
||||||
// TODO: document the options here
|
// TODO: document the options here
|
||||||
"-o", "UserKnownHostsFile=/dev/null",
|
"-o", "UserKnownHostsFile=/dev/null",
|
||||||
"-o", "StrictHostKeyChecking=no",
|
"-o", "StrictHostKeyChecking=no",
|
||||||
|
"-o", "IdentitiesOnly=yes",
|
||||||
"-N",
|
"-N",
|
||||||
"docker@127.0.0.1",
|
"docker@127.0.0.1",
|
||||||
"-p", sshPort,
|
"-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})
|
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()
|
err := c.cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
go logOutput(r, c.service)
|
||||||
|
|
||||||
c.activeConn = true
|
c.activeConn = true
|
||||||
// we ignore wait error because the process will be killed
|
// we ignore wait error because the process will be killed
|
||||||
|
@ -172,6 +180,13 @@ func (c *sshConn) startAndWait() error {
|
||||||
return nil
|
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 {
|
func (c *sshConn) stop() error {
|
||||||
if c.activeConn {
|
if c.activeConn {
|
||||||
c.activeConn = false
|
c.activeConn = false
|
||||||
|
|
Loading…
Reference in New Issue