88
99 awsv2 "github.com/aws/aws-sdk-go-v2/aws"
1010 "github.com/aws/aws-sdk-go-v2/aws/arn"
11- "github.com/aws/aws-sdk-go-v2/aws/middleware"
11+ awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
1212 configv2 "github.com/aws/aws-sdk-go-v2/config"
1313 "github.com/aws/aws-sdk-go-v2/credentials/stscreds"
1414 ec2v2 "github.com/aws/aws-sdk-go-v2/service/ec2"
@@ -23,6 +23,7 @@ import (
2323 "github.com/aws/aws-sdk-go-v2/service/s3"
2424 s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
2525 "github.com/aws/aws-sdk-go-v2/service/sts"
26+ "github.com/aws/smithy-go/middleware"
2627 "github.com/pkg/errors"
2728 "github.com/sirupsen/logrus"
2829 utilerrors "k8s.io/apimachinery/pkg/util/errors"
@@ -87,6 +88,9 @@ const (
8788 endpointISOBEast1 = "us-isob-east-1"
8889 endpointUSGovEast1 = "us-gov-east-1"
8990 endpointUSGovWest1 = "us-gov-west-1"
91+
92+ // OpenShiftInstallerDestroyerUserAgent is the User Agent key to add to the AWS Destroy API request header.
93+ OpenShiftInstallerDestroyerUserAgent = "OpenShift/4.x Destroyer"
9094)
9195
9296// New returns an AWS destroyer from ClusterMetadata.
@@ -101,49 +105,58 @@ func New(logger logrus.FieldLogger, metadata *types.ClusterMetadata) (providers.
101105 ec2Client , err := awssession .NewEC2Client (ctx , awssession.EndpointOptions {
102106 Region : region ,
103107 Endpoints : metadata .AWS .ServiceEndpoints ,
104- })
108+ }, ec2v2 . WithAPIOptions ( awsmiddleware . AddUserAgentKeyValue ( OpenShiftInstallerDestroyerUserAgent , version . Raw )) )
105109 if err != nil {
106110 return nil , fmt .Errorf ("failed to create EC2 client: %w" , err )
107111 }
108112
109113 iamClient , err := awssession .NewIAMClient (ctx , awssession.EndpointOptions {
110114 Region : region ,
111115 Endpoints : metadata .AWS .ServiceEndpoints ,
112- })
116+ }, iamv2 . WithAPIOptions ( awsmiddleware . AddUserAgentKeyValue ( OpenShiftInstallerDestroyerUserAgent , version . Raw )) )
113117 if err != nil {
114118 return nil , fmt .Errorf ("failed to create IAM client: %w" , err )
115119 }
116120
117121 // FIXME: remove this code when the elb and elbv2 clients are "fixed" or figured out
118- elbCfg , err := awssession .GetConfigWithOptions (ctx , configv2 .WithRegion (region ))
122+ elbCfg , err := awssession .GetConfigWithOptions (ctx , configv2 .WithRegion (region ),
123+ configv2 .WithAPIOptions ([]func (* middleware.Stack ) error {
124+ awsmiddleware .AddUserAgentKeyValue (OpenShiftInstallerDestroyerUserAgent , version .Raw ),
125+ }))
119126 if err != nil {
120127 return nil , fmt .Errorf ("failed to create AWS config for elb client: %w" , err )
121128 }
122129 elbclient := elb .NewFromConfig (elbCfg , func (options * elb.Options ) {
123130 options .Region = region
124131 for _ , endpoint := range metadata .AWS .ServiceEndpoints {
125- if strings .EqualFold (endpoint .Name , "elb" ) {
132+ if strings .EqualFold (endpoint .Name , "elb" ) || strings . EqualFold ( endpoint . Name , "elasticloadbalancing" ) {
126133 options .BaseEndpoint = awsv2 .String (endpoint .URL )
127134 }
128135 }
129136 })
130137
131138 // FIXME: remove this code when the elb and elbv2 clients are "fixed" or figured out
132- elbv2Cfg , err := awssession .GetConfigWithOptions (ctx , configv2 .WithRegion (region ))
139+ elbv2Cfg , err := awssession .GetConfigWithOptions (ctx , configv2 .WithRegion (region ),
140+ configv2 .WithAPIOptions ([]func (* middleware.Stack ) error {
141+ awsmiddleware .AddUserAgentKeyValue (OpenShiftInstallerDestroyerUserAgent , version .Raw ),
142+ }))
133143 if err != nil {
134144 return nil , fmt .Errorf ("failed to create AWS config for elbv2 client: %w" , err )
135145 }
136146 elbv2client := elbv2 .NewFromConfig (elbv2Cfg , func (options * elbv2.Options ) {
137147 options .Region = region
138148 for _ , endpoint := range metadata .AWS .ServiceEndpoints {
139- if strings .EqualFold (endpoint .Name , "elbv2" ) {
149+ if strings .EqualFold (endpoint .Name , "elbv2" ) || strings . EqualFold ( endpoint . Name , "elasticloadbalancingv2" ) {
140150 options .BaseEndpoint = awsv2 .String (endpoint .URL )
141151 }
142152 }
143153 })
144154
145155 // FIXME: remove this code when the s3client is made
146- s3Cfg , err := awssession .GetConfigWithOptions (ctx , configv2 .WithRegion (region ))
156+ s3Cfg , err := awssession .GetConfigWithOptions (ctx , configv2 .WithRegion (region ),
157+ configv2 .WithAPIOptions ([]func (* middleware.Stack ) error {
158+ awsmiddleware .AddUserAgentKeyValue (OpenShiftInstallerDestroyerUserAgent , version .Raw ),
159+ }))
147160 if err != nil {
148161 return nil , fmt .Errorf ("failed to create AWS config for S3 client: %w" , err )
149162 }
@@ -157,14 +170,17 @@ func New(logger logrus.FieldLogger, metadata *types.ClusterMetadata) (providers.
157170 })
158171
159172 // FIXME: remove this code when the EFS client is made
160- efsCfg , err := awssession .GetConfigWithOptions (ctx , configv2 .WithRegion (region ))
173+ efsCfg , err := awssession .GetConfigWithOptions (ctx , configv2 .WithRegion (region ),
174+ configv2 .WithAPIOptions ([]func (* middleware.Stack ) error {
175+ awsmiddleware .AddUserAgentKeyValue (OpenShiftInstallerDestroyerUserAgent , version .Raw ),
176+ }))
161177 if err != nil {
162178 return nil , fmt .Errorf ("failed to create AWS config for EFS client: %w" , err )
163179 }
164180 efsClient := efs .NewFromConfig (efsCfg , func (options * efs.Options ) {
165181 options .Region = region
166182 for _ , endpoint := range metadata .AWS .ServiceEndpoints {
167- if strings .EqualFold (endpoint .Name , "efs " ) {
183+ if strings .EqualFold (endpoint .Name , "elasticfilesystem " ) {
168184 options .BaseEndpoint = awsv2 .String (endpoint .URL )
169185 }
170186 }
@@ -173,7 +189,7 @@ func New(logger logrus.FieldLogger, metadata *types.ClusterMetadata) (providers.
173189 route53Client , err := awssession .NewRoute53Client (ctx , awssession.EndpointOptions {
174190 Region : region ,
175191 Endpoints : metadata .AWS .ServiceEndpoints ,
176- }, "" ) // FIXME: Do we need an ARN here?
192+ }, "" , route53 . WithAPIOptions ( awsmiddleware . AddUserAgentKeyValue ( OpenShiftInstallerDestroyerUserAgent , version . Raw )))
177193 if err != nil {
178194 return nil , fmt .Errorf ("failed to create Route53 client: %w" , err )
179195 }
@@ -213,15 +229,18 @@ func createResourceTaggingClientWithConfig(cfg awsv2.Config, region string, endp
213229 return resourcegroupstaggingapi .NewFromConfig (cfg , func (options * resourcegroupstaggingapi.Options ) {
214230 options .Region = region
215231 for _ , endpoint := range endpoints {
216- if strings .EqualFold (endpoint .Name , "resourcegroupstaggingapi " ) {
232+ if strings .EqualFold (endpoint .Name , "tagging " ) {
217233 options .BaseEndpoint = awsv2 .String (endpoint .URL )
218234 }
219235 }
220236 })
221237}
222238
223239func createResourceTaggingClient (region string , endpoints []awstypes.ServiceEndpoint ) (* resourcegroupstaggingapi.Client , error ) {
224- cfg , err := awssession .GetConfigWithOptions (context .Background (), configv2 .WithRegion (region ))
240+ cfg , err := awssession .GetConfigWithOptions (context .Background (), configv2 .WithRegion (region ),
241+ configv2 .WithAPIOptions ([]func (* middleware.Stack ) error {
242+ awsmiddleware .AddUserAgentKeyValue (OpenShiftInstallerDestroyerUserAgent , version .Raw ),
243+ }))
225244 if err != nil {
226245 return nil , fmt .Errorf ("failed to create AWS config for resource tagging client: %w" , err )
227246 }
@@ -250,7 +269,7 @@ func (o *ClusterUninstaller) RunWithContext(ctx context.Context) ([]string, erro
250269 stsSvc , err := awssession .NewSTSClient (ctx , awssession.EndpointOptions {
251270 Region : endpointUSEast1 ,
252271 Endpoints : o .endpoints ,
253- }, sts .WithAPIOptions (middleware .AddUserAgentKeyValue ("OpenShift/4.x Destroyer" , version .Raw )))
272+ }, sts .WithAPIOptions (awsmiddleware .AddUserAgentKeyValue (OpenShiftInstallerDestroyerUserAgent , version .Raw )))
254273 if err != nil {
255274 return nil , fmt .Errorf ("failed to create STS client: %w" , err )
256275 }
@@ -691,7 +710,7 @@ func deleteRoute53(ctx context.Context, client *route53.Client, arn arn.ARN, log
691710 for paginator .HasMorePages () {
692711 page , err := paginator .NextPage (ctx )
693712 if err != nil {
694- return fmt .Errorf ("listing record sets for public zone: %w" , err )
713+ return fmt .Errorf ("listing record sets for public zone %s : %w" , publicZoneID , err )
695714 }
696715 for _ , recordSet := range page .ResourceRecordSets {
697716 key := recordSetKey (recordSet )
@@ -707,7 +726,7 @@ func deleteRoute53(ctx context.Context, client *route53.Client, arn arn.ARN, log
707726 for paginator .HasMorePages () {
708727 page , err := paginator .NextPage (ctx )
709728 if err != nil {
710- return fmt .Errorf ("listing record sets: %w" , err )
729+ return fmt .Errorf ("listing record sets for zone %s : %w" , id , err )
711730 }
712731
713732 for _ , recordSet := range page .ResourceRecordSets {
0 commit comments