Skip to content

Commit e95a5e6

Browse files
committed
make loadbalancer tunnel protocol aware
Change-Id: I04adae38af0befe33f22e2d36c18fbdea59e45b5
1 parent f470a80 commit e95a5e6

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

pkg/container/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func PortMaps(name string) (map[string]string, error) {
220220
// TODO we just can get the first entry or look for ip families
221221
for _, pm := range v {
222222
if pm.HostPort != "" {
223-
result[parts[0]] = pm.HostPort
223+
result[parts[0]+"/"+protocol] = pm.HostPort
224224
break
225225
}
226226
}

pkg/loadbalancer/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func waitLoadBalancerReady(ctx context.Context, name string, timeout time.Durati
327327
}
328328
authority = net.JoinHostPort(ipv4, strconv.Itoa(envoyAdminPort))
329329
} else {
330-
port, ok := portmaps[strconv.Itoa(envoyAdminPort)]
330+
port, ok := portmaps[strconv.Itoa(envoyAdminPort)+"/tcp"]
331331
if !ok {
332332
return fmt.Errorf("envoy admin port %d not found, got %v", envoyAdminPort, portmaps)
333333
}

pkg/loadbalancer/tunnel.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io"
66
"net"
7+
"strings"
78
"sync"
89

910
"k8s.io/klog/v2"
@@ -49,7 +50,12 @@ func (t *tunnelManager) setupTunnels(containerName string) error {
4950
defer t.mu.Unlock()
5051
// There is one IP per Service and a tunnel per Service Port
5152
for containerPort, hostPort := range portmaps {
52-
tun := NewTunnel(ipv4, containerPort, "localhost", hostPort)
53+
parts := strings.Split(containerPort, "/")
54+
if len(parts) != 2 {
55+
return fmt.Errorf("expected format port/protocol for container port, got %s", containerPort)
56+
}
57+
58+
tun := NewTunnel(ipv4, parts[0], parts[1], "localhost", hostPort)
5359
// TODO check if we can leak tunnels
5460
err = tun.Start()
5561
if err != nil {
@@ -95,22 +101,24 @@ type tunnel struct {
95101
listener net.Listener
96102
localIP string
97103
localPort string
104+
protocol string
98105
remoteIP string // address:Port
99106
remotePort string
100107
}
101108

102-
func NewTunnel(localIP, localPort, remoteIP, remotePort string) *tunnel {
109+
func NewTunnel(localIP, localPort, protocol, remoteIP, remotePort string) *tunnel {
103110
return &tunnel{
104111
localIP: localIP,
105112
localPort: localPort,
113+
protocol: protocol,
106114
remoteIP: remoteIP,
107115
remotePort: remotePort,
108116
}
109117
}
110118

111119
func (t *tunnel) Start() error {
112120
klog.Infof("Starting tunnel on %s", net.JoinHostPort(t.localIP, t.localPort))
113-
ln, err := net.Listen("tcp", net.JoinHostPort(t.localIP, t.localPort))
121+
ln, err := net.Listen(t.protocol, net.JoinHostPort(t.localIP, t.localPort))
114122
if err != nil {
115123
return err
116124
}
@@ -144,7 +152,7 @@ func (t *tunnel) Stop() error {
144152
}
145153

146154
func (t *tunnel) handleConnection(local net.Conn) error {
147-
remote, err := net.Dial("tcp", net.JoinHostPort(t.remoteIP, t.remotePort))
155+
remote, err := net.Dial(t.protocol, net.JoinHostPort(t.remoteIP, t.remotePort))
148156
if err != nil {
149157
return fmt.Errorf("can't connect to server %q: %v", net.JoinHostPort(t.remoteIP, t.remotePort), err)
150158
}

0 commit comments

Comments
 (0)