mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 15:58:37 +00:00
Merge pull request #54333 from liggitt/webhook-service-resolver
Automatic merge from submit-queue (batch tested with PRs 54363, 54333). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Ensure port on resolved service host The resolved host should include a port so it can be used by dialers directly. It's also not necessary to reparse the URL when constructing directly. ```release-note NONE ```
This commit is contained in:
commit
fd3878a59d
@ -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,8 +49,10 @@ 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 serviceURL.String() != scenario.expectedOutput {
|
if !scenario.expectError {
|
||||||
t.Errorf("expected = %s, got = %s", scenario.expectedOutput, serviceURL.String())
|
if serviceURL.String() != scenario.expectedOutput {
|
||||||
|
t.Errorf("expected = %s, got = %s", scenario.expectedOutput, serviceURL.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user