Part 2 of plural ports: make endpoints a struct
Includes conversions for v1b[12] and tests and fixups for call sites.
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -102,8 +103,8 @@ func (fake *fakeIptables) IsIpv6() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
var tcpServerPort string
|
||||
var udpServerPort string
|
||||
var tcpServerPort int
|
||||
var udpServerPort int
|
||||
|
||||
func init() {
|
||||
// Don't handle panics
|
||||
@@ -118,20 +119,28 @@ func init() {
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to parse: %v", err))
|
||||
}
|
||||
_, tcpServerPort, err = net.SplitHostPort(u.Host)
|
||||
_, port, err := net.SplitHostPort(u.Host)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to parse: %v", err))
|
||||
}
|
||||
tcpServerPort, err = strconv.Atoi(port)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to atoi(%s): %v", port, err))
|
||||
}
|
||||
|
||||
// UDP setup.
|
||||
udp, err := newUDPEchoServer()
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to make a UDP server: %v", err))
|
||||
}
|
||||
_, udpServerPort, err = net.SplitHostPort(udp.LocalAddr().String())
|
||||
_, port, err = net.SplitHostPort(udp.LocalAddr().String())
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to parse: %v", err))
|
||||
}
|
||||
udpServerPort, err = strconv.Atoi(port)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to atoi(%s): %v", port, err))
|
||||
}
|
||||
go udp.Loop()
|
||||
}
|
||||
|
||||
@@ -188,7 +197,7 @@ func TestTCPProxy(t *testing.T) {
|
||||
lb.OnUpdate([]api.Endpoints{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "echo"},
|
||||
Endpoints: []string{net.JoinHostPort("127.0.0.1", tcpServerPort)},
|
||||
Endpoints: []api.Endpoint{{IP: "127.0.0.1", Port: tcpServerPort}},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -208,7 +217,7 @@ func TestUDPProxy(t *testing.T) {
|
||||
lb.OnUpdate([]api.Endpoints{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "echo"},
|
||||
Endpoints: []string{net.JoinHostPort("127.0.0.1", udpServerPort)},
|
||||
Endpoints: []api.Endpoint{{IP: "127.0.0.1", Port: udpServerPort}},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -237,7 +246,7 @@ func TestTCPProxyStop(t *testing.T) {
|
||||
lb.OnUpdate([]api.Endpoints{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "echo"},
|
||||
Endpoints: []string{net.JoinHostPort("127.0.0.1", tcpServerPort)},
|
||||
Endpoints: []api.Endpoint{{IP: "127.0.0.1", Port: tcpServerPort}},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -268,7 +277,7 @@ func TestUDPProxyStop(t *testing.T) {
|
||||
lb.OnUpdate([]api.Endpoints{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "echo"},
|
||||
Endpoints: []string{net.JoinHostPort("127.0.0.1", udpServerPort)},
|
||||
Endpoints: []api.Endpoint{{IP: "127.0.0.1", Port: udpServerPort}},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -299,7 +308,7 @@ func TestTCPProxyUpdateDelete(t *testing.T) {
|
||||
lb.OnUpdate([]api.Endpoints{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "echo"},
|
||||
Endpoints: []string{net.JoinHostPort("127.0.0.1", tcpServerPort)},
|
||||
Endpoints: []api.Endpoint{{IP: "127.0.0.1", Port: tcpServerPort}},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -329,7 +338,7 @@ func TestUDPProxyUpdateDelete(t *testing.T) {
|
||||
lb.OnUpdate([]api.Endpoints{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "echo"},
|
||||
Endpoints: []string{net.JoinHostPort("127.0.0.1", udpServerPort)},
|
||||
Endpoints: []api.Endpoint{{IP: "127.0.0.1", Port: udpServerPort}},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -359,7 +368,7 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
|
||||
lb.OnUpdate([]api.Endpoints{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "echo"},
|
||||
Endpoints: []string{net.JoinHostPort("127.0.0.1", tcpServerPort)},
|
||||
Endpoints: []api.Endpoint{{IP: "127.0.0.1", Port: tcpServerPort}},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -398,7 +407,7 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
|
||||
lb.OnUpdate([]api.Endpoints{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "echo"},
|
||||
Endpoints: []string{net.JoinHostPort("127.0.0.1", udpServerPort)},
|
||||
Endpoints: []api.Endpoint{{IP: "127.0.0.1", Port: udpServerPort}},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -437,7 +446,7 @@ func TestTCPProxyUpdatePort(t *testing.T) {
|
||||
lb.OnUpdate([]api.Endpoints{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "echo"},
|
||||
Endpoints: []string{net.JoinHostPort("127.0.0.1", tcpServerPort)},
|
||||
Endpoints: []api.Endpoint{{IP: "127.0.0.1", Port: tcpServerPort}},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -473,7 +482,7 @@ func TestUDPProxyUpdatePort(t *testing.T) {
|
||||
lb.OnUpdate([]api.Endpoints{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{Name: "echo"},
|
||||
Endpoints: []string{net.JoinHostPort("127.0.0.1", udpServerPort)},
|
||||
Endpoints: []api.Endpoint{{IP: "127.0.0.1", Port: udpServerPort}},
|
||||
},
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user