@@ -4,17 +4,21 @@ package aws
4
4
import (
5
5
"context"
6
6
"fmt"
7
-
8
- "github.com/aws/aws-sdk-go/aws"
9
- "github.com/aws/aws-sdk-go/service/ec2"
10
- "github.com/aws/aws-sdk-go/service/iam"
11
- "github.com/aws/aws-sdk-go/service/route53"
7
+ "strings"
8
+
9
+ "github.com/aws/aws-sdk-go-v2/aws"
10
+ configv2 "github.com/aws/aws-sdk-go-v2/config"
11
+ "github.com/aws/aws-sdk-go-v2/service/ec2"
12
+ ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
13
+ "github.com/aws/aws-sdk-go-v2/service/iam"
14
+ iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
15
+ "github.com/aws/aws-sdk-go-v2/service/route53"
16
+ r53types "github.com/aws/aws-sdk-go-v2/service/route53/types"
12
17
"github.com/pkg/errors"
13
18
"github.com/sirupsen/logrus"
14
19
"k8s.io/apimachinery/pkg/util/sets"
15
20
16
21
"github.com/openshift/installer/pkg/asset/installconfig"
17
- awsic "github.com/openshift/installer/pkg/asset/installconfig/aws"
18
22
"github.com/openshift/installer/pkg/types"
19
23
awstypes "github.com/openshift/installer/pkg/types/aws"
20
24
)
@@ -68,39 +72,54 @@ func tagSharedVPCResources(ctx context.Context, clusterID string, installConfig
68
72
return err
69
73
}
70
74
71
- ids := make ([]* string , 0 , len (privateSubnets )+ len (publicSubnets )+ len (edgeSubnets ))
75
+ ids := make ([]string , 0 , len (privateSubnets )+ len (publicSubnets )+ len (edgeSubnets ))
72
76
for id := range privateSubnets {
73
- ids = append (ids , aws . String ( id ) )
77
+ ids = append (ids , id )
74
78
}
75
79
for id := range publicSubnets {
76
- ids = append (ids , aws . String ( id ) )
80
+ ids = append (ids , id )
77
81
}
78
82
for id := range edgeSubnets {
79
- ids = append (ids , aws . String ( id ) )
83
+ ids = append (ids , id )
80
84
}
81
85
82
- session , err := installConfig .AWS .Session (ctx )
86
+ tagKey , tagValue := sharedTag (clusterID )
87
+
88
+ cfg , err := configv2 .LoadDefaultConfig (context .TODO (), configv2 .WithRegion (installConfig .Config .Platform .AWS .Region ))
83
89
if err != nil {
84
- return errors . Wrap ( err , "could not create AWS session" )
90
+ return fmt . Errorf ( "failed loading default config: %w" , err )
85
91
}
86
92
87
- tagKey , tagValue := sharedTag (clusterID )
93
+ ec2Client := ec2 .NewFromConfig (cfg , func (options * ec2.Options ) {
94
+ options .Region = installConfig .Config .Platform .AWS .Region
95
+ for _ , endpoint := range installConfig .Config .AWS .ServiceEndpoints {
96
+ if strings .EqualFold (endpoint .Name , "ec2" ) {
97
+ options .BaseEndpoint = aws .String (endpoint .URL )
98
+ }
99
+ }
100
+ })
88
101
89
- ec2Client := ec2 .New (session , aws .NewConfig ().WithRegion (installConfig .Config .Platform .AWS .Region ))
90
- if _ , err = ec2Client .CreateTagsWithContext (ctx , & ec2.CreateTagsInput {
102
+ if _ , err = ec2Client .CreateTags (ctx , & ec2.CreateTagsInput {
91
103
Resources : ids ,
92
- Tags : []* ec2 .Tag {{Key : & tagKey , Value : & tagValue }},
104
+ Tags : []ec2types .Tag {{Key : & tagKey , Value : & tagValue }},
93
105
}); err != nil {
94
106
return errors .Wrap (err , "could not add tags to subnets" )
95
107
}
96
108
97
109
if zone := installConfig .Config .AWS .HostedZone ; zone != "" {
98
- r53cfg := awsic .GetR53ClientCfg (session , installConfig .Config .AWS .HostedZoneRole )
99
- route53Client := route53 .New (session , r53cfg )
100
- if _ , err := route53Client .ChangeTagsForResourceWithContext (ctx , & route53.ChangeTagsForResourceInput {
101
- ResourceType : aws .String ("hostedzone" ),
110
+ route53Client := route53 .NewFromConfig (cfg , func (options * route53.Options ) {
111
+ options .Region = installConfig .Config .Platform .AWS .Region
112
+ for _ , endpoint := range installConfig .Config .AWS .ServiceEndpoints {
113
+ if strings .EqualFold (endpoint .Name , "route53" ) {
114
+ options .BaseEndpoint = aws .String (endpoint .URL )
115
+ }
116
+ }
117
+ })
118
+
119
+ if _ , err := route53Client .ChangeTagsForResource (ctx , & route53.ChangeTagsForResourceInput {
120
+ ResourceType : r53types .TagResourceTypeHostedzone ,
102
121
ResourceId : aws .String (zone ),
103
- AddTags : []* route53 .Tag {{Key : & tagKey , Value : & tagValue }},
122
+ AddTags : []r53types .Tag {{Key : & tagKey , Value : & tagValue }},
104
123
}); err != nil {
105
124
return errors .Wrap (err , "could not add tags to hosted zone" )
106
125
}
@@ -145,18 +164,26 @@ func tagSharedIAMRoles(ctx context.Context, clusterID string, installConfig *ins
145
164
146
165
logrus .Debugf ("Tagging shared instance roles: %v" , sets .List (iamRoles ))
147
166
148
- session , err := installConfig .AWS .Session (ctx )
167
+ tagKey , tagValue := sharedTag (clusterID )
168
+
169
+ cfg , err := configv2 .LoadDefaultConfig (context .TODO (), configv2 .WithRegion (installConfig .Config .Platform .AWS .Region ))
149
170
if err != nil {
150
- return fmt .Errorf ("could not create AWS session : %w" , err )
171
+ return fmt .Errorf ("failed loading default config : %w" , err )
151
172
}
152
173
153
- tagKey , tagValue := sharedTag (clusterID )
174
+ iamClient := iam .NewFromConfig (cfg , func (options * iam.Options ) {
175
+ options .Region = installConfig .Config .Platform .AWS .Region
176
+ for _ , endpoint := range installConfig .Config .AWS .ServiceEndpoints {
177
+ if strings .EqualFold (endpoint .Name , "iam" ) {
178
+ options .BaseEndpoint = aws .String (endpoint .URL )
179
+ }
180
+ }
181
+ })
154
182
155
- iamClient := iam .New (session , aws .NewConfig ().WithRegion (installConfig .Config .Platform .AWS .Region ))
156
183
for role := range iamRoles {
157
- if _ , err := iamClient .TagRoleWithContext (ctx , & iam.TagRoleInput {
184
+ if _ , err := iamClient .TagRole (ctx , & iam.TagRoleInput {
158
185
RoleName : aws .String (role ),
159
- Tags : []* iam .Tag {
186
+ Tags : []iamtypes .Tag {
160
187
{Key : aws .String (tagKey ), Value : aws .String (tagValue )},
161
188
},
162
189
}); err != nil {
@@ -207,17 +234,25 @@ func tagSharedIAMProfiles(ctx context.Context, clusterID string, installConfig *
207
234
208
235
logrus .Debugf ("Tagging shared instance profiles: %v" , sets .List (iamProfileNames ))
209
236
210
- session , err := installConfig .AWS .Session ( ctx )
237
+ cfg , err := configv2 . LoadDefaultConfig ( context . TODO (), configv2 . WithRegion ( installConfig .Config . Platform . AWS .Region ) )
211
238
if err != nil {
212
- return errors . Wrap ( err , "could not create AWS session" )
239
+ return fmt . Errorf ( "failed loading default config: %w" , err )
213
240
}
214
- iamClient := iam .New (session , aws .NewConfig ().WithRegion (installConfig .Config .AWS .Region ))
241
+
242
+ iamClient := iam .NewFromConfig (cfg , func (options * iam.Options ) {
243
+ options .Region = installConfig .Config .Platform .AWS .Region
244
+ for _ , endpoint := range installConfig .Config .AWS .ServiceEndpoints {
245
+ if strings .EqualFold (endpoint .Name , "iam" ) {
246
+ options .BaseEndpoint = aws .String (endpoint .URL )
247
+ }
248
+ }
249
+ })
215
250
216
251
tagKey , tagValue := sharedTag (clusterID )
217
252
for name := range iamProfileNames {
218
- if _ , err := iamClient .TagInstanceProfileWithContext (ctx , & iam.TagInstanceProfileInput {
253
+ if _ , err := iamClient .TagInstanceProfile (ctx , & iam.TagInstanceProfileInput {
219
254
InstanceProfileName : aws .String (name ),
220
- Tags : []* iam .Tag {
255
+ Tags : []iamtypes .Tag {
221
256
{Key : aws .String (tagKey ), Value : aws .String (tagValue )},
222
257
},
223
258
}); err != nil {
0 commit comments