Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add support for env var keys from AWS SDK #8231

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/eks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ func newAWSProvider(spec *api.ProviderConfig, configurationLoader AWSConfigurati
provider.asg = autoscaling.NewFromConfig(cfg)
provider.cloudwatchlogs = cloudwatchlogs.NewFromConfig(cfg)
provider.cloudtrail = cloudtrail.NewFromConfig(cfg, func(o *cloudtrail.Options) {
o.BaseEndpoint = getBaseEndpoint(cloudtrail.ServiceID, "AWS_CLOUDTRAIL_ENDPOINT")
o.BaseEndpoint = getBaseEndpoint(cloudtrail.ServiceID, []string{
"AWS_CLOUDTRAIL_ENDPOINT",
"AWS_ENDPOINT_URL_CLOUDTRAIL",
"AWS_ENDPOINT_URL",
})
})

return provider, nil
Expand Down
53 changes: 41 additions & 12 deletions pkg/eks/services_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ func (s *ServicesV2) STS() awsapi.STS {
defer s.mu.Unlock()
if s.sts == nil {
s.sts = sts.NewFromConfig(s.config, func(o *sts.Options) {
o.BaseEndpoint = getBaseEndpoint(sts.ServiceID, "AWS_STS_ENDPOINT")
o.BaseEndpoint = getBaseEndpoint(sts.ServiceID, []string{
"AWS_STS_ENDPOINT",
"AWS_ENDPOINT_URL_STS",
"AWS_ENDPOINT_URL",
})
// Disable retryer for STS
// (see https://github.com/eksctl-io/eksctl/issues/705)
o.Retryer = aws.NopRetryer{}
Expand Down Expand Up @@ -79,7 +83,11 @@ func (s *ServicesV2) CloudFormation() awsapi.CloudFormation {
defer s.mu.Unlock()
if s.cloudformation == nil {
s.cloudformation = cloudformation.NewFromConfig(s.config, func(o *cloudformation.Options) {
o.BaseEndpoint = getBaseEndpoint(cloudformation.ServiceID, "AWS_CLOUDFORMATION_ENDPOINT")
o.BaseEndpoint = getBaseEndpoint(cloudformation.ServiceID, []string{
"AWS_CLOUDFORMATION_ENDPOINT",
"AWS_ENDPOINT_URL_CLOUDFORMATION",
"AWS_ENDPOINT_URL",
})
// Use adaptive mode for retrying CloudFormation requests to mimic
// the logic used for AWS SDK v1.
o.Retryer = retry.NewAdaptiveMode(func(o *retry.AdaptiveModeOptions) {
Expand All @@ -101,7 +109,11 @@ func (s *ServicesV2) ELB() awsapi.ELB {
defer s.mu.Unlock()
if s.elasticloadbalancing == nil {
s.elasticloadbalancing = elasticloadbalancing.NewFromConfig(s.config, func(o *elasticloadbalancing.Options) {
o.BaseEndpoint = getBaseEndpoint(elasticloadbalancing.ServiceID, "AWS_ELB_ENDPOINT")
o.BaseEndpoint = getBaseEndpoint(elasticloadbalancing.ServiceID, []string{
"AWS_ELB_ENDPOINT",
"AWS_ENDPOINT_URL_ELASTIC_LOAD_BALANCING",
"AWS_ENDPOINT_URL",
})
})
}
return s.elasticloadbalancing
Expand All @@ -113,7 +125,11 @@ func (s *ServicesV2) ELBV2() awsapi.ELBV2 {
defer s.mu.Unlock()
if s.elasticloadbalancingV2 == nil {
s.elasticloadbalancingV2 = elasticloadbalancingv2.NewFromConfig(s.config, func(o *elasticloadbalancingv2.Options) {
o.BaseEndpoint = getBaseEndpoint(elasticloadbalancingv2.ServiceID, "AWS_ELBV2_ENDPOINT")
o.BaseEndpoint = getBaseEndpoint(elasticloadbalancingv2.ServiceID, []string{
"AWS_ELBV2_ENDPOINT",
"AWS_ENDPOINT_URL_ELASTIC_LOAD_BALANCING_V2",
"AWS_ENDPOINT_URL",
})
})
}
return s.elasticloadbalancingV2
Expand All @@ -135,7 +151,11 @@ func (s *ServicesV2) IAM() awsapi.IAM {
defer s.mu.Unlock()
if s.iam == nil {
s.iam = iam.NewFromConfig(s.config, func(o *iam.Options) {
o.BaseEndpoint = getBaseEndpoint(iam.ServiceID, "AWS_IAM_ENDPOINT")
o.BaseEndpoint = getBaseEndpoint(iam.ServiceID, []string{
"AWS_IAM_ENDPOINT",
"AWS_ENDPOINT_URL_IAM",
"AWS_ENDPOINT_URL",
})
})
}
return s.iam
Expand All @@ -147,7 +167,11 @@ func (s *ServicesV2) EC2() awsapi.EC2 {
defer s.mu.Unlock()
if s.ec2 == nil {
s.ec2 = ec2.NewFromConfig(s.config, func(o *ec2.Options) {
o.BaseEndpoint = getBaseEndpoint(ec2.ServiceID, "AWS_EC2_ENDPOINT")
o.BaseEndpoint = getBaseEndpoint(ec2.ServiceID, []string{
"AWS_EC2_ENDPOINT",
"AWS_ENDPOINT_URL_EC2",
"AWS_ENDPOINT_URL",
})
})
}
return s.ec2
Expand All @@ -159,7 +183,11 @@ func (s *ServicesV2) EKS() awsapi.EKS {
defer s.mu.Unlock()
if s.eks == nil {
s.eks = eks.NewFromConfig(s.config, func(o *eks.Options) {
o.BaseEndpoint = getBaseEndpoint(eks.ServiceID, "AWS_EKS_ENDPOINT")
o.BaseEndpoint = getBaseEndpoint(eks.ServiceID, []string{
"AWS_EKS_ENDPOINT",
"AWS_ENDPOINT_URL_EC2",
"AWS_ENDPOINT_URL",
})
})
}
return s.eks
Expand All @@ -183,11 +211,12 @@ func (s *ServicesV2) CredentialsProvider() aws.CredentialsProvider {
return s.config.Credentials
}

func getBaseEndpoint(serviceID, endpoint string) *string {
if endpoint, ok := os.LookupEnv(endpoint); ok {
logger.Debug(
"Setting %s endpoint to %s", serviceID, endpoint)
return aws.String(endpoint)
func getBaseEndpoint(serviceID string, endpoints []string) *string {
for _, endpoint := range endpoints {
if value, ok := os.LookupEnv(endpoint); ok {
logger.Debug("Setting %s endpoint to %s", serviceID, value)
return aws.String(value)
}
}
return nil
}
Loading