Skip to content

Commit

Permalink
Re-add support for env var keys from AWS SDK (#8231)
Browse files Browse the repository at this point in the history
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
  • Loading branch information
dims authored Feb 20, 2025
1 parent 0ece616 commit f3eca40
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
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
}

0 comments on commit f3eca40

Please sign in to comment.