Ensure port on resolved service host

This commit is contained in:
Jordan Liggitt 2017-10-20 23:01:11 -04:00
parent c27444fe99
commit d45f01e953
No known key found for this signature in database
GPG Key ID: 39928704103C7229
2 changed files with 8 additions and 7 deletions

View File

@ -32,11 +32,10 @@ var _ admissioninit.ServiceResolver = defaultServiceResolver{}
// ResolveEndpoint constructs a service URL from a given namespace and name
// note that the name and namespace are required and by default all created addresses use HTTPS scheme.
// for example:
// name=ross namespace=andromeda resolves to https://ross.andromeda.svc
// name=ross namespace=andromeda resolves to https://ross.andromeda.svc:443
func (sr defaultServiceResolver) ResolveEndpoint(namespace, name string) (*url.URL, error) {
if len(name) == 0 || len(namespace) == 0 {
return &url.URL{}, errors.New("cannot resolve an empty service name or namespace")
return nil, errors.New("cannot resolve an empty service name or namespace")
}
return url.Parse(fmt.Sprintf("https://%s.%s.svc", name, namespace))
return &url.URL{Scheme: "https", Host: fmt.Sprintf("%s.%s.svc:443", name, namespace)}, nil
}

View File

@ -30,7 +30,7 @@ func TestDefaultServiceResolver(t *testing.T) {
expectError bool
}{
// scenario 1: a service name along with a namespace resolves
{serviceName: "ross", serviceNamespace: "andromeda", expectedOutput: "https://ross.andromeda.svc"},
{serviceName: "ross", serviceNamespace: "andromeda", expectedOutput: "https://ross.andromeda.svc:443"},
// scenario 2: a service name without a namespace does not resolve
{serviceName: "ross", expectError: true},
// scenario 3: cannot resolve an empty service name
@ -49,8 +49,10 @@ func TestDefaultServiceResolver(t *testing.T) {
if err == nil && scenario.expectError {
t.Error("expected an error but got nothing")
}
if serviceURL.String() != scenario.expectedOutput {
t.Errorf("expected = %s, got = %s", scenario.expectedOutput, serviceURL.String())
if !scenario.expectError {
if serviceURL.String() != scenario.expectedOutput {
t.Errorf("expected = %s, got = %s", scenario.expectedOutput, serviceURL.String())
}
}
})
}