@@ -24,8 +24,6 @@ import (
24
24
"time"
25
25
26
26
"github.com/containerd/log"
27
-
28
- netutils "k8s.io/utils/net"
29
27
)
30
28
31
29
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
44
42
} else {
45
43
// HPCs use the host networking namespace.
46
44
// Therefore, dial to localhost.
47
- podIP = "127.0.0.1 "
45
+ podIP = "localhost "
48
46
}
49
47
50
48
err = func () error {
51
49
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 )
62
53
}
63
54
log .G (ctx ).Debugf ("Connection to ip %s and port %d was successful" , podIP , port )
64
55
0 commit comments