mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
Ensure port on resolved service host
This commit is contained in:
parent
c27444fe99
commit
d45f01e953
@ -32,11 +32,10 @@ var _ admissioninit.ServiceResolver = defaultServiceResolver{}
|
|||||||
// ResolveEndpoint constructs a service URL from a given namespace and name
|
// 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.
|
// note that the name and namespace are required and by default all created addresses use HTTPS scheme.
|
||||||
// for example:
|
// 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) {
|
func (sr defaultServiceResolver) ResolveEndpoint(namespace, name string) (*url.URL, error) {
|
||||||
if len(name) == 0 || len(namespace) == 0 {
|
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.URL{Scheme: "https", Host: fmt.Sprintf("%s.%s.svc:443", name, namespace)}, nil
|
||||||
return url.Parse(fmt.Sprintf("https://%s.%s.svc", name, namespace))
|
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ func TestDefaultServiceResolver(t *testing.T) {
|
|||||||
expectError bool
|
expectError bool
|
||||||
}{
|
}{
|
||||||
// scenario 1: a service name along with a namespace resolves
|
// 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
|
// scenario 2: a service name without a namespace does not resolve
|
||||||
{serviceName: "ross", expectError: true},
|
{serviceName: "ross", expectError: true},
|
||||||
// scenario 3: cannot resolve an empty service name
|
// scenario 3: cannot resolve an empty service name
|
||||||
@ -49,9 +49,11 @@ func TestDefaultServiceResolver(t *testing.T) {
|
|||||||
if err == nil && scenario.expectError {
|
if err == nil && scenario.expectError {
|
||||||
t.Error("expected an error but got nothing")
|
t.Error("expected an error but got nothing")
|
||||||
}
|
}
|
||||||
|
if !scenario.expectError {
|
||||||
if serviceURL.String() != scenario.expectedOutput {
|
if serviceURL.String() != scenario.expectedOutput {
|
||||||
t.Errorf("expected = %s, got = %s", scenario.expectedOutput, serviceURL.String())
|
t.Errorf("expected = %s, got = %s", scenario.expectedOutput, serviceURL.String())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user