Skip to content

Commit 2c3e130

Browse files
authored
Migrate AWS SDK for Go to v2 (#943)
* chore(deps): Migrate go.mod from AWS SDK v1 to v2 Replace aws-sdk-go v1.55.6 with aws-sdk-go-v2 and individual service modules. Update both root and test/ module dependencies. Key dependency changes: - Remove github.com/aws/aws-sdk-go v1.55.6 - Add github.com/aws/aws-sdk-go-v2 v1.41.5 - Add github.com/aws/aws-sdk-go-v2/config v1.32.14 - Add github.com/aws/aws-sdk-go-v2/service/vpclattice v1.20.11 - Add github.com/aws/aws-sdk-go-v2/service/acm v1.38.1 - Add github.com/aws/smithy-go v1.24.3 - Add additional v2 service modules for integration tests * refactor: Migrate production code from AWS SDK v1 to v2 Migrate all production code in pkg/ from aws-sdk-go v1 to aws-sdk-go-v2. This is the core of the SDK migration. Import convention follows idiomatic v2 patterns: - vpclattice: service package (Input/Output types) - types: types subpackage (model types, enums) - apitypes: k8s apimachinery types (where conflict exists) Key changes across all files: - Replace v1 session-based clients with v2 config-based clients - Replace *string fields with string for SDK model types - Replace []*Type slices with []Type value slices - Replace *int64 with *int32 for port/count fields - Replace map[string]*string tags with map[string]string - Replace WithContext method calls with context-first signatures - Replace awserr error handling with smithy-go error types - Replace string constants with typed enums - Replace v1 Matcher/RuleAction structs with v2 union interfaces - Remove unused gwlogAdapter and getMapValue dead code - Fix printf format for struct pointer (%s -> %v) * chore: Regenerate mocks for v2 SDK interfaces Regenerate all gomock files via go generate to match updated interface signatures using AWS SDK v2 types. * test: Migrate unit tests from AWS SDK v1 to v2 Update all pkg/ unit tests to use v2 SDK types, matching the production code migration. Changes mirror the production code patterns: value types in slices, typed enums, *int32 ports, map[string]string tags, and v2 union interfaces for Matcher and RuleAction. * test: Migrate integration tests from AWS SDK v1 to v2 Update all test/ integration tests and framework to use v2 SDK. Key changes: - Replace session.NewSession() with config.LoadDefaultConfig() - Replace service.New(sess) with service.NewFromConfig(cfg) - Migrate all AWS service clients (VPC Lattice, EC2, ACM, S3, IAM, STS, Route53, CloudWatch Logs, Firehose, RAM) - Update HealthCheckConfig assertions for v2 types (*int32, typed enums, MatcherMemberHttpCode union interface) - Update EC2 DescribeVpcs VpcIds from []*string to []string * fixes * fixes * address comments, fix flaky tests * fix: Restore shortened comments, remove test retry override - Restore multi-line comments in drift_detection_test.go that were accidentally shortened during rebase - Remove RetryMaxAttempts=10 override in ram_share_test.go to match v1 behavior (SDK default of 3 attempts) - Add Serial to VpcAssociationPolicy drift test to prevent interference - Fix flaky drift test: wait for associations to be ACTIVE before delete - Increase association deletion timeout from 2min to 4min * address review comments * add more retries for ram share test * Disable aws sdk built-in rate limiter * fix flaky service drift detection test
1 parent 6e1bd94 commit 2c3e130

114 files changed

Lines changed: 4574 additions & 6707 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

go.mod

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ module github.com/aws/aws-application-networking-k8s
33
go 1.26.0
44

55
require (
6-
github.com/aws/aws-sdk-go v1.55.6
6+
github.com/aws/aws-sdk-go-v2 v1.41.6
7+
github.com/aws/aws-sdk-go-v2/config v1.28.6
8+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21
9+
github.com/aws/aws-sdk-go-v2/service/acm v1.38.2
10+
github.com/aws/aws-sdk-go-v2/service/ec2 v1.298.0
11+
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.31.11
12+
github.com/aws/aws-sdk-go-v2/service/vpclattice v1.20.12
13+
github.com/aws/smithy-go v1.25.0
714
github.com/go-logr/zapr v1.3.0
815
github.com/google/uuid v1.6.0
916
github.com/hashicorp/golang-lru/v2 v2.0.7
@@ -25,6 +32,15 @@ require (
2532
)
2633

2734
require (
35+
github.com/aws/aws-sdk-go-v2/credentials v1.17.47 // indirect
36+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.22 // indirect
37+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.22 // indirect
38+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
39+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.8 // indirect
40+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.22 // indirect
41+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.7 // indirect
42+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6 // indirect
43+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2 // indirect
2844
github.com/beorn7/perks v1.0.1 // indirect
2945
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3046
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
@@ -51,7 +67,6 @@ require (
5167
github.com/google/btree v1.1.3 // indirect
5268
github.com/google/gnostic-models v0.7.0 // indirect
5369
github.com/google/go-cmp v0.7.0 // indirect
54-
github.com/jmespath/go-jmespath v0.4.0 // indirect
5570
github.com/josharian/intern v1.0.0 // indirect
5671
github.com/json-iterator/go v1.1.12 // indirect
5772
github.com/mailru/easyjson v0.9.1 // indirect

go.sum

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
11
github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc=
22
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
33
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
4-
github.com/aws/aws-sdk-go v1.55.6 h1:cSg4pvZ3m8dgYcgqB97MrcdjUmZ1BeMYKUxMMB89IPk=
5-
github.com/aws/aws-sdk-go v1.55.6/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
4+
github.com/aws/aws-sdk-go-v2 v1.41.6 h1:1AX0AthnBQzMx1vbmir3Y4WsnJgiydmnJjiLu+LvXOg=
5+
github.com/aws/aws-sdk-go-v2 v1.41.6/go.mod h1:dy0UzBIfwSeot4grGvY1AqFWN5zgziMmWGzysDnHFcQ=
6+
github.com/aws/aws-sdk-go-v2/config v1.28.6 h1:D89IKtGrs/I3QXOLNTH93NJYtDhm8SYa9Q5CsPShmyo=
7+
github.com/aws/aws-sdk-go-v2/config v1.28.6/go.mod h1:GDzxJ5wyyFSCoLkS+UhGB0dArhb9mI+Co4dHtoTxbko=
8+
github.com/aws/aws-sdk-go-v2/credentials v1.17.47 h1:48bA+3/fCdi2yAwVt+3COvmatZ6jUDNkDTIsqDiMUdw=
9+
github.com/aws/aws-sdk-go-v2/credentials v1.17.47/go.mod h1:+KdckOejLW3Ks3b0E3b5rHsr2f9yuORBum0WPnE5o5w=
10+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21 h1:AmoU1pziydclFT/xRV+xXE/Vb8fttJCLRPv8oAkprc0=
11+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21/go.mod h1:AjUdLYe4Tgs6kpH4Bv7uMZo7pottoyHMn4eTcIcneaY=
12+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.22 h1:GmLa5Kw1ESqtFpXsx5MmC84QWa/ZrLZvlJGa2y+4kcQ=
13+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.22/go.mod h1:6sW9iWm9DK9YRpRGga/qzrzNLgKpT2cIxb7Vo2eNOp0=
14+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.22 h1:dY4kWZiSaXIzxnKlj17nHnBcXXBfac6UlsAx2qL6XrU=
15+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.22/go.mod h1:KIpEUx0JuRZLO7U6cbV204cWAEco2iC3l061IxlwLtI=
16+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ=
17+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc=
18+
github.com/aws/aws-sdk-go-v2/service/acm v1.38.2 h1:ozcwethaFOi2ST9h6MKGq1GAIHP68tjiDqgkWVPwfR8=
19+
github.com/aws/aws-sdk-go-v2/service/acm v1.38.2/go.mod h1:HNtDOv4XmqExPxNIBp171KKc5ZoUJwHH9ZhlCcZmdt0=
20+
github.com/aws/aws-sdk-go-v2/service/ec2 v1.298.0 h1:PP4/BDTcOWR9Sr64K3atzu2738pmNLiFzJ70lxS3Yno=
21+
github.com/aws/aws-sdk-go-v2/service/ec2 v1.298.0/go.mod h1:E1pnYwWFZ8N3REmeN9Fe/Zipbpps4HJj8DQGNnLUMYc=
22+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.8 h1:HtOTYcbVcGABLOVuPYaIihj6IlkqubBwFj10K5fxRek=
23+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.8/go.mod h1:VsK9abqQeGlzPgUr+isNWzPlK2vKe9INMLWnY65f5Xs=
24+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.22 h1:PUmZeJU6Y1Lbvt9WFuJ0ugUK2xn6hIWUBBbKuOWF30s=
25+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.22/go.mod h1:nO6egFBoAaoXze24a2C0NjQCvdpk8OueRoYimvEB9jo=
26+
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.31.11 h1:H+rP6r3xvF72rcATLBm+XAdjjxL+v5g+ka/gjJBvPao=
27+
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.31.11/go.mod h1:1orx2HYtb6hJEmD1o/OID8vWD5sBKxB8RH+0XS25rYo=
28+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.7 h1:rLnYAfXQ3YAccocshIH5mzNNwZBkBo+bP6EhIxak6Hw=
29+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.7/go.mod h1:ZHtuQJ6t9A/+YDuxOLnbryAmITtr8UysSny3qcyvJTc=
30+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6 h1:JnhTZR3PiYDNKlXy50/pNeix9aGMo6lLpXwJ1mw8MD4=
31+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6/go.mod h1:URronUEGfXZN1VpdktPSD1EkAL9mfrV+2F4sjH38qOY=
32+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2 h1:s4074ZO1Hk8qv65GqNXqDjmkf4HSQqJukaLuuW0TpDA=
33+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2/go.mod h1:mVggCnIWoM09jP71Wh+ea7+5gAp53q+49wDFs1SW5z8=
34+
github.com/aws/aws-sdk-go-v2/service/vpclattice v1.20.12 h1:Lu9L/Jy3AxHqMO3GtJp61gYPj8gT03oPk4kfHurGAKY=
35+
github.com/aws/aws-sdk-go-v2/service/vpclattice v1.20.12/go.mod h1:besmPK9H+eqFdoUqfIS6rlJ184HkKL/Cu6wrU5Np2Ow=
36+
github.com/aws/smithy-go v1.25.0 h1:Sz/XJ64rwuiKtB6j98nDIPyYrV1nVNJ4YU74gttcl5U=
37+
github.com/aws/smithy-go v1.25.0/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
638
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
739
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
840
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
@@ -87,10 +119,6 @@ github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
87119
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
88120
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
89121
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
90-
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
91-
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
92-
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
93-
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
94122
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
95123
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
96124
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
@@ -247,10 +275,7 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
247275
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
248276
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
249277
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
250-
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
251278
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
252-
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
253-
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
254279
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
255280
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
256281
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/aws/cloud.go

Lines changed: 67 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ package aws
33
import (
44
"context"
55
"fmt"
6-
7-
"github.com/prometheus/client_golang/prometheus"
8-
96
"maps"
107

11-
"github.com/aws/aws-sdk-go/aws/request"
12-
"github.com/aws/aws-sdk-go/aws/session"
13-
"github.com/aws/aws-sdk-go/service/vpclattice"
8+
"github.com/aws/aws-sdk-go-v2/aws"
9+
awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
10+
"github.com/aws/aws-sdk-go-v2/aws/ratelimit"
11+
"github.com/aws/aws-sdk-go-v2/aws/retry"
12+
awsconfig "github.com/aws/aws-sdk-go-v2/config"
13+
"github.com/aws/aws-sdk-go-v2/service/vpclattice"
14+
"github.com/aws/smithy-go/middleware"
15+
"github.com/prometheus/client_golang/prometheus"
1416

1517
"github.com/aws/aws-application-networking-k8s/pkg/aws/metrics"
1618
"github.com/aws/aws-application-networking-k8s/pkg/aws/services"
@@ -20,6 +22,8 @@ import (
2022
const (
2123
TagBase = "application-networking.k8s.aws/"
2224
TagManagedBy = TagBase + "ManagedBy"
25+
26+
userAgent = "amazon-vpc-lattice-gateway-api-controller"
2327
)
2428

2529
//go:generate mockgen -destination cloud_mocks.go -package aws github.com/aws/aws-application-networking-k8s/pkg/aws Cloud
@@ -61,48 +65,45 @@ type Cloud interface {
6165

6266
// NewCloud constructs new Cloud implementation.
6367
func NewCloud(log gwlog.Logger, cfg CloudConfig, metricsRegisterer prometheus.Registerer) (Cloud, error) {
64-
sess, err := session.NewSession()
68+
awsCfg, err := awsconfig.LoadDefaultConfig(context.TODO(),
69+
awsconfig.WithRegion(cfg.Region),
70+
awsconfig.WithRetryer(func() aws.Retryer {
71+
return retry.NewStandard(func(o *retry.StandardOptions) {
72+
o.RateLimiter = ratelimit.None
73+
})
74+
}),
75+
)
6576
if err != nil {
6677
return nil, err
6778
}
6879

69-
addUserAgentHandler(sess)
70-
71-
sess.Handlers.Complete.PushFront(func(r *request.Request) {
72-
if r.Error != nil {
73-
log.Debugw(context.TODO(), "error",
74-
"error", r.Error.Error(),
75-
"serviceName", r.ClientInfo.ServiceName,
76-
"operation", r.Operation.Name,
77-
"params", r.Params,
78-
)
79-
} else {
80-
log.Debugw(context.TODO(), "response",
81-
"serviceName", r.ClientInfo.ServiceName,
82-
"operation", r.Operation.Name,
83-
"params", r.Params,
84-
)
85-
}
80+
// Add user agent to all API calls
81+
awsCfg.APIOptions = append(awsCfg.APIOptions, awsmiddleware.AddUserAgentKeyValue(userAgent, ""))
82+
83+
// Add logging middleware
84+
awsCfg.APIOptions = append(awsCfg.APIOptions, func(stack *middleware.Stack) error {
85+
return stack.Initialize.Add(&loggingMiddleware{log: log}, middleware.After)
8686
})
8787

88+
// Add metrics middleware
8889
if metricsRegisterer != nil {
8990
metricsCollector, err := metrics.NewCollector(metricsRegisterer)
9091
if err != nil {
9192
return nil, err
9293
}
93-
metricsCollector.InjectHandlers(&sess.Handlers)
94+
awsCfg.APIOptions = append(awsCfg.APIOptions, metricsCollector.APIOptions()...)
9495
}
9596

96-
lattice := services.NewDefaultLattice(sess, cfg.AccountId, cfg.Region)
97+
lattice := services.NewDefaultLattice(awsCfg, cfg.AccountId, cfg.Region)
9798
var tagging services.Tagging
9899

99100
if cfg.TaggingServiceAPIDisabled {
100-
tagging = services.NewLatticeTagging(sess, cfg.AccountId, cfg.Region, cfg.VpcId)
101+
tagging = services.NewLatticeTagging(awsCfg, cfg.AccountId, cfg.Region, cfg.VpcId)
101102
} else {
102-
tagging = services.NewDefaultTagging(sess, cfg.Region)
103+
tagging = services.NewDefaultTagging(awsCfg)
103104
}
104105

105-
acmClient := services.NewDefaultACM(sess, cfg.Region)
106+
acmClient := services.NewDefaultACM(awsCfg)
106107

107108
return &defaultCloud{
108109
cfg: cfg,
@@ -156,9 +157,9 @@ func (c *defaultCloud) Config() CloudConfig {
156157
}
157158

158159
func (c *defaultCloud) DefaultTags() services.Tags {
159-
tags := services.Tags{}
160-
tags[TagManagedBy] = &c.managedByTag
161-
return tags
160+
return services.Tags{
161+
TagManagedBy: c.managedByTag,
162+
}
162163
}
163164

164165
func (c *defaultCloud) DefaultTagsMergedWith(tags services.Tags) services.Tags {
@@ -179,8 +180,7 @@ func (c *defaultCloud) MergeTags(baseTags services.Tags, additionalTags services
179180
}
180181

181182
func (c *defaultCloud) getTags(ctx context.Context, arn string) (services.Tags, error) {
182-
tagsReq := &vpclattice.ListTagsForResourceInput{ResourceArn: &arn}
183-
resp, err := c.lattice.ListTagsForResourceWithContext(ctx, tagsReq)
183+
resp, err := c.lattice.ListTagsForResource(ctx, &vpclattice.ListTagsForResourceInput{ResourceArn: &arn})
184184
if err != nil {
185185
return nil, err
186186
}
@@ -189,10 +189,10 @@ func (c *defaultCloud) getTags(ctx context.Context, arn string) (services.Tags,
189189

190190
func (c *defaultCloud) GetManagedByFromTags(tags services.Tags) string {
191191
tag, ok := tags[TagManagedBy]
192-
if !ok || tag == nil {
192+
if !ok {
193193
return ""
194194
}
195-
return *tag
195+
return tag
196196
}
197197

198198
func (c *defaultCloud) IsArnManaged(ctx context.Context, arn string) (bool, error) {
@@ -226,7 +226,7 @@ func (c *defaultCloud) TryOwnFromTags(ctx context.Context, arn string, tags serv
226226
}
227227

228228
func (c *defaultCloud) ownResource(ctx context.Context, arn string) error {
229-
_, err := c.Lattice().TagResourceWithContext(ctx, &vpclattice.TagResourceInput{
229+
_, err := c.Lattice().TagResource(ctx, &vpclattice.TagResourceInput{
230230
ResourceArn: &arn,
231231
Tags: c.DefaultTags(),
232232
})
@@ -241,7 +241,34 @@ func getManagedByTag(cfg CloudConfig) string {
241241
return fmt.Sprintf("%s/%s/%s", cfg.AccountId, cfg.ClusterName, cfg.VpcId)
242242
}
243243

244-
// addUserAgentHandler appends the controller identifier to the User-Agent header on all AWS API calls.
245-
func addUserAgentHandler(sess *session.Session) {
246-
sess.Handlers.Build.PushBack(request.MakeAddToUserAgentFreeFormHandler("amazon-vpc-lattice-gateway-api-controller"))
244+
// loggingMiddleware logs API call results
245+
type loggingMiddleware struct {
246+
log gwlog.Logger
247+
}
248+
249+
func (m *loggingMiddleware) ID() string { return "ControllerLogging" }
250+
251+
func (m *loggingMiddleware) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
252+
out middleware.InitializeOutput, metadata middleware.Metadata, err error,
253+
) {
254+
out, metadata, err = next.HandleInitialize(ctx, in)
255+
256+
service := middleware.GetServiceID(ctx)
257+
operation := middleware.GetOperationName(ctx)
258+
259+
if err != nil {
260+
m.log.Debugw(ctx, "error",
261+
"error", err.Error(),
262+
"serviceName", service,
263+
"operation", operation,
264+
"params", in.Parameters,
265+
)
266+
} else {
267+
m.log.Debugw(ctx, "response",
268+
"serviceName", service,
269+
"operation", operation,
270+
"params", in.Parameters,
271+
)
272+
}
273+
return out, metadata, err
247274
}

0 commit comments

Comments
 (0)