Skip to content

Commit

Permalink
Use endpointResolver and add serviceEndpointsID to serviceController (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
ryansteakley authored Aug 13, 2021
1 parent 934ba68 commit 5e11a07
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
12 changes: 8 additions & 4 deletions pkg/runtime/service_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type serviceController struct {
// ServiceAPIGroup is a string with the full DNS-correct API group that
// this service controller manages, e.g. "s3.services.k8s.aws"
ServiceAPIGroup string
// ServiceEndpointsID is a string with the service API's EndpointsID, e.g. "api.sagemaker"
ServiceEndpointsID string
// VersionInfo describes the service controller's built code
VersionInfo VersionInfo
// rmFactories is a map of resource manager factories, keyed by the
Expand Down Expand Up @@ -163,12 +165,14 @@ func (c *serviceController) BindControllerManager(mgr ctrlrt.Manager, cfg ackcfg
func NewServiceController(
svcAlias string,
svcAPIGroup string,
svcEndpointsID string,
versionInfo VersionInfo,
) acktypes.ServiceController {
return &serviceController{
ServiceAlias: svcAlias,
ServiceAPIGroup: svcAPIGroup,
VersionInfo: versionInfo,
metrics: ackmetrics.NewMetrics(svcAlias),
ServiceAlias: svcAlias,
ServiceAPIGroup: svcAPIGroup,
ServiceEndpointsID: svcEndpointsID,
VersionInfo: versionInfo,
metrics: ackmetrics.NewMetrics(svcAlias),
}
}
3 changes: 1 addition & 2 deletions pkg/runtime/service_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ func TestServiceController(t *testing.T) {
BuildDate: "now",
}

sc := ackrt.NewServiceController("bookstore", "bookstore.services.k8s.aws", vi)
sc := ackrt.NewServiceController("bookstore", "bookstore.services.k8s.aws", "bookstore", vi)
require.NotNil(sc)

zapOptions := ctrlrtzap.Options{
Development: true,
Level: zapcore.InfoLevel,
Expand Down
13 changes: 11 additions & 2 deletions pkg/runtime/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ func (c *serviceController) NewSession(
Region: aws.String(string(region)),
STSRegionalEndpoint: endpoints.RegionalSTSEndpoint,
}
if endpointURL != nil {
awsCfg.Endpoint = endpointURL

if *endpointURL != "" {
endpointServiceResolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
if service == c.ServiceEndpointsID {
return endpoints.ResolvedEndpoint{
URL: *endpointURL,
}, nil
}
return endpoints.DefaultResolver().EndpointFor(service, region)
}
awsCfg.EndpointResolver = endpoints.ResolverFunc(endpointServiceResolver)
}

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

0 comments on commit 5e11a07

Please sign in to comment.