Skip to content

Commit 5e11a07

Browse files
authored
Use endpointResolver and add serviceEndpointsID to serviceController (#44)
Issue #, if available: aws-controllers-k8s/community#896 Description of changes: If `endpointURL` is not an empty string then we will use the `endpointresolver` and we will use this `endpointURL` when the service is equal to the `serviceEndpointID` which is retrieved from the service controller. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 934ba68 commit 5e11a07

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

pkg/runtime/service_controller.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type serviceController struct {
4747
// ServiceAPIGroup is a string with the full DNS-correct API group that
4848
// this service controller manages, e.g. "s3.services.k8s.aws"
4949
ServiceAPIGroup string
50+
// ServiceEndpointsID is a string with the service API's EndpointsID, e.g. "api.sagemaker"
51+
ServiceEndpointsID string
5052
// VersionInfo describes the service controller's built code
5153
VersionInfo VersionInfo
5254
// rmFactories is a map of resource manager factories, keyed by the
@@ -163,12 +165,14 @@ func (c *serviceController) BindControllerManager(mgr ctrlrt.Manager, cfg ackcfg
163165
func NewServiceController(
164166
svcAlias string,
165167
svcAPIGroup string,
168+
svcEndpointsID string,
166169
versionInfo VersionInfo,
167170
) acktypes.ServiceController {
168171
return &serviceController{
169-
ServiceAlias: svcAlias,
170-
ServiceAPIGroup: svcAPIGroup,
171-
VersionInfo: versionInfo,
172-
metrics: ackmetrics.NewMetrics(svcAlias),
172+
ServiceAlias: svcAlias,
173+
ServiceAPIGroup: svcAPIGroup,
174+
ServiceEndpointsID: svcEndpointsID,
175+
VersionInfo: versionInfo,
176+
metrics: ackmetrics.NewMetrics(svcAlias),
173177
}
174178
}

pkg/runtime/service_controller_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ func TestServiceController(t *testing.T) {
107107
BuildDate: "now",
108108
}
109109

110-
sc := ackrt.NewServiceController("bookstore", "bookstore.services.k8s.aws", vi)
110+
sc := ackrt.NewServiceController("bookstore", "bookstore.services.k8s.aws", "bookstore", vi)
111111
require.NotNil(sc)
112-
113112
zapOptions := ctrlrtzap.Options{
114113
Development: true,
115114
Level: zapcore.InfoLevel,

pkg/runtime/session.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,17 @@ func (c *serviceController) NewSession(
4242
Region: aws.String(string(region)),
4343
STSRegionalEndpoint: endpoints.RegionalSTSEndpoint,
4444
}
45-
if endpointURL != nil {
46-
awsCfg.Endpoint = endpointURL
45+
46+
if *endpointURL != "" {
47+
endpointServiceResolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
48+
if service == c.ServiceEndpointsID {
49+
return endpoints.ResolvedEndpoint{
50+
URL: *endpointURL,
51+
}, nil
52+
}
53+
return endpoints.DefaultResolver().EndpointFor(service, region)
54+
}
55+
awsCfg.EndpointResolver = endpoints.ResolverFunc(endpointServiceResolver)
4756
}
4857

4958
sess, err := session.NewSession(&awsCfg)

0 commit comments

Comments
 (0)