aggregation: add ExternalName service support

This commit is contained in:
Dr. Stefan Schimanski 2017-05-30 10:43:04 +02:00
parent b1f708758c
commit 8b409e8f77
2 changed files with 24 additions and 0 deletions

View File

@ -113,6 +113,14 @@ func ResolveCluster(services listersv1.ServiceLister, namespace, id string) (*ur
Scheme: "https",
Host: net.JoinHostPort(svc.Spec.ClusterIP, fmt.Sprintf("%d", svcPort.Port)),
}, nil
case svc.Spec.Type == v1.ServiceTypeExternalName:
if port.Type != intstr.Int {
return nil, fmt.Errorf("named ports not supported")
}
return &url.URL{
Scheme: "https",
Host: net.JoinHostPort(svc.Spec.ExternalName, port.String()),
}, nil
default:
return nil, fmt.Errorf("unsupported service type %q", svc.Spec.Type)
}

View File

@ -174,6 +174,22 @@ func TestResolve(t *testing.T) {
clusterMode: expectation{url: "https://np:443"},
endpointMode: expectation{url: "https://127.0.0.1:1443"},
},
{
name: "external name",
services: []*v1.Service{
{
ObjectMeta: metav1.ObjectMeta{Namespace: "one", Name: "alfa"},
Spec: v1.ServiceSpec{
Type: v1.ServiceTypeExternalName,
ExternalName: "foo.bar.com",
},
},
},
endpoints: nil,
clusterMode: expectation{url: "https://foo.bar.com:443"},
endpointMode: expectation{error: true},
},
{
name: "missing service",
services: nil,