[kube-proxy] Move Service/EndpointInfo common codes to change tracker
This commit is contained in:
@@ -17,9 +17,7 @@ limitations under the License.
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"net"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
@@ -30,48 +28,16 @@ import (
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
)
|
||||
|
||||
type fakeEndpointsInfo struct {
|
||||
endpoint string
|
||||
isLocal bool
|
||||
}
|
||||
|
||||
func newFakeEndpointsInfo(IP string, port int, isLocal bool) Endpoint {
|
||||
return &fakeEndpointsInfo{
|
||||
endpoint: net.JoinHostPort(IP, strconv.Itoa(port)),
|
||||
isLocal: isLocal,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fakeEndpointsInfo) String() string {
|
||||
return f.endpoint
|
||||
}
|
||||
|
||||
func (f *fakeEndpointsInfo) IsLocal() bool {
|
||||
return f.isLocal
|
||||
}
|
||||
|
||||
func (f *fakeEndpointsInfo) IP() string {
|
||||
// Must be IP:port
|
||||
host, _, _ := net.SplitHostPort(f.endpoint)
|
||||
return host
|
||||
}
|
||||
|
||||
func (f *fakeEndpointsInfo) Equal(other Endpoint) bool {
|
||||
return f.String() == other.String() &&
|
||||
f.IsLocal() == other.IsLocal() &&
|
||||
f.IP() == other.IP()
|
||||
}
|
||||
|
||||
func (proxier *FakeProxier) addEndpoints(endpoints *api.Endpoints) {
|
||||
proxier.endpointsChanges.Update(nil, endpoints, newFakeEndpointsInfo)
|
||||
proxier.endpointsChanges.Update(nil, endpoints)
|
||||
}
|
||||
|
||||
func (proxier *FakeProxier) updateEndpoints(oldEndpoints, endpoints *api.Endpoints) {
|
||||
proxier.endpointsChanges.Update(oldEndpoints, endpoints, newFakeEndpointsInfo)
|
||||
proxier.endpointsChanges.Update(oldEndpoints, endpoints)
|
||||
}
|
||||
|
||||
func (proxier *FakeProxier) deleteEndpoints(endpoints *api.Endpoints) {
|
||||
proxier.endpointsChanges.Update(endpoints, nil, newFakeEndpointsInfo)
|
||||
proxier.endpointsChanges.Update(endpoints, nil)
|
||||
}
|
||||
|
||||
func TestGetLocalEndpointIPs(t *testing.T) {
|
||||
@@ -86,7 +52,7 @@ func TestGetLocalEndpointIPs(t *testing.T) {
|
||||
// Case[1]: unnamed port
|
||||
endpointsMap: EndpointsMap{
|
||||
makeServicePortName("ns1", "ep1", ""): []Endpoint{
|
||||
&fakeEndpointsInfo{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
&EndpointInfoCommon{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expected: map[types.NamespacedName]sets.String{},
|
||||
@@ -94,7 +60,7 @@ func TestGetLocalEndpointIPs(t *testing.T) {
|
||||
// Case[2]: unnamed port local
|
||||
endpointsMap: EndpointsMap{
|
||||
makeServicePortName("ns1", "ep1", ""): []Endpoint{
|
||||
&fakeEndpointsInfo{endpoint: "1.1.1.1:11", isLocal: true},
|
||||
&EndpointInfoCommon{Endpoint: "1.1.1.1:11", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expected: map[types.NamespacedName]sets.String{
|
||||
@@ -104,12 +70,12 @@ func TestGetLocalEndpointIPs(t *testing.T) {
|
||||
// Case[3]: named local and non-local ports for the same IP.
|
||||
endpointsMap: EndpointsMap{
|
||||
makeServicePortName("ns1", "ep1", "p11"): []Endpoint{
|
||||
&fakeEndpointsInfo{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
&fakeEndpointsInfo{endpoint: "1.1.1.2:11", isLocal: true},
|
||||
&EndpointInfoCommon{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
&EndpointInfoCommon{Endpoint: "1.1.1.2:11", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): []Endpoint{
|
||||
&fakeEndpointsInfo{endpoint: "1.1.1.1:12", isLocal: false},
|
||||
&fakeEndpointsInfo{endpoint: "1.1.1.2:12", isLocal: true},
|
||||
&EndpointInfoCommon{Endpoint: "1.1.1.1:12", IsLocal: false},
|
||||
&EndpointInfoCommon{Endpoint: "1.1.1.2:12", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expected: map[types.NamespacedName]sets.String{
|
||||
@@ -119,21 +85,21 @@ func TestGetLocalEndpointIPs(t *testing.T) {
|
||||
// Case[4]: named local and non-local ports for different IPs.
|
||||
endpointsMap: EndpointsMap{
|
||||
makeServicePortName("ns1", "ep1", "p11"): []Endpoint{
|
||||
&fakeEndpointsInfo{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
&EndpointInfoCommon{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p22"): []Endpoint{
|
||||
&fakeEndpointsInfo{endpoint: "2.2.2.2:22", isLocal: true},
|
||||
&fakeEndpointsInfo{endpoint: "2.2.2.22:22", isLocal: true},
|
||||
&EndpointInfoCommon{Endpoint: "2.2.2.2:22", IsLocal: true},
|
||||
&EndpointInfoCommon{Endpoint: "2.2.2.22:22", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p23"): []Endpoint{
|
||||
&fakeEndpointsInfo{endpoint: "2.2.2.3:23", isLocal: true},
|
||||
&EndpointInfoCommon{Endpoint: "2.2.2.3:23", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns4", "ep4", "p44"): []Endpoint{
|
||||
&fakeEndpointsInfo{endpoint: "4.4.4.4:44", isLocal: true},
|
||||
&fakeEndpointsInfo{endpoint: "4.4.4.5:44", isLocal: false},
|
||||
&EndpointInfoCommon{Endpoint: "4.4.4.4:44", IsLocal: true},
|
||||
&EndpointInfoCommon{Endpoint: "4.4.4.5:44", IsLocal: false},
|
||||
},
|
||||
makeServicePortName("ns4", "ep4", "p45"): []Endpoint{
|
||||
&fakeEndpointsInfo{endpoint: "4.4.4.6:45", isLocal: true},
|
||||
&EndpointInfoCommon{Endpoint: "4.4.4.6:45", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expected: map[types.NamespacedName]sets.String{
|
||||
@@ -164,14 +130,16 @@ func makeTestEndpoints(namespace, name string, eptFunc func(*api.Endpoints)) *ap
|
||||
}
|
||||
|
||||
// This is a coarse test, but it offers some modicum of confidence as the code is evolved.
|
||||
func Test_endpointsToEndpointsMap(t *testing.T) {
|
||||
func TestEndpointsToEndpointsMap(t *testing.T) {
|
||||
epTracker := NewEndpointChangeTracker("test-hostname", nil, nil, nil)
|
||||
|
||||
testCases := []struct {
|
||||
newEndpoints *api.Endpoints
|
||||
expected map[ServicePortName][]*fakeEndpointsInfo
|
||||
expected map[ServicePortName][]*EndpointInfoCommon
|
||||
}{{
|
||||
// Case[0]: nothing
|
||||
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {}),
|
||||
expected: map[ServicePortName][]*fakeEndpointsInfo{},
|
||||
expected: map[ServicePortName][]*EndpointInfoCommon{},
|
||||
}, {
|
||||
// Case[1]: no changes, unnamed port
|
||||
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {
|
||||
@@ -187,9 +155,9 @@ func Test_endpointsToEndpointsMap(t *testing.T) {
|
||||
},
|
||||
}
|
||||
}),
|
||||
expected: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expected: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", ""): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
@@ -207,9 +175,9 @@ func Test_endpointsToEndpointsMap(t *testing.T) {
|
||||
},
|
||||
}
|
||||
}),
|
||||
expected: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expected: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "port"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
@@ -226,15 +194,15 @@ func Test_endpointsToEndpointsMap(t *testing.T) {
|
||||
},
|
||||
}
|
||||
}),
|
||||
expected: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expected: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", ""): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
// Case[4]: remove port
|
||||
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {}),
|
||||
expected: map[ServicePortName][]*fakeEndpointsInfo{},
|
||||
expected: map[ServicePortName][]*EndpointInfoCommon{},
|
||||
}, {
|
||||
// Case[5]: new IP and port
|
||||
newEndpoints: makeTestEndpoints("ns1", "ep1", func(ept *api.Endpoints) {
|
||||
@@ -255,14 +223,14 @@ func Test_endpointsToEndpointsMap(t *testing.T) {
|
||||
},
|
||||
}
|
||||
}),
|
||||
expected: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expected: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p1"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{endpoint: "2.2.2.2:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
{Endpoint: "2.2.2.2:11", IsLocal: false},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p2"): {
|
||||
{endpoint: "1.1.1.1:22", isLocal: false},
|
||||
{endpoint: "2.2.2.2:22", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:22", IsLocal: false},
|
||||
{Endpoint: "2.2.2.2:22", IsLocal: false},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
@@ -280,9 +248,9 @@ func Test_endpointsToEndpointsMap(t *testing.T) {
|
||||
},
|
||||
}
|
||||
}),
|
||||
expected: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expected: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p1"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
@@ -300,9 +268,9 @@ func Test_endpointsToEndpointsMap(t *testing.T) {
|
||||
},
|
||||
}
|
||||
}),
|
||||
expected: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expected: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p2"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
@@ -320,16 +288,16 @@ func Test_endpointsToEndpointsMap(t *testing.T) {
|
||||
},
|
||||
}
|
||||
}),
|
||||
expected: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expected: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p1"): {
|
||||
{endpoint: "1.1.1.1:22", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:22", IsLocal: false},
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
for tci, tc := range testCases {
|
||||
// outputs
|
||||
newEndpoints := endpointsToEndpointsMap(tc.newEndpoints, "host", newFakeEndpointsInfo)
|
||||
newEndpoints := epTracker.endpointsToEndpointsMap(tc.newEndpoints)
|
||||
|
||||
if len(newEndpoints) != len(tc.expected) {
|
||||
t.Errorf("[%d] expected %d new, got %d: %v", tci, len(tc.expected), len(newEndpoints), spew.Sdump(newEndpoints))
|
||||
@@ -339,7 +307,7 @@ func Test_endpointsToEndpointsMap(t *testing.T) {
|
||||
t.Errorf("[%d] expected %d endpoints for %v, got %d", tci, len(tc.expected[x]), x, len(newEndpoints[x]))
|
||||
} else {
|
||||
for i := range newEndpoints[x] {
|
||||
ep := newEndpoints[x][i].(*fakeEndpointsInfo)
|
||||
ep := newEndpoints[x][i].(*EndpointInfoCommon)
|
||||
if *ep != *(tc.expected[x][i]) {
|
||||
t.Errorf("[%d] expected new[%v][%d] to be %v, got %v", tci, x, i, tc.expected[x][i], *ep)
|
||||
}
|
||||
@@ -661,15 +629,15 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
// or non-nil) and must be of equal length.
|
||||
previousEndpoints []*api.Endpoints
|
||||
currentEndpoints []*api.Endpoints
|
||||
oldEndpoints map[ServicePortName][]*fakeEndpointsInfo
|
||||
expectedResult map[ServicePortName][]*fakeEndpointsInfo
|
||||
oldEndpoints map[ServicePortName][]*EndpointInfoCommon
|
||||
expectedResult map[ServicePortName][]*EndpointInfoCommon
|
||||
expectedStaleEndpoints []ServiceEndpoint
|
||||
expectedStaleServiceNames map[ServicePortName]bool
|
||||
expectedHealthchecks map[types.NamespacedName]int
|
||||
}{{
|
||||
// Case[0]: nothing
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{},
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{},
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{},
|
||||
expectedStaleServiceNames: map[ServicePortName]bool{},
|
||||
expectedHealthchecks: map[types.NamespacedName]int{},
|
||||
@@ -681,14 +649,14 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
makeTestEndpoints("ns1", "ep1", unnamedPort),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", ""): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", ""): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{},
|
||||
@@ -702,14 +670,14 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
makeTestEndpoints("ns1", "ep1", namedPortLocal),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{},
|
||||
@@ -725,20 +693,20 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
makeTestEndpoints("ns1", "ep1", multipleSubsets),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
{endpoint: "1.1.1.2:12", isLocal: false},
|
||||
{Endpoint: "1.1.1.2:12", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
{endpoint: "1.1.1.2:12", isLocal: false},
|
||||
{Endpoint: "1.1.1.2:12", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{},
|
||||
@@ -752,26 +720,26 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
makeTestEndpoints("ns1", "ep1", multipleSubsetsMultiplePortsLocal),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
{endpoint: "1.1.1.1:12", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:12", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p13"): {
|
||||
{endpoint: "1.1.1.3:13", isLocal: false},
|
||||
{Endpoint: "1.1.1.3:13", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
{endpoint: "1.1.1.1:12", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:12", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p13"): {
|
||||
{endpoint: "1.1.1.3:13", isLocal: false},
|
||||
{Endpoint: "1.1.1.3:13", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{},
|
||||
@@ -789,56 +757,56 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns1", "ep1", multipleSubsetsIPsPorts1),
|
||||
makeTestEndpoints("ns2", "ep2", multipleSubsetsIPsPorts2),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{endpoint: "1.1.1.2:11", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
{Endpoint: "1.1.1.2:11", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
{endpoint: "1.1.1.1:12", isLocal: false},
|
||||
{endpoint: "1.1.1.2:12", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:12", IsLocal: false},
|
||||
{Endpoint: "1.1.1.2:12", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p13"): {
|
||||
{endpoint: "1.1.1.3:13", isLocal: false},
|
||||
{endpoint: "1.1.1.4:13", isLocal: true},
|
||||
{Endpoint: "1.1.1.3:13", IsLocal: false},
|
||||
{Endpoint: "1.1.1.4:13", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p14"): {
|
||||
{endpoint: "1.1.1.3:14", isLocal: false},
|
||||
{endpoint: "1.1.1.4:14", isLocal: true},
|
||||
{Endpoint: "1.1.1.3:14", IsLocal: false},
|
||||
{Endpoint: "1.1.1.4:14", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p21"): {
|
||||
{endpoint: "2.2.2.1:21", isLocal: false},
|
||||
{endpoint: "2.2.2.2:21", isLocal: true},
|
||||
{Endpoint: "2.2.2.1:21", IsLocal: false},
|
||||
{Endpoint: "2.2.2.2:21", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p22"): {
|
||||
{endpoint: "2.2.2.1:22", isLocal: false},
|
||||
{endpoint: "2.2.2.2:22", isLocal: true},
|
||||
{Endpoint: "2.2.2.1:22", IsLocal: false},
|
||||
{Endpoint: "2.2.2.2:22", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{endpoint: "1.1.1.2:11", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
{Endpoint: "1.1.1.2:11", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
{endpoint: "1.1.1.1:12", isLocal: false},
|
||||
{endpoint: "1.1.1.2:12", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:12", IsLocal: false},
|
||||
{Endpoint: "1.1.1.2:12", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p13"): {
|
||||
{endpoint: "1.1.1.3:13", isLocal: false},
|
||||
{endpoint: "1.1.1.4:13", isLocal: true},
|
||||
{Endpoint: "1.1.1.3:13", IsLocal: false},
|
||||
{Endpoint: "1.1.1.4:13", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p14"): {
|
||||
{endpoint: "1.1.1.3:14", isLocal: false},
|
||||
{endpoint: "1.1.1.4:14", isLocal: true},
|
||||
{Endpoint: "1.1.1.3:14", IsLocal: false},
|
||||
{Endpoint: "1.1.1.4:14", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p21"): {
|
||||
{endpoint: "2.2.2.1:21", isLocal: false},
|
||||
{endpoint: "2.2.2.2:21", isLocal: true},
|
||||
{Endpoint: "2.2.2.1:21", IsLocal: false},
|
||||
{Endpoint: "2.2.2.2:21", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p22"): {
|
||||
{endpoint: "2.2.2.1:22", isLocal: false},
|
||||
{endpoint: "2.2.2.2:22", isLocal: true},
|
||||
{Endpoint: "2.2.2.1:22", IsLocal: false},
|
||||
{Endpoint: "2.2.2.2:22", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{},
|
||||
@@ -855,10 +823,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
makeTestEndpoints("ns1", "ep1", unnamedPortLocal),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{},
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", ""): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{},
|
||||
@@ -876,12 +844,12 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
nil,
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", ""): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{},
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{{
|
||||
Endpoint: "1.1.1.1:11",
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", ""),
|
||||
@@ -896,19 +864,19 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
makeTestEndpoints("ns1", "ep1", namedPortsLocalNoLocal),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{endpoint: "1.1.1.2:11", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
{Endpoint: "1.1.1.2:11", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
{endpoint: "1.1.1.1:12", isLocal: false},
|
||||
{endpoint: "1.1.1.2:12", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:12", IsLocal: false},
|
||||
{Endpoint: "1.1.1.2:12", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{},
|
||||
@@ -926,19 +894,19 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
makeTestEndpoints("ns1", "ep1", namedPort),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{endpoint: "1.1.1.2:11", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
{Endpoint: "1.1.1.2:11", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
{endpoint: "1.1.1.1:12", isLocal: false},
|
||||
{endpoint: "1.1.1.2:12", isLocal: true},
|
||||
{Endpoint: "1.1.1.1:12", IsLocal: false},
|
||||
{Endpoint: "1.1.1.2:12", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{{
|
||||
@@ -961,17 +929,17 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
makeTestEndpoints("ns1", "ep1", multipleSubsetsWithLocal),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
{endpoint: "1.1.1.2:12", isLocal: true},
|
||||
{Endpoint: "1.1.1.2:12", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{},
|
||||
@@ -989,17 +957,17 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
makeTestEndpoints("ns1", "ep1", namedPort),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
{endpoint: "1.1.1.2:12", isLocal: false},
|
||||
{Endpoint: "1.1.1.2:12", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{{
|
||||
@@ -1016,14 +984,14 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
makeTestEndpoints("ns1", "ep1", namedPortRenamed),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11-2"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{{
|
||||
@@ -1042,14 +1010,14 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
makeTestEndpoints("ns1", "ep1", namedPortRenumbered),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:22", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:22", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{{
|
||||
@@ -1072,41 +1040,41 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns3", "ep3", complexAfter3),
|
||||
makeTestEndpoints("ns4", "ep4", complexAfter4),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p22"): {
|
||||
{endpoint: "2.2.2.2:22", isLocal: true},
|
||||
{endpoint: "2.2.2.22:22", isLocal: true},
|
||||
{Endpoint: "2.2.2.2:22", IsLocal: true},
|
||||
{Endpoint: "2.2.2.22:22", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p23"): {
|
||||
{endpoint: "2.2.2.3:23", isLocal: true},
|
||||
{Endpoint: "2.2.2.3:23", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns4", "ep4", "p44"): {
|
||||
{endpoint: "4.4.4.4:44", isLocal: true},
|
||||
{endpoint: "4.4.4.5:44", isLocal: true},
|
||||
{Endpoint: "4.4.4.4:44", IsLocal: true},
|
||||
{Endpoint: "4.4.4.5:44", IsLocal: true},
|
||||
},
|
||||
makeServicePortName("ns4", "ep4", "p45"): {
|
||||
{endpoint: "4.4.4.6:45", isLocal: true},
|
||||
{Endpoint: "4.4.4.6:45", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{endpoint: "1.1.1.11:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
{Endpoint: "1.1.1.11:11", IsLocal: false},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
{endpoint: "1.1.1.2:12", isLocal: false},
|
||||
{Endpoint: "1.1.1.2:12", IsLocal: false},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p122"): {
|
||||
{endpoint: "1.1.1.2:122", isLocal: false},
|
||||
{Endpoint: "1.1.1.2:122", IsLocal: false},
|
||||
},
|
||||
makeServicePortName("ns3", "ep3", "p33"): {
|
||||
{endpoint: "3.3.3.3:33", isLocal: false},
|
||||
{Endpoint: "3.3.3.3:33", IsLocal: false},
|
||||
},
|
||||
makeServicePortName("ns4", "ep4", "p44"): {
|
||||
{endpoint: "4.4.4.4:44", isLocal: true},
|
||||
{Endpoint: "4.4.4.4:44", IsLocal: true},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{{
|
||||
@@ -1141,10 +1109,10 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
currentEndpoints: []*api.Endpoints{
|
||||
makeTestEndpoints("ns1", "ep1", unnamedPort),
|
||||
},
|
||||
oldEndpoints: map[ServicePortName][]*fakeEndpointsInfo{},
|
||||
expectedResult: map[ServicePortName][]*fakeEndpointsInfo{
|
||||
oldEndpoints: map[ServicePortName][]*EndpointInfoCommon{},
|
||||
expectedResult: map[ServicePortName][]*EndpointInfoCommon{
|
||||
makeServicePortName("ns1", "ep1", ""): {
|
||||
{endpoint: "1.1.1.1:11", isLocal: false},
|
||||
{Endpoint: "1.1.1.1:11", IsLocal: false},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []ServiceEndpoint{},
|
||||
@@ -1224,7 +1192,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func compareEndpointsMaps(t *testing.T, tci int, newMap EndpointsMap, expected map[ServicePortName][]*fakeEndpointsInfo) {
|
||||
func compareEndpointsMaps(t *testing.T, tci int, newMap EndpointsMap, expected map[ServicePortName][]*EndpointInfoCommon) {
|
||||
if len(newMap) != len(expected) {
|
||||
t.Errorf("[%d] expected %d results, got %d: %v", tci, len(expected), len(newMap), newMap)
|
||||
}
|
||||
@@ -1233,7 +1201,7 @@ func compareEndpointsMaps(t *testing.T, tci int, newMap EndpointsMap, expected m
|
||||
t.Errorf("[%d] expected %d endpoints for %v, got %d", tci, len(expected[x]), x, len(newMap[x]))
|
||||
} else {
|
||||
for i := range expected[x] {
|
||||
newEp, ok := newMap[x][i].(*fakeEndpointsInfo)
|
||||
newEp, ok := newMap[x][i].(*EndpointInfoCommon)
|
||||
if !ok {
|
||||
t.Errorf("Failed to cast endpointsInfo")
|
||||
continue
|
||||
|
Reference in New Issue
Block a user