|
|
|
@@ -21,11 +21,13 @@ import (
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"k8s.io/api/core/v1"
|
|
|
|
"k8s.io/api/core/v1"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"k8s.io/apimachinery/pkg/util/intstr"
|
|
|
|
"k8s.io/apimachinery/pkg/util/intstr"
|
|
|
|
|
|
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
|
|
|
restclient "k8s.io/client-go/rest"
|
|
|
|
restclient "k8s.io/client-go/rest"
|
|
|
|
"k8s.io/client-go/tools/cache"
|
|
|
|
"k8s.io/client-go/tools/cache"
|
|
|
|
utiltesting "k8s.io/client-go/util/testing"
|
|
|
|
utiltesting "k8s.io/client-go/util/testing"
|
|
|
|
@@ -38,6 +40,7 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var alwaysReady = func() bool { return true }
|
|
|
|
var alwaysReady = func() bool { return true }
|
|
|
|
|
|
|
|
var neverReady = func() bool { return false }
|
|
|
|
var emptyNodeName string
|
|
|
|
var emptyNodeName string
|
|
|
|
|
|
|
|
|
|
|
|
func addPods(store cache.Store, namespace string, nPods int, nPorts int, nNotReady int) {
|
|
|
|
func addPods(store cache.Store, namespace string, nPods int, nPorts int, nNotReady int) {
|
|
|
|
@@ -78,10 +81,10 @@ type serverResponse struct {
|
|
|
|
obj interface{}
|
|
|
|
obj interface{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func makeTestServer(t *testing.T, namespace string, endpointsResponse serverResponse) (*httptest.Server, *utiltesting.FakeHandler) {
|
|
|
|
func makeTestServer(t *testing.T, namespace string) (*httptest.Server, *utiltesting.FakeHandler) {
|
|
|
|
fakeEndpointsHandler := utiltesting.FakeHandler{
|
|
|
|
fakeEndpointsHandler := utiltesting.FakeHandler{
|
|
|
|
StatusCode: endpointsResponse.statusCode,
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
ResponseBody: runtime.EncodeOrDie(testapi.Default.Codec(), endpointsResponse.obj.(runtime.Object)),
|
|
|
|
ResponseBody: runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
mux.Handle(testapi.Default.ResourcePath("endpoints", namespace, ""), &fakeEndpointsHandler)
|
|
|
|
mux.Handle(testapi.Default.ResourcePath("endpoints", namespace, ""), &fakeEndpointsHandler)
|
|
|
|
@@ -95,39 +98,43 @@ func makeTestServer(t *testing.T, namespace string, endpointsResponse serverResp
|
|
|
|
|
|
|
|
|
|
|
|
type endpointController struct {
|
|
|
|
type endpointController struct {
|
|
|
|
*EndpointController
|
|
|
|
*EndpointController
|
|
|
|
podStore cache.Store
|
|
|
|
podStore cache.Store
|
|
|
|
serviceStore cache.Store
|
|
|
|
serviceStore cache.Store
|
|
|
|
|
|
|
|
endpointsStore cache.Store
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newController(url string) *endpointController {
|
|
|
|
func newController(url string) *endpointController {
|
|
|
|
client := clientset.NewForConfigOrDie(&restclient.Config{Host: url, ContentConfig: restclient.ContentConfig{GroupVersion: &api.Registry.GroupOrDie(v1.GroupName).GroupVersion}})
|
|
|
|
client := clientset.NewForConfigOrDie(&restclient.Config{Host: url, ContentConfig: restclient.ContentConfig{GroupVersion: &api.Registry.GroupOrDie(v1.GroupName).GroupVersion}})
|
|
|
|
informerFactory := informers.NewSharedInformerFactory(client, controller.NoResyncPeriodFunc())
|
|
|
|
informerFactory := informers.NewSharedInformerFactory(client, controller.NoResyncPeriodFunc())
|
|
|
|
endpoints := NewEndpointController(informerFactory.Core().V1().Pods(), informerFactory.Core().V1().Services(), client)
|
|
|
|
endpoints := NewEndpointController(informerFactory.Core().V1().Pods(), informerFactory.Core().V1().Services(),
|
|
|
|
|
|
|
|
informerFactory.Core().V1().Endpoints(), client)
|
|
|
|
endpoints.podsSynced = alwaysReady
|
|
|
|
endpoints.podsSynced = alwaysReady
|
|
|
|
endpoints.servicesSynced = alwaysReady
|
|
|
|
endpoints.servicesSynced = alwaysReady
|
|
|
|
|
|
|
|
endpoints.endpointsSynced = alwaysReady
|
|
|
|
return &endpointController{
|
|
|
|
return &endpointController{
|
|
|
|
endpoints,
|
|
|
|
endpoints,
|
|
|
|
informerFactory.Core().V1().Pods().Informer().GetStore(),
|
|
|
|
informerFactory.Core().V1().Pods().Informer().GetStore(),
|
|
|
|
informerFactory.Core().V1().Services().Informer().GetStore(),
|
|
|
|
informerFactory.Core().V1().Services().Informer().GetStore(),
|
|
|
|
|
|
|
|
informerFactory.Core().V1().Endpoints().Informer().GetStore(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestSyncEndpointsItemsPreserveNoSelector(t *testing.T) {
|
|
|
|
func TestSyncEndpointsItemsPreserveNoSelector(t *testing.T) {
|
|
|
|
ns := metav1.NamespaceDefault
|
|
|
|
ns := metav1.NamespaceDefault
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns,
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns)
|
|
|
|
serverResponse{http.StatusOK, &v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "6.7.8.9", NodeName: &emptyNodeName}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 1000}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}})
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
defer testServer.Close()
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
|
|
|
|
endpoints.endpointsStore.Add(&v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "6.7.8.9", NodeName: &emptyNodeName}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 1000}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
})
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Port: 80}}},
|
|
|
|
Spec: v1.ServiceSpec{Ports: []v1.ServicePort{{Port: 80}}},
|
|
|
|
@@ -138,29 +145,21 @@ func TestSyncEndpointsItemsPreserveNoSelector(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestCheckLeftoverEndpoints(t *testing.T) {
|
|
|
|
func TestCheckLeftoverEndpoints(t *testing.T) {
|
|
|
|
ns := metav1.NamespaceDefault
|
|
|
|
ns := metav1.NamespaceDefault
|
|
|
|
// Note that this requests *all* endpoints, therefore metav1.NamespaceAll
|
|
|
|
testServer, _ := makeTestServer(t, ns)
|
|
|
|
// below.
|
|
|
|
|
|
|
|
testServer, _ := makeTestServer(t, metav1.NamespaceAll,
|
|
|
|
|
|
|
|
serverResponse{http.StatusOK, &v1.EndpointsList{
|
|
|
|
|
|
|
|
ListMeta: metav1.ListMeta{
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Items: []v1.Endpoints{{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "6.7.8.9", NodeName: &emptyNodeName}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 1000}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}})
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
defer testServer.Close()
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
|
|
|
|
endpoints.endpointsStore.Add(&v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "6.7.8.9", NodeName: &emptyNodeName}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 1000}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
})
|
|
|
|
endpoints.checkLeftoverEndpoints()
|
|
|
|
endpoints.checkLeftoverEndpoints()
|
|
|
|
|
|
|
|
|
|
|
|
if e, a := 1, endpoints.queue.Len(); e != a {
|
|
|
|
if e, a := 1, endpoints.queue.Len(); e != a {
|
|
|
|
t.Fatalf("Expected %v, got %v", e, a)
|
|
|
|
t.Fatalf("Expected %v, got %v", e, a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -172,21 +171,20 @@ func TestCheckLeftoverEndpoints(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestSyncEndpointsProtocolTCP(t *testing.T) {
|
|
|
|
func TestSyncEndpointsProtocolTCP(t *testing.T) {
|
|
|
|
ns := "other"
|
|
|
|
ns := "other"
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns,
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns)
|
|
|
|
serverResponse{http.StatusOK, &v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "6.7.8.9", NodeName: &emptyNodeName}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 1000, Protocol: "TCP"}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}})
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
defer testServer.Close()
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
|
|
|
|
endpoints.endpointsStore.Add(&v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "6.7.8.9", NodeName: &emptyNodeName}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 1000, Protocol: "TCP"}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
})
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 0)
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 0)
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
@@ -196,7 +194,8 @@ func TestSyncEndpointsProtocolTCP(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
endpointsHandler.ValidateRequestCount(t, 2)
|
|
|
|
|
|
|
|
|
|
|
|
endpointsHandler.ValidateRequestCount(t, 1)
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Name: "foo",
|
|
|
|
@@ -213,20 +212,20 @@ func TestSyncEndpointsProtocolTCP(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestSyncEndpointsProtocolUDP(t *testing.T) {
|
|
|
|
func TestSyncEndpointsProtocolUDP(t *testing.T) {
|
|
|
|
ns := "other"
|
|
|
|
ns := "other"
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns,
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns)
|
|
|
|
serverResponse{http.StatusOK, &v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "6.7.8.9", NodeName: &emptyNodeName}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 1000, Protocol: "UDP"}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}})
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
defer testServer.Close()
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
|
|
|
|
endpoints.endpointsStore.Add(&v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "6.7.8.9", NodeName: &emptyNodeName}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 1000, Protocol: "UDP"}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
})
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 0)
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 0)
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
@@ -236,7 +235,8 @@ func TestSyncEndpointsProtocolUDP(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
endpointsHandler.ValidateRequestCount(t, 2)
|
|
|
|
|
|
|
|
|
|
|
|
endpointsHandler.ValidateRequestCount(t, 1)
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Name: "foo",
|
|
|
|
@@ -253,17 +253,17 @@ func TestSyncEndpointsProtocolUDP(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
|
|
|
|
func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
|
|
|
|
ns := "other"
|
|
|
|
ns := "other"
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns,
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns)
|
|
|
|
serverResponse{http.StatusOK, &v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{},
|
|
|
|
|
|
|
|
}})
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
defer testServer.Close()
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
|
|
|
|
endpoints.endpointsStore.Add(&v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{},
|
|
|
|
|
|
|
|
})
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 0)
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 0)
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
@@ -273,6 +273,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
|
|
|
|
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Name: "foo",
|
|
|
|
@@ -289,17 +290,17 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestSyncEndpointsItemsEmptySelectorSelectsAllNotReady(t *testing.T) {
|
|
|
|
func TestSyncEndpointsItemsEmptySelectorSelectsAllNotReady(t *testing.T) {
|
|
|
|
ns := "other"
|
|
|
|
ns := "other"
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns,
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns)
|
|
|
|
serverResponse{http.StatusOK, &v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{},
|
|
|
|
|
|
|
|
}})
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
defer testServer.Close()
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
|
|
|
|
endpoints.endpointsStore.Add(&v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{},
|
|
|
|
|
|
|
|
})
|
|
|
|
addPods(endpoints.podStore, ns, 0, 1, 1)
|
|
|
|
addPods(endpoints.podStore, ns, 0, 1, 1)
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
@@ -309,6 +310,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAllNotReady(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
|
|
|
|
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Name: "foo",
|
|
|
|
@@ -325,17 +327,17 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAllNotReady(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestSyncEndpointsItemsEmptySelectorSelectsAllMixed(t *testing.T) {
|
|
|
|
func TestSyncEndpointsItemsEmptySelectorSelectsAllMixed(t *testing.T) {
|
|
|
|
ns := "other"
|
|
|
|
ns := "other"
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns,
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns)
|
|
|
|
serverResponse{http.StatusOK, &v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{},
|
|
|
|
|
|
|
|
}})
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
defer testServer.Close()
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
|
|
|
|
endpoints.endpointsStore.Add(&v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{},
|
|
|
|
|
|
|
|
})
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 1)
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 1)
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
@@ -345,6 +347,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAllMixed(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
|
|
|
|
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Name: "foo",
|
|
|
|
@@ -362,20 +365,20 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAllMixed(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestSyncEndpointsItemsPreexisting(t *testing.T) {
|
|
|
|
func TestSyncEndpointsItemsPreexisting(t *testing.T) {
|
|
|
|
ns := "bar"
|
|
|
|
ns := "bar"
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns,
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns)
|
|
|
|
serverResponse{http.StatusOK, &v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "6.7.8.9", NodeName: &emptyNodeName}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 1000}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}})
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
defer testServer.Close()
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
|
|
|
|
endpoints.endpointsStore.Add(&v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "6.7.8.9", NodeName: &emptyNodeName}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 1000}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
})
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 0)
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 0)
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
@@ -385,6 +388,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
|
|
|
|
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Name: "foo",
|
|
|
|
@@ -401,20 +405,20 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
|
|
|
|
func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
|
|
|
|
ns := metav1.NamespaceDefault
|
|
|
|
ns := metav1.NamespaceDefault
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, metav1.NamespaceDefault,
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns)
|
|
|
|
serverResponse{http.StatusOK, &v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "1.2.3.4", NodeName: &emptyNodeName, TargetRef: &v1.ObjectReference{Kind: "Pod", Name: "pod0", Namespace: ns}}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 8080, Protocol: "TCP"}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}})
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
defer testServer.Close()
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
|
|
|
|
endpoints.endpointsStore.Add(&v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "1.2.3.4", NodeName: &emptyNodeName, TargetRef: &v1.ObjectReference{Kind: "Pod", Name: "pod0", Namespace: ns}}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 8080, Protocol: "TCP"}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
})
|
|
|
|
addPods(endpoints.podStore, metav1.NamespaceDefault, 1, 1, 0)
|
|
|
|
addPods(endpoints.podStore, metav1.NamespaceDefault, 1, 1, 0)
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: metav1.NamespaceDefault},
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: metav1.NamespaceDefault},
|
|
|
|
@@ -424,13 +428,12 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
endpointsHandler.ValidateRequest(t, testapi.Default.ResourcePath("endpoints", metav1.NamespaceDefault, "foo"), "GET", nil)
|
|
|
|
endpointsHandler.ValidateRequestCount(t, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestSyncEndpointsItems(t *testing.T) {
|
|
|
|
func TestSyncEndpointsItems(t *testing.T) {
|
|
|
|
ns := "other"
|
|
|
|
ns := "other"
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns,
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns)
|
|
|
|
serverResponse{http.StatusOK, &v1.Endpoints{}})
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
defer testServer.Close()
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
addPods(endpoints.podStore, ns, 3, 2, 0)
|
|
|
|
addPods(endpoints.podStore, ns, 3, 2, 0)
|
|
|
|
@@ -446,6 +449,7 @@ func TestSyncEndpointsItems(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
endpoints.syncService("other/foo")
|
|
|
|
endpoints.syncService("other/foo")
|
|
|
|
|
|
|
|
|
|
|
|
expectedSubsets := []v1.EndpointSubset{{
|
|
|
|
expectedSubsets := []v1.EndpointSubset{{
|
|
|
|
Addresses: []v1.EndpointAddress{
|
|
|
|
Addresses: []v1.EndpointAddress{
|
|
|
|
{IP: "1.2.3.4", NodeName: &emptyNodeName, TargetRef: &v1.ObjectReference{Kind: "Pod", Name: "pod0", Namespace: ns}},
|
|
|
|
{IP: "1.2.3.4", NodeName: &emptyNodeName, TargetRef: &v1.ObjectReference{Kind: "Pod", Name: "pod0", Namespace: ns}},
|
|
|
|
@@ -460,18 +464,17 @@ func TestSyncEndpointsItems(t *testing.T) {
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
ResourceVersion: "",
|
|
|
|
ResourceVersion: "",
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subsets: endptspkg.SortSubsets(expectedSubsets),
|
|
|
|
Subsets: endptspkg.SortSubsets(expectedSubsets),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// endpointsHandler should get 2 requests - one for "GET" and the next for "POST".
|
|
|
|
endpointsHandler.ValidateRequestCount(t, 1)
|
|
|
|
endpointsHandler.ValidateRequestCount(t, 2)
|
|
|
|
|
|
|
|
endpointsHandler.ValidateRequest(t, testapi.Default.ResourcePath("endpoints", ns, ""), "POST", &data)
|
|
|
|
endpointsHandler.ValidateRequest(t, testapi.Default.ResourcePath("endpoints", ns, ""), "POST", &data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestSyncEndpointsItemsWithLabels(t *testing.T) {
|
|
|
|
func TestSyncEndpointsItemsWithLabels(t *testing.T) {
|
|
|
|
ns := "other"
|
|
|
|
ns := "other"
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns,
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns)
|
|
|
|
serverResponse{http.StatusOK, &v1.Endpoints{}})
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
defer testServer.Close()
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
addPods(endpoints.podStore, ns, 3, 2, 0)
|
|
|
|
addPods(endpoints.podStore, ns, 3, 2, 0)
|
|
|
|
@@ -491,6 +494,7 @@ func TestSyncEndpointsItemsWithLabels(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
|
|
|
|
|
|
|
|
expectedSubsets := []v1.EndpointSubset{{
|
|
|
|
expectedSubsets := []v1.EndpointSubset{{
|
|
|
|
Addresses: []v1.EndpointAddress{
|
|
|
|
Addresses: []v1.EndpointAddress{
|
|
|
|
{IP: "1.2.3.4", NodeName: &emptyNodeName, TargetRef: &v1.ObjectReference{Kind: "Pod", Name: "pod0", Namespace: ns}},
|
|
|
|
{IP: "1.2.3.4", NodeName: &emptyNodeName, TargetRef: &v1.ObjectReference{Kind: "Pod", Name: "pod0", Namespace: ns}},
|
|
|
|
@@ -505,34 +509,34 @@ func TestSyncEndpointsItemsWithLabels(t *testing.T) {
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
ResourceVersion: "",
|
|
|
|
ResourceVersion: "",
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
Labels: serviceLabels,
|
|
|
|
Labels: serviceLabels,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Subsets: endptspkg.SortSubsets(expectedSubsets),
|
|
|
|
Subsets: endptspkg.SortSubsets(expectedSubsets),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// endpointsHandler should get 2 requests - one for "GET" and the next for "POST".
|
|
|
|
endpointsHandler.ValidateRequestCount(t, 1)
|
|
|
|
endpointsHandler.ValidateRequestCount(t, 2)
|
|
|
|
|
|
|
|
endpointsHandler.ValidateRequest(t, testapi.Default.ResourcePath("endpoints", ns, ""), "POST", &data)
|
|
|
|
endpointsHandler.ValidateRequest(t, testapi.Default.ResourcePath("endpoints", ns, ""), "POST", &data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestSyncEndpointsItemsPreexistingLabelsChange(t *testing.T) {
|
|
|
|
func TestSyncEndpointsItemsPreexistingLabelsChange(t *testing.T) {
|
|
|
|
ns := "bar"
|
|
|
|
ns := "bar"
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns,
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns)
|
|
|
|
serverResponse{http.StatusOK, &v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
Labels: map[string]string{
|
|
|
|
|
|
|
|
"foo": "bar",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "6.7.8.9", NodeName: &emptyNodeName}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 1000}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}})
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
defer testServer.Close()
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
|
|
|
|
endpoints.endpointsStore.Add(&v1.Endpoints{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Namespace: ns,
|
|
|
|
|
|
|
|
ResourceVersion: "1",
|
|
|
|
|
|
|
|
Labels: map[string]string{
|
|
|
|
|
|
|
|
"foo": "bar",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "6.7.8.9", NodeName: &emptyNodeName}},
|
|
|
|
|
|
|
|
Ports: []v1.EndpointPort{{Port: 1000}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
})
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 0)
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 0)
|
|
|
|
serviceLabels := map[string]string{"baz": "blah"}
|
|
|
|
serviceLabels := map[string]string{"baz": "blah"}
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
endpoints.serviceStore.Add(&v1.Service{
|
|
|
|
@@ -547,6 +551,7 @@ func TestSyncEndpointsItemsPreexistingLabelsChange(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
endpoints.syncService(ns + "/foo")
|
|
|
|
|
|
|
|
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
data := runtime.EncodeOrDie(testapi.Default.Codec(), &v1.Endpoints{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "foo",
|
|
|
|
Name: "foo",
|
|
|
|
@@ -561,3 +566,57 @@ func TestSyncEndpointsItemsPreexistingLabelsChange(t *testing.T) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
endpointsHandler.ValidateRequest(t, testapi.Default.ResourcePath("endpoints", ns, "foo"), "PUT", &data)
|
|
|
|
endpointsHandler.ValidateRequest(t, testapi.Default.ResourcePath("endpoints", ns, "foo"), "PUT", &data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestWaitsForAllInformersToBeSynced2(t *testing.T) {
|
|
|
|
|
|
|
|
var tests = []struct {
|
|
|
|
|
|
|
|
podsSynced func() bool
|
|
|
|
|
|
|
|
servicesSynced func() bool
|
|
|
|
|
|
|
|
endpointsSynced func() bool
|
|
|
|
|
|
|
|
shouldUpdateEndpoints bool
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{neverReady, alwaysReady, alwaysReady, false},
|
|
|
|
|
|
|
|
{alwaysReady, neverReady, alwaysReady, false},
|
|
|
|
|
|
|
|
{alwaysReady, alwaysReady, neverReady, false},
|
|
|
|
|
|
|
|
{alwaysReady, alwaysReady, alwaysReady, true},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
|
|
|
func() {
|
|
|
|
|
|
|
|
ns := "other"
|
|
|
|
|
|
|
|
testServer, endpointsHandler := makeTestServer(t, ns)
|
|
|
|
|
|
|
|
defer testServer.Close()
|
|
|
|
|
|
|
|
endpoints := newController(testServer.URL)
|
|
|
|
|
|
|
|
addPods(endpoints.podStore, ns, 1, 1, 0)
|
|
|
|
|
|
|
|
service := &v1.Service{
|
|
|
|
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: ns},
|
|
|
|
|
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
|
|
|
|
Selector: map[string]string{},
|
|
|
|
|
|
|
|
Ports: []v1.ServicePort{{Port: 80, TargetPort: intstr.FromInt(8080), Protocol: "TCP"}},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
endpoints.serviceStore.Add(service)
|
|
|
|
|
|
|
|
endpoints.enqueueService(service)
|
|
|
|
|
|
|
|
endpoints.podsSynced = test.podsSynced
|
|
|
|
|
|
|
|
endpoints.servicesSynced = test.servicesSynced
|
|
|
|
|
|
|
|
endpoints.endpointsSynced = test.endpointsSynced
|
|
|
|
|
|
|
|
endpoints.workerLoopPeriod = 10 * time.Millisecond
|
|
|
|
|
|
|
|
stopCh := make(chan struct{})
|
|
|
|
|
|
|
|
defer close(stopCh)
|
|
|
|
|
|
|
|
go endpoints.Run(1, stopCh)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// cache.WaitForCacheSync has a 100ms poll period, and the endpoints worker has a 10ms period.
|
|
|
|
|
|
|
|
// To ensure we get all updates, including unexpected ones, we need to wait at least as long as
|
|
|
|
|
|
|
|
// a single cache sync period and worker period, with some fudge room.
|
|
|
|
|
|
|
|
time.Sleep(150 * time.Millisecond)
|
|
|
|
|
|
|
|
if test.shouldUpdateEndpoints {
|
|
|
|
|
|
|
|
// Ensure the work queue has been processed by looping for up to a second to prevent flakes.
|
|
|
|
|
|
|
|
wait.PollImmediate(50*time.Millisecond, 1*time.Second, func() (bool, error) {
|
|
|
|
|
|
|
|
return endpoints.queue.Len() == 0, nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
endpointsHandler.ValidateRequestCount(t, 1)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
endpointsHandler.ValidateRequestCount(t, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|