Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 82878c7

Browse files
committed
Use ChooseHostInterface from kube to select interface
We need to select interface used to access default gateway, as docker0 bridge or Windows DockerNAT won't route traffic to containers by exposed port Signed-off-by: Nicolas De Loof <[email protected]>
1 parent d10e2f5 commit 82878c7

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/helper_test.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package e2e
33
import (
44
"fmt"
55
"io/ioutil"
6-
"net"
76
"strconv"
87
"strings"
98
"testing"
@@ -13,6 +12,7 @@ import (
1312
"gotest.tools/assert"
1413
"gotest.tools/fs"
1514
"gotest.tools/icmd"
15+
net2 "k8s.io/apimachinery/pkg/util/net"
1616
)
1717

1818
// readFile returns the content of the file at the designated path normalizing
@@ -151,20 +151,16 @@ func (c *Container) getPort(t *testing.T) string {
151151
return port
152152
}
153153

154+
var host string
155+
154156
func (c *Container) getIP(t *testing.T) string {
155-
ip := "127.0.0.1"
156-
// This won't work, but we can't guarantee computer has another IP
157-
addrs, err := net.InterfaceAddrs()
158-
assert.NilError(t, err)
159-
for _, a := range addrs {
160-
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
161-
if ipnet.IP.To4() != nil {
162-
ip = ipnet.IP.String()
163-
break
164-
}
165-
}
157+
if host != "" {
158+
return host
166159
}
167-
return ip
160+
ip, err := net2.ChooseHostInterface()
161+
assert.NilError(t, err)
162+
host = ip.String()
163+
return host
168164
}
169165

170166
func (c *Container) Logs(t *testing.T) func() string {

0 commit comments

Comments
 (0)