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

Automated cherry pick of #16778: dns: don't use IMDS region resolver when it previously failed #16781

Merged
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
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
Loading