Account for ipv4 vs ipv6 localhost
in windows port forwarding Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
This commit is contained in:
parent
99693a32c2
commit
7e60d5a074
@ -24,8 +24,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/log"
|
"github.com/containerd/log"
|
||||||
|
|
||||||
netutils "k8s.io/utils/net"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *criService) portForward(ctx context.Context, id string, port int32, stream io.ReadWriter) error {
|
func (c *criService) portForward(ctx context.Context, id string, port int32, stream io.ReadWriter) error {
|
||||||
@ -44,21 +42,14 @@ func (c *criService) portForward(ctx context.Context, id string, port int32, str
|
|||||||
} else {
|
} else {
|
||||||
// HPCs use the host networking namespace.
|
// HPCs use the host networking namespace.
|
||||||
// Therefore, dial to localhost.
|
// Therefore, dial to localhost.
|
||||||
podIP = "127.0.0.1"
|
podIP = "localhost"
|
||||||
}
|
}
|
||||||
|
|
||||||
err = func() error {
|
err = func() error {
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
if netutils.IsIPv4String(podIP) {
|
conn, err = net.Dial("tcp", net.JoinHostPort(podIP, fmt.Sprintf("%d", port)))
|
||||||
conn, err = net.Dial("tcp4", fmt.Sprintf("%s:%d", podIP, port))
|
if err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("failed to connect to %s:%d for pod %q: %v", podIP, port, id, err)
|
||||||
return fmt.Errorf("failed to connect to %s:%d for pod %q: %v", podIP, port, id, err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
conn, err = net.Dial("tcp6", fmt.Sprintf("%s:%d", podIP, port))
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to connect to %s:%d for pod %q: %v", podIP, port, id, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
log.G(ctx).Debugf("Connection to ip %s and port %d was successful", podIP, port)
|
log.G(ctx).Debugf("Connection to ip %s and port %d was successful", podIP, port)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user