Change:
expectEndpoint(t, loadBalancer, barServiceP, shuffledBarEndpoints[2], nil) } <del> func TestStickyLoadBalanceWorksWithSingleEndpoint(t *testing.T) { client1 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0} client2 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 2), Port: 0} </del> <ins> func TestStickyLoadBalanceWorksWithNewServiceCalledFirst(t *testing.T) { </ins> loadBalancer := NewLoadBalancerRR() service := ServicePortName{types.NamespacedName{"testnamespace", "foo"}, ""} endpoint, err := loadBalancer.NextEndpoint(service, nil) if err == nil || len(endpoint) != 0 { t.Errorf("Didn't fail with non-existent service") } <ins> // Call NewService() before OnUpdate() </ins> loadBalancer.NewService(service, api.ServiceAffinityClientIP, 0) endpoints := make([]api.Endpoints, 1) endpoints[0] = api.Endpoints{ ObjectMeta: api.ObjectMeta{Name: service.Name, Namespace: service.Namespace}, <del> Subsets:    []api.EndpointSubset{{Addresses: []api.EndpointAddress{{IP: "endpoint"}}, Ports: []api.EndpointPort{{Port: 1}}}}, </del> <ins> Subsets: []api.EndpointSubset{ {Addresses: []api.EndpointAddress{{IP: "endpoint1"}}, Ports: []api.EndpointPort{{Port: 1}}}, {Addresses: []api.EndpointAddress{{IP: "endpoint2"}}, Ports: []api.EndpointPort{{Port: 2}}}, {Addresses: []api.EndpointAddress{{IP: "endpoint3"}}, Ports: []api.EndpointPort{{Port: 3}}}, }, </ins> } loadBalancer.OnUpdate(endpoints) <del> expectEndpoint(t, loadBalancer, service, "endpoint:1", client1) expectEndpoint(t, loadBalancer, service, "endpoint:1", client1) expectEndpoint(t, loadBalancer, service, "endpoint:1", client2) expectEndpoint(t, loadBalancer, service, "endpoint:1", client2) } func TestStickyLoadBalanaceWorksWithMultipleEndpoints(t *testing.T) { </del> client1 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0} client2 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 2), Port: 0} client3 := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 3), Port: 0} <ins> ep1, err := loadBalancer.NextEndpoint(service, client1) if err != nil { t.Errorf("Didn't find a service for %s: %v", service, err) } expectEndpoint(t, loadBalancer, service, ep1, client1) expectEndpoint(t, loadBalancer, service, ep1, client1) expectEndpoint(t, loadBalancer, service, ep1, client1) ep2, err := loadBalancer.NextEndpoint(service, client2) if err != nil { t.Errorf("Didn't find a service for %s: %v", service, err) } expectEndpoint(t, loadBalancer, service, ep2, client2) expectEndpoint(t, loadBalancer, service, ep2, client2) expectEndpoint(t, loadBalancer, service, ep2, client2) ep3, err := loadBalancer.NextEndpoint(service, client3) if err != nil { t.Errorf("Didn't find a service for %s: %v", service, err) } expectEndpoint(t, loadBalancer, service, ep3, client3) expectEndpoint(t, loadBalancer, service, ep3, client3) expectEndpoint(t, loadBalancer, service, ep3, client3) expectEndpoint(t, loadBalancer, service, ep1, client1) expectEndpoint(t, loadBalancer, service, ep2, client2) expectEndpoint(t, loadBalancer, service, ep3, client3) expectEndpoint(t, loadBalancer, service, ep1, client1) expectEndpoint(t, loadBalancer, service, ep2, client2) expectEndpoint(t, loadBalancer, service, ep3, client3) } func TestStickyLoadBalanceWorksWithNewServiceCalledSecond(t *testing.T) { </ins> loadBalancer := NewLoadBalancerRR() service := ServicePortName{types.NamespacedName{"testnamespace", "foo"}, ""} endpoint, err := loadBalancer.NextEndpoint(service, nil)

Discussion:
!topic/google-containers/pjx13NWEFcg The bug seems to be in kube-proxy.