Do not create endpoints if service of type ExternalName (#114814)
This commit is contained in:

committed by
GitHub

parent
46f3821bf4
commit
6adf60fdf4
@@ -479,6 +479,75 @@ func TestSyncEndpointsHeadlessServiceLabel(t *testing.T) {
|
||||
endpointsHandler.ValidateRequestCount(t, 0)
|
||||
}
|
||||
|
||||
func TestSyncServiceExternalNameType(t *testing.T) {
|
||||
serviceName := "testing-1"
|
||||
namespace := metav1.NamespaceDefault
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
service *v1.Service
|
||||
}{
|
||||
{
|
||||
desc: "External name with selector and ports should not receive endpoints",
|
||||
service: &v1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: serviceName, Namespace: namespace},
|
||||
Spec: v1.ServiceSpec{
|
||||
Selector: map[string]string{"foo": "bar"},
|
||||
Ports: []v1.ServicePort{{Port: 80}},
|
||||
Type: v1.ServiceTypeExternalName,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "External name with ports should not receive endpoints",
|
||||
service: &v1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: serviceName, Namespace: namespace},
|
||||
Spec: v1.ServiceSpec{
|
||||
Ports: []v1.ServicePort{{Port: 80}},
|
||||
Type: v1.ServiceTypeExternalName,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "External name with selector should not receive endpoints",
|
||||
service: &v1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: serviceName, Namespace: namespace},
|
||||
Spec: v1.ServiceSpec{
|
||||
Selector: map[string]string{"foo": "bar"},
|
||||
Type: v1.ServiceTypeExternalName,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "External name without selector and ports should not receive endpoints",
|
||||
service: &v1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: serviceName, Namespace: namespace},
|
||||
Spec: v1.ServiceSpec{
|
||||
Type: v1.ServiceTypeExternalName,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
testServer, endpointsHandler := makeTestServer(t, namespace)
|
||||
|
||||
defer testServer.Close()
|
||||
endpoints := newController(testServer.URL, 0*time.Second)
|
||||
err := endpoints.serviceStore.Add(tc.service)
|
||||
if err != nil {
|
||||
t.Fatalf("Error adding service to service store: %v", err)
|
||||
}
|
||||
err = endpoints.syncService(context.TODO(), namespace+"/"+serviceName)
|
||||
if err != nil {
|
||||
t.Fatalf("Error syncing service: %v", err)
|
||||
}
|
||||
endpointsHandler.ValidateRequestCount(t, 0)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncEndpointsProtocolUDP(t *testing.T) {
|
||||
ns := "other"
|
||||
testServer, endpointsHandler := makeTestServer(t, ns)
|
||||
|
Reference in New Issue
Block a user