Skip to content

Commit

Permalink
Merge pull request kubernetes#16781 from rifelpet/automated-cherry-pi…
Browse files Browse the repository at this point in the history
…ck-of-#16778-origin-release-1.30

Automated cherry pick of kubernetes#16778: dns: don't use IMDS region resolver when it previously failed
  • Loading branch information
k8s-ci-robot authored Aug 28, 2024
2 parents 2b6ce45 + 86fa71a commit afd6aad
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions dnsprovider/pkg/dnsprovider/providers/aws/route53/route53.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func newRoute53() (*Interface, error) {
imdsRegionResp, err := imdsClient.GetRegion(ctx, &imds.GetRegionInput{})
if err != nil {
klog.V(4).Infof("Unable to discover region by IMDS, using SDK defaults: %s", err)
// Don't use imdsClient if it's erroring (we're probably not running on EC2 here, e.g. kops update)
imdsClient = nil
} else {
region = imdsRegionResp.Region
}
Expand All @@ -83,7 +85,7 @@ func newRoute53() (*Interface, error) {
return nil, fmt.Errorf("failed to load default aws config for STS client: %w", err)
}

cfg, err := awsconfig.LoadDefaultConfig(ctx,
awsOptions := []func(*awsconfig.LoadOptions) error{
awsconfig.WithClientLogMode(aws.LogRetries),
awslog.WithAWSLogger(),
awsconfig.WithRetryer(func() aws.Retryer {
Expand All @@ -93,11 +95,15 @@ func newRoute53() (*Interface, error) {
// Ensure the STS client has a region configured, if discovered by IMDS
aro.Client = sts.NewFromConfig(stsCfg)
}),
awsconfig.WithEC2IMDSRegion(func(o *awsconfig.UseEC2IMDSRegion) {
}

if imdsClient != nil {
awsOptions = append(awsOptions, awsconfig.WithEC2IMDSRegion(func(o *awsconfig.UseEC2IMDSRegion) {
o.Client = imdsClient
}),
)
}))
}

cfg, err := awsconfig.LoadDefaultConfig(ctx, awsOptions...)
if err != nil {
return nil, fmt.Errorf("failed to load default aws config: %w", err)
}
Expand Down

0 comments on commit afd6aad

Please sign in to comment.