Skip to content

Commit 703fe6f

Browse files
committed
dns: don't use IMDS region resolver when it previously failed
This should allow use to IMDS on EC2, but not when not running on EC2, for example when running `kops update cluster`.
1 parent b215294 commit 703fe6f

File tree

1 file changed

+10
-4
lines changed
  • dnsprovider/pkg/dnsprovider/providers/aws/route53

1 file changed

+10
-4
lines changed

dnsprovider/pkg/dnsprovider/providers/aws/route53/route53.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ func newRoute53() (*Interface, error) {
6767
imdsRegionResp, err := imdsClient.GetRegion(ctx, &imds.GetRegionInput{})
6868
if err != nil {
6969
klog.V(4).Infof("Unable to discover region by IMDS, using SDK defaults: %s", err)
70+
// Don't use imdsClient if it's erroring (we're probably not running on EC2 here, e.g. kops update)
71+
imdsClient = nil
7072
} else {
7173
region = imdsRegionResp.Region
7274
}
@@ -83,7 +85,7 @@ func newRoute53() (*Interface, error) {
8385
return nil, fmt.Errorf("failed to load default aws config for STS client: %w", err)
8486
}
8587

86-
cfg, err := awsconfig.LoadDefaultConfig(ctx,
88+
awsOptions := []func(*awsconfig.LoadOptions) error{
8789
awsconfig.WithClientLogMode(aws.LogRetries),
8890
awslog.WithAWSLogger(),
8991
awsconfig.WithRetryer(func() aws.Retryer {
@@ -93,11 +95,15 @@ func newRoute53() (*Interface, error) {
9395
// Ensure the STS client has a region configured, if discovered by IMDS
9496
aro.Client = sts.NewFromConfig(stsCfg)
9597
}),
96-
awsconfig.WithEC2IMDSRegion(func(o *awsconfig.UseEC2IMDSRegion) {
98+
}
99+
100+
if imdsClient != nil {
101+
awsOptions = append(awsOptions, awsconfig.WithEC2IMDSRegion(func(o *awsconfig.UseEC2IMDSRegion) {
97102
o.Client = imdsClient
98-
}),
99-
)
103+
}))
104+
}
100105

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

0 commit comments

Comments
 (0)