Skip to content

Commit 091c1fd

Browse files
Merge pull request #7 from nmvk/endpoint
Allow optional endpoint argument
2 parents cbda0df + 54658e8 commit 091c1fd

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

pkg/config/config.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package config
1515

1616
import (
1717
"errors"
18+
"net/url"
1819

1920
flag "github.com/spf13/pflag"
2021
"go.uber.org/zap/zapcore"
@@ -29,6 +30,7 @@ const (
2930
flagEnableDevLogging = "enable-development-logging"
3031
flagAWSAccountID = "aws-account-id"
3132
flagAWSRegion = "aws-region"
33+
flagAWSEndpointURL = "aws-endpoint-url"
3234
flagLogLevel = "log-level"
3335
flagResourceTags = "resource-tags"
3436
)
@@ -41,6 +43,7 @@ type Config struct {
4143
EnableDevelopmentLogging bool
4244
AccountID string
4345
Region string
46+
EndpointURL string
4447
LogLevel string
4548
ResourceTags []string
4649
}
@@ -79,6 +82,13 @@ func (cfg *Config) BindFlags() {
7982
"",
8083
"The AWS Region in which the service controller will create its resources",
8184
)
85+
flag.StringVar(
86+
&cfg.EndpointURL, flagAWSEndpointURL,
87+
"",
88+
"The AWS endpoint URL the service controller will use to create its resources. This is an optional" +
89+
" flag that can be used to override the default behaviour of aws-sdk-go that constructs endpoint URLs" +
90+
" automatically based on service and region",
91+
)
8292
flag.StringVar(
8393
&cfg.LogLevel, flagLogLevel,
8494
"info",
@@ -117,5 +127,13 @@ func (cfg *Config) Validate() error {
117127
if cfg.Region == "" {
118128
return errors.New("unable to start service controller as AWS region is nil. Please pass --aws-region flag")
119129
}
130+
131+
if cfg.EndpointURL != "" {
132+
endpoint, err := url.Parse(cfg.EndpointURL)
133+
if err != nil || endpoint.Scheme != "https" && endpoint.Host != "" {
134+
return errors.New("invalid service endpoint. Please refer to " +
135+
"https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html for more details")
136+
}
137+
}
120138
return nil
121139
}

pkg/runtime/reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (r *reconciler) reconcile(req ctrlrt.Request) error {
143143
region := r.getRegion(res)
144144
roleARN := r.getRoleARN(acctID)
145145
sess, err := r.sc.newSession(
146-
region, roleARN,
146+
region, &r.cfg.EndpointURL, roleARN,
147147
res.RuntimeObject().GetObjectKind().GroupVersionKind(),
148148
)
149149
if err != nil {

pkg/runtime/session.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ const appName = "aws-controller-k8s"
3434
// the session.
3535
func (c *ServiceController) newSession(
3636
region ackv1alpha1.AWSRegion,
37+
endpointURL *string,
3738
assumeRoleARN ackv1alpha1.AWSResourceName,
3839
groupVersionKind schema.GroupVersionKind,
3940
) (*session.Session, error) {
4041
awsCfg := aws.Config{
4142
Region: aws.String(string(region)),
4243
STSRegionalEndpoint: endpoints.RegionalSTSEndpoint,
4344
}
45+
if endpointURL != nil {
46+
awsCfg.Endpoint = endpointURL
47+
}
48+
4449
sess, err := session.NewSession(&awsCfg)
4550
if err != nil {
4651
return nil, err

0 commit comments

Comments
 (0)