Skip to content

Commit 7e60d5a

Browse files
committed
Account for ipv4 vs ipv6 localhost
in windows port forwarding Signed-off-by: Kirtana Ashok <[email protected]>
1 parent 99693a3 commit 7e60d5a

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

internal/cri/server/sandbox_portforward_windows.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
"time"
2525

2626
"github.com/containerd/log"
27-
28-
netutils "k8s.io/utils/net"
2927
)
3028

3129
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
4442
} else {
4543
// HPCs use the host networking namespace.
4644
// Therefore, dial to localhost.
47-
podIP = "127.0.0.1"
45+
podIP = "localhost"
4846
}
4947

5048
err = func() error {
5149
var conn net.Conn
52-
if netutils.IsIPv4String(podIP) {
53-
conn, err = net.Dial("tcp4", fmt.Sprintf("%s:%d", podIP, port))
54-
if err != nil {
55-
return fmt.Errorf("failed to connect to %s:%d for pod %q: %v", podIP, port, id, err)
56-
}
57-
} else {
58-
conn, err = net.Dial("tcp6", fmt.Sprintf("%s:%d", podIP, port))
59-
if err != nil {
60-
return fmt.Errorf("failed to connect to %s:%d for pod %q: %v", podIP, port, id, err)
61-
}
50+
conn, err = net.Dial("tcp", net.JoinHostPort(podIP, fmt.Sprintf("%d", port)))
51+
if err != nil {
52+
return fmt.Errorf("failed to connect to %s:%d for pod %q: %v", podIP, port, id, err)
6253
}
6354
log.G(ctx).Debugf("Connection to ip %s and port %d was successful", podIP, port)
6455

0 commit comments

Comments
 (0)