mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Edge-based userspace proxy
This commit is contained in:
		@@ -67,8 +67,6 @@ func TestFilterWorks(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
func TestLoadBalanceFailsWithNoEndpoints(t *testing.T) {
 | 
			
		||||
	loadBalancer := NewLoadBalancerRR()
 | 
			
		||||
	var endpoints []*api.Endpoints
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	service := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "foo"}, Port: "does-not-exist"}
 | 
			
		||||
	endpoint, err := loadBalancer.NextEndpoint(service, nil, false)
 | 
			
		||||
	if err == nil {
 | 
			
		||||
@@ -106,15 +104,14 @@ func TestLoadBalanceWorksWithSingleEndpoint(t *testing.T) {
 | 
			
		||||
	if err == nil || len(endpoint) != 0 {
 | 
			
		||||
		t.Errorf("Didn't fail with non-existent service")
 | 
			
		||||
	}
 | 
			
		||||
	endpoints := make([]*api.Endpoints, 1)
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpoints := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{{
 | 
			
		||||
			Addresses: []api.EndpointAddress{{IP: "endpoint1"}},
 | 
			
		||||
			Ports:     []api.EndpointPort{{Name: "p", Port: 40}},
 | 
			
		||||
		}},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpoints)
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, "endpoint1:40", nil)
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, "endpoint1:40", nil)
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, "endpoint1:40", nil)
 | 
			
		||||
@@ -144,15 +141,14 @@ func TestLoadBalanceWorksWithMultipleEndpoints(t *testing.T) {
 | 
			
		||||
	if err == nil || len(endpoint) != 0 {
 | 
			
		||||
		t.Errorf("Didn't fail with non-existent service")
 | 
			
		||||
	}
 | 
			
		||||
	endpoints := make([]*api.Endpoints, 1)
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpoints := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{{
 | 
			
		||||
			Addresses: []api.EndpointAddress{{IP: "endpoint"}},
 | 
			
		||||
			Ports:     []api.EndpointPort{{Name: "p", Port: 1}, {Name: "p", Port: 2}, {Name: "p", Port: 3}},
 | 
			
		||||
		}},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpoints)
 | 
			
		||||
 | 
			
		||||
	shuffledEndpoints := loadBalancer.services[service].endpoints
 | 
			
		||||
	if !stringsInSlice(shuffledEndpoints, "endpoint:1", "endpoint:2", "endpoint:3") {
 | 
			
		||||
@@ -172,8 +168,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsMultiplePorts(t *testing.T) {
 | 
			
		||||
	if err == nil || len(endpoint) != 0 {
 | 
			
		||||
		t.Errorf("Didn't fail with non-existent service")
 | 
			
		||||
	}
 | 
			
		||||
	endpoints := make([]*api.Endpoints, 1)
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpoints := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{
 | 
			
		||||
@@ -186,7 +181,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsMultiplePorts(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpoints)
 | 
			
		||||
 | 
			
		||||
	shuffledEndpoints := loadBalancer.services[serviceP].endpoints
 | 
			
		||||
	if !stringsInSlice(shuffledEndpoints, "endpoint1:1", "endpoint2:1", "endpoint3:3") {
 | 
			
		||||
@@ -215,8 +210,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
 | 
			
		||||
	if err == nil || len(endpoint) != 0 {
 | 
			
		||||
		t.Errorf("Didn't fail with non-existent service")
 | 
			
		||||
	}
 | 
			
		||||
	endpoints := make([]*api.Endpoints, 1)
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpointsv1 := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{
 | 
			
		||||
@@ -233,7 +227,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpointsv1)
 | 
			
		||||
 | 
			
		||||
	shuffledEndpoints := loadBalancer.services[serviceP].endpoints
 | 
			
		||||
	if !stringsInSlice(shuffledEndpoints, "endpoint1:1", "endpoint2:2", "endpoint3:3") {
 | 
			
		||||
@@ -255,7 +249,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// Then update the configuration with one fewer endpoints, make sure
 | 
			
		||||
	// we start in the beginning again
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpointsv2 := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{
 | 
			
		||||
@@ -268,7 +262,7 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpointsv1, endpointsv2)
 | 
			
		||||
 | 
			
		||||
	shuffledEndpoints = loadBalancer.services[serviceP].endpoints
 | 
			
		||||
	if !stringsInSlice(shuffledEndpoints, "endpoint4:4", "endpoint5:5") {
 | 
			
		||||
@@ -289,8 +283,8 @@ func TestLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
 | 
			
		||||
	expectEndpoint(t, loadBalancer, serviceQ, shuffledEndpoints[1], nil)
 | 
			
		||||
 | 
			
		||||
	// Clear endpoints
 | 
			
		||||
	endpoints[0] = &api.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, Subsets: nil}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	endpointsv3 := &api.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: serviceP.Name, Namespace: serviceP.Namespace}, Subsets: nil}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpointsv2, endpointsv3)
 | 
			
		||||
 | 
			
		||||
	endpoint, err = loadBalancer.NextEndpoint(serviceP, nil, false)
 | 
			
		||||
	if err == nil || len(endpoint) != 0 {
 | 
			
		||||
@@ -306,8 +300,7 @@ func TestLoadBalanceWorksWithServiceRemoval(t *testing.T) {
 | 
			
		||||
	if err == nil || len(endpoint) != 0 {
 | 
			
		||||
		t.Errorf("Didn't fail with non-existent service")
 | 
			
		||||
	}
 | 
			
		||||
	endpoints := make([]*api.Endpoints, 2)
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpoints1 := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: fooServiceP.Name, Namespace: fooServiceP.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{
 | 
			
		||||
@@ -316,7 +309,7 @@ func TestLoadBalanceWorksWithServiceRemoval(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	endpoints[1] = &api.Endpoints{
 | 
			
		||||
	endpoints2 := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: barServiceP.Name, Namespace: barServiceP.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{
 | 
			
		||||
@@ -325,7 +318,8 @@ func TestLoadBalanceWorksWithServiceRemoval(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpoints1)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpoints2)
 | 
			
		||||
	shuffledFooEndpoints := loadBalancer.services[fooServiceP].endpoints
 | 
			
		||||
	expectEndpoint(t, loadBalancer, fooServiceP, shuffledFooEndpoints[0], nil)
 | 
			
		||||
	expectEndpoint(t, loadBalancer, fooServiceP, shuffledFooEndpoints[1], nil)
 | 
			
		||||
@@ -341,7 +335,7 @@ func TestLoadBalanceWorksWithServiceRemoval(t *testing.T) {
 | 
			
		||||
	expectEndpoint(t, loadBalancer, barServiceP, shuffledBarEndpoints[1], nil)
 | 
			
		||||
 | 
			
		||||
	// Then update the configuration by removing foo
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints[1:])
 | 
			
		||||
	loadBalancer.OnEndpointsDelete(endpoints1)
 | 
			
		||||
	endpoint, err = loadBalancer.NextEndpoint(fooServiceP, nil, false)
 | 
			
		||||
	if err == nil || len(endpoint) != 0 {
 | 
			
		||||
		t.Errorf("Didn't fail with non-existent service")
 | 
			
		||||
@@ -364,8 +358,7 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledFirst(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// Call NewService() before OnEndpointsUpdate()
 | 
			
		||||
	loadBalancer.NewService(service, api.ServiceAffinityClientIP, 0)
 | 
			
		||||
	endpoints := make([]*api.Endpoints, 1)
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpoints := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Ports: []api.EndpointPort{{Port: 1}}},
 | 
			
		||||
@@ -373,7 +366,7 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledFirst(t *testing.T) {
 | 
			
		||||
			{Addresses: []api.EndpointAddress{{IP: "endpoint3"}}, Ports: []api.EndpointPort{{Port: 3}}},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpoints)
 | 
			
		||||
 | 
			
		||||
	client1 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0}
 | 
			
		||||
	client2 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 2), Port: 0}
 | 
			
		||||
@@ -420,15 +413,14 @@ func TestStickyLoadBalanceWorksWithNewServiceCalledSecond(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Call OnEndpointsUpdate() before NewService()
 | 
			
		||||
	endpoints := make([]*api.Endpoints, 1)
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpoints := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Ports: []api.EndpointPort{{Port: 1}}},
 | 
			
		||||
			{Addresses: []api.EndpointAddress{{IP: "endpoint2"}}, Ports: []api.EndpointPort{{Port: 2}}},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpoints)
 | 
			
		||||
	loadBalancer.NewService(service, api.ServiceAffinityClientIP, 0)
 | 
			
		||||
 | 
			
		||||
	client1 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0}
 | 
			
		||||
@@ -482,8 +474,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	loadBalancer.NewService(service, api.ServiceAffinityClientIP, 0)
 | 
			
		||||
	endpoints := make([]*api.Endpoints, 1)
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpointsv1 := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{
 | 
			
		||||
@@ -492,7 +483,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpointsv1)
 | 
			
		||||
	shuffledEndpoints := loadBalancer.services[service].endpoints
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, shuffledEndpoints[0], client1)
 | 
			
		||||
	client1Endpoint := shuffledEndpoints[0]
 | 
			
		||||
@@ -503,7 +494,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, shuffledEndpoints[2], client3)
 | 
			
		||||
	client3Endpoint := shuffledEndpoints[2]
 | 
			
		||||
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpointsv2 := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{
 | 
			
		||||
@@ -512,7 +503,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpointsv1, endpointsv2)
 | 
			
		||||
	shuffledEndpoints = loadBalancer.services[service].endpoints
 | 
			
		||||
	if client1Endpoint == "endpoint:3" {
 | 
			
		||||
		client1Endpoint = shuffledEndpoints[0]
 | 
			
		||||
@@ -525,7 +516,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, client2Endpoint, client2)
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, client3Endpoint, client3)
 | 
			
		||||
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpointsv3 := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{
 | 
			
		||||
@@ -534,7 +525,7 @@ func TestStickyLoadBalanaceWorksWithMultipleEndpointsRemoveOne(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpointsv2, endpointsv3)
 | 
			
		||||
	shuffledEndpoints = loadBalancer.services[service].endpoints
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, client1Endpoint, client1)
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, client2Endpoint, client2)
 | 
			
		||||
@@ -556,8 +547,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	loadBalancer.NewService(service, api.ServiceAffinityClientIP, 0)
 | 
			
		||||
	endpoints := make([]*api.Endpoints, 1)
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpointsv1 := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{
 | 
			
		||||
@@ -566,7 +556,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpointsv1)
 | 
			
		||||
	shuffledEndpoints := loadBalancer.services[service].endpoints
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, shuffledEndpoints[0], client1)
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, shuffledEndpoints[0], client1)
 | 
			
		||||
@@ -577,7 +567,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, shuffledEndpoints[1], client2)
 | 
			
		||||
	// Then update the configuration with one fewer endpoints, make sure
 | 
			
		||||
	// we start in the beginning again
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpointsv2 := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{
 | 
			
		||||
@@ -586,7 +576,7 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpointsv1, endpointsv2)
 | 
			
		||||
	shuffledEndpoints = loadBalancer.services[service].endpoints
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, shuffledEndpoints[0], client1)
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, shuffledEndpoints[1], client2)
 | 
			
		||||
@@ -596,8 +586,8 @@ func TestStickyLoadBalanceWorksWithMultipleEndpointsAndUpdates(t *testing.T) {
 | 
			
		||||
	expectEndpoint(t, loadBalancer, service, shuffledEndpoints[1], client2)
 | 
			
		||||
 | 
			
		||||
	// Clear endpoints
 | 
			
		||||
	endpoints[0] = &api.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, Subsets: nil}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	endpointsv3 := &api.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, Subsets: nil}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpointsv2, endpointsv3)
 | 
			
		||||
 | 
			
		||||
	endpoint, err = loadBalancer.NextEndpoint(service, nil, false)
 | 
			
		||||
	if err == nil || len(endpoint) != 0 {
 | 
			
		||||
@@ -616,8 +606,7 @@ func TestStickyLoadBalanceWorksWithServiceRemoval(t *testing.T) {
 | 
			
		||||
		t.Errorf("Didn't fail with non-existent service")
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.NewService(fooService, api.ServiceAffinityClientIP, 0)
 | 
			
		||||
	endpoints := make([]*api.Endpoints, 2)
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpoints1 := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: fooService.Name, Namespace: fooService.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{
 | 
			
		||||
@@ -628,7 +617,7 @@ func TestStickyLoadBalanceWorksWithServiceRemoval(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
	barService := proxy.ServicePortName{NamespacedName: types.NamespacedName{Namespace: "testnamespace", Name: "bar"}, Port: ""}
 | 
			
		||||
	loadBalancer.NewService(barService, api.ServiceAffinityClientIP, 0)
 | 
			
		||||
	endpoints[1] = &api.Endpoints{
 | 
			
		||||
	endpoints2 := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: barService.Name, Namespace: barService.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{
 | 
			
		||||
@@ -637,7 +626,8 @@ func TestStickyLoadBalanceWorksWithServiceRemoval(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpoints1)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpoints2)
 | 
			
		||||
 | 
			
		||||
	shuffledFooEndpoints := loadBalancer.services[fooService].endpoints
 | 
			
		||||
	expectEndpoint(t, loadBalancer, fooService, shuffledFooEndpoints[0], client1)
 | 
			
		||||
@@ -659,7 +649,7 @@ func TestStickyLoadBalanceWorksWithServiceRemoval(t *testing.T) {
 | 
			
		||||
	expectEndpoint(t, loadBalancer, barService, shuffledBarEndpoints[1], client2)
 | 
			
		||||
 | 
			
		||||
	// Then update the configuration by removing foo
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints[1:])
 | 
			
		||||
	loadBalancer.OnEndpointsDelete(endpoints1)
 | 
			
		||||
	endpoint, err = loadBalancer.NextEndpoint(fooService, nil, false)
 | 
			
		||||
	if err == nil || len(endpoint) != 0 {
 | 
			
		||||
		t.Errorf("Didn't fail with non-existent service")
 | 
			
		||||
@@ -685,8 +675,7 @@ func TestStickyLoadBalanceWorksWithEndpointFails(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// Call NewService() before OnEndpointsUpdate()
 | 
			
		||||
	loadBalancer.NewService(service, api.ServiceAffinityClientIP, 0)
 | 
			
		||||
	endpoints := make([]*api.Endpoints, 1)
 | 
			
		||||
	endpoints[0] = &api.Endpoints{
 | 
			
		||||
	endpoints := &api.Endpoints{
 | 
			
		||||
		ObjectMeta: metav1.ObjectMeta{Name: service.Name, Namespace: service.Namespace},
 | 
			
		||||
		Subsets: []api.EndpointSubset{
 | 
			
		||||
			{Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Ports: []api.EndpointPort{{Port: 1}}},
 | 
			
		||||
@@ -694,7 +683,7 @@ func TestStickyLoadBalanceWorksWithEndpointFails(t *testing.T) {
 | 
			
		||||
			{Addresses: []api.EndpointAddress{{IP: "endpoint3"}}, Ports: []api.EndpointPort{{Port: 3}}},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	loadBalancer.OnEndpointsUpdate(endpoints)
 | 
			
		||||
	loadBalancer.OnEndpointsAdd(endpoints)
 | 
			
		||||
 | 
			
		||||
	client1 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0}
 | 
			
		||||
	client2 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 2), Port: 0}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user