Skip to content

Commit ecfe5e2

Browse files
author
Neil Jerram
committed
Fix loopback IP to work when there's only one plane
1 parent ef328bf commit ecfe5e2

File tree

1 file changed

+18
-10
lines changed
  • pkg/cluster/internal/providers/docker

1 file changed

+18
-10
lines changed

pkg/cluster/internal/providers/docker/node.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,27 @@ func (n *node) IP() (ipv4 string, ipv6 string, err error) {
9393
if len(lines) != 1 {
9494
return "", "", errors.Errorf("file should only be one line, got %d lines", len(lines))
9595
}
96+
// If the node has a loopback address, that provides the IPv4.
97+
loopAddr, err := n.Loopback()
98+
if err == nil && loopAddr != "" {
99+
fmt.Printf("%v: use IPv4 loopback address %v\n", n.name, loopAddr)
100+
ipv4 = loopAddr
101+
}
96102
ips := strings.Split(lines[0], ",")
97-
if len(ips) != 2 {
98-
//return "", "", errors.Errorf("container addresses should have 2 values, got %d values", len(ips))
99-
fmt.Printf("%v: %#v\n", n.name, ips)
100-
// If the node has a loopback address, that overrides the IPv4 one.
101-
loopAddr, err := n.Loopback()
102-
if err == nil && loopAddr != "" {
103-
fmt.Printf("%v: use IPv4 loopback address %v\n", n.name, loopAddr)
104-
return loopAddr, ips[1], nil
103+
for _, ip := range ips {
104+
if strings.Contains(ip, ":") {
105+
// IPv6.
106+
if ipv6 == "" {
107+
ipv6 = ip
108+
}
109+
} else {
110+
// IPv4
111+
if ipv4 == "" {
112+
ipv4 = ip
113+
}
105114
}
106-
return ips[0], "", nil
107115
}
108-
return ips[0], ips[1], nil
116+
return
109117
}
110118

111119
func (n *node) Command(command string, args ...string) exec.Cmd {

0 commit comments

Comments
 (0)