|
|
|
@ -44,6 +44,8 @@ func makeMultiPortService() *v1.Service {
|
|
|
|
|
Port: int32(30901), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
Type: v1.ServiceTypeClusterIP, |
|
|
|
|
ClusterIP: "10.0.0.1", |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -62,6 +64,8 @@ func makeSuffixedService(suffix string) *v1.Service {
|
|
|
|
|
Port: int32(30900), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
Type: v1.ServiceTypeClusterIP, |
|
|
|
|
ClusterIP: "10.0.0.1", |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -70,6 +74,26 @@ func makeService() *v1.Service {
|
|
|
|
|
return makeSuffixedService("") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func makeExternalService() *v1.Service { |
|
|
|
|
return &v1.Service{ |
|
|
|
|
ObjectMeta: metav1.ObjectMeta{ |
|
|
|
|
Name: "testservice-external", |
|
|
|
|
Namespace: "default", |
|
|
|
|
}, |
|
|
|
|
Spec: v1.ServiceSpec{ |
|
|
|
|
Ports: []v1.ServicePort{ |
|
|
|
|
{ |
|
|
|
|
Name: "testport", |
|
|
|
|
Protocol: v1.ProtocolTCP, |
|
|
|
|
Port: int32(31900), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
Type: v1.ServiceTypeExternalName, |
|
|
|
|
ExternalName: "FooExternalName", |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestServiceDiscoveryAdd(t *testing.T) { |
|
|
|
|
n, c, w := makeDiscovery(RoleService, NamespaceDiscovery{}) |
|
|
|
|
|
|
|
|
@ -79,14 +103,18 @@ func TestServiceDiscoveryAdd(t *testing.T) {
|
|
|
|
|
obj := makeService() |
|
|
|
|
c.CoreV1().Services(obj.Namespace).Create(obj) |
|
|
|
|
w.Services().Add(obj) |
|
|
|
|
obj = makeExternalService() |
|
|
|
|
c.CoreV1().Services(obj.Namespace).Create(obj) |
|
|
|
|
w.Services().Add(obj) |
|
|
|
|
}, |
|
|
|
|
expectedMaxItems: 1, |
|
|
|
|
expectedMaxItems: 2, |
|
|
|
|
expectedRes: map[string]*targetgroup.Group{ |
|
|
|
|
"svc/default/testservice": { |
|
|
|
|
Targets: []model.LabelSet{ |
|
|
|
|
{ |
|
|
|
|
"__meta_kubernetes_service_port_protocol": "TCP", |
|
|
|
|
"__address__": "testservice.default.svc:30900", |
|
|
|
|
"__meta_kubernetes_service_cluster_ip": "10.0.0.1", |
|
|
|
|
"__meta_kubernetes_service_port_name": "testport", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
@ -96,6 +124,21 @@ func TestServiceDiscoveryAdd(t *testing.T) {
|
|
|
|
|
}, |
|
|
|
|
Source: "svc/default/testservice", |
|
|
|
|
}, |
|
|
|
|
"svc/default/testservice-external": { |
|
|
|
|
Targets: []model.LabelSet{ |
|
|
|
|
{ |
|
|
|
|
"__meta_kubernetes_service_port_protocol": "TCP", |
|
|
|
|
"__address__": "testservice-external.default.svc:31900", |
|
|
|
|
"__meta_kubernetes_service_port_name": "testport", |
|
|
|
|
"__meta_kubernetes_service_external_name": "FooExternalName", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
Labels: model.LabelSet{ |
|
|
|
|
"__meta_kubernetes_service_name": "testservice-external", |
|
|
|
|
"__meta_kubernetes_namespace": "default", |
|
|
|
|
}, |
|
|
|
|
Source: "svc/default/testservice-external", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}.Run(t) |
|
|
|
|
} |
|
|
|
@ -136,11 +179,13 @@ func TestServiceDiscoveryUpdate(t *testing.T) {
|
|
|
|
|
{ |
|
|
|
|
"__meta_kubernetes_service_port_protocol": "TCP", |
|
|
|
|
"__address__": "testservice.default.svc:30900", |
|
|
|
|
"__meta_kubernetes_service_cluster_ip": "10.0.0.1", |
|
|
|
|
"__meta_kubernetes_service_port_name": "testport0", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
"__meta_kubernetes_service_port_protocol": "UDP", |
|
|
|
|
"__address__": "testservice.default.svc:30901", |
|
|
|
|
"__meta_kubernetes_service_cluster_ip": "10.0.0.1", |
|
|
|
|
"__meta_kubernetes_service_port_name": "testport1", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
@ -176,6 +221,7 @@ func TestServiceDiscoveryNamespaces(t *testing.T) {
|
|
|
|
|
{ |
|
|
|
|
"__meta_kubernetes_service_port_protocol": "TCP", |
|
|
|
|
"__address__": "testservice.ns1.svc:30900", |
|
|
|
|
"__meta_kubernetes_service_cluster_ip": "10.0.0.1", |
|
|
|
|
"__meta_kubernetes_service_port_name": "testport", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
@ -190,6 +236,7 @@ func TestServiceDiscoveryNamespaces(t *testing.T) {
|
|
|
|
|
{ |
|
|
|
|
"__meta_kubernetes_service_port_protocol": "TCP", |
|
|
|
|
"__address__": "testservice.ns2.svc:30900", |
|
|
|
|
"__meta_kubernetes_service_cluster_ip": "10.0.0.1", |
|
|
|
|
"__meta_kubernetes_service_port_name": "testport", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|