Skip to content

Commit c524527

Browse files
Rebase on AWS SDK v2
Signed-off-by: Danil Grigorev <[email protected]>
1 parent a915858 commit c524527

File tree

10 files changed

+108
-34
lines changed

10 files changed

+108
-34
lines changed

config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,6 +3108,7 @@ spec:
31083108
to "default" namespace.
31093109
type: string
31103110
required:
3111+
- roleARN
31113112
- serviceAccountName
31123113
- serviceAccountNamespace
31133114
type: object

controlplane/eks/controllers/awsmanagedcontrolplane_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,10 +951,10 @@ func mockedEKSCluster(ctx context.Context, g *WithT, eksRec *mock_eksiface.MockE
951951
}).Return(&eks.ListAddonsOutput{}, nil)
952952

953953
eksRec.UpdateClusterConfig(ctx, gomock.AssignableToTypeOf(&eks.UpdateClusterConfigInput{})).After(waitUntilClusterActiveCall).Return(&eks.UpdateClusterConfigOutput{}, nil)
954-
eksRec.ListPodIdentityAssociationsWqithContext(context.TODO(), gomock.Eq(&eks.ListPodIdentityAssociationsInput{
954+
eksRec.ListPodIdentityAssociations(context.TODO(), gomock.Eq(&eks.ListPodIdentityAssociationsInput{
955955
ClusterName: aws.String("test-cluster"),
956956
})).Return(&eks.ListPodIdentityAssociationsOutput{
957-
Associations: []*eks.PodIdentityAssociationSummary{},
957+
Associations: []ekstypes.PodIdentityAssociationSummary{},
958958
}, nil)
959959

960960
awsNodeRec.ReconcileCNI(gomock.Any()).Return(nil)

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ require (
88
github.com/aws/amazon-vpc-cni-k8s v1.15.5
99
github.com/aws/aws-lambda-go v1.41.0
1010
github.com/aws/aws-sdk-go v1.55.7
11-
github.com/aws/aws-sdk-go-v2 v1.36.5
11+
github.com/aws/aws-sdk-go-v2 v1.36.6
1212
github.com/aws/aws-sdk-go-v2/config v1.27.11
1313
github.com/aws/aws-sdk-go-v2/credentials v1.17.11
1414
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.52.4
1515
github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0
16-
github.com/aws/aws-sdk-go-v2/service/eks v1.64.0
16+
github.com/aws/aws-sdk-go-v2/service/eks v1.66.2
1717
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.6
1818
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.45.2
1919
github.com/aws/aws-sdk-go-v2/service/iam v1.32.0
@@ -86,8 +86,8 @@ require (
8686
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
8787
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
8888
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect
89-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.36 // indirect
90-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.36 // indirect
89+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.37 // indirect
90+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.37 // indirect
9191
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
9292
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.36 // indirect
9393
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.50.0 // indirect

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ github.com/aws/aws-lambda-go v1.41.0 h1:l/5fyVb6Ud9uYd411xdHZzSf2n86TakxzpvIoz7l
4848
github.com/aws/aws-lambda-go v1.41.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM=
4949
github.com/aws/aws-sdk-go v1.55.7 h1:UJrkFq7es5CShfBwlWAC8DA077vp8PyVbQd3lqLiztE=
5050
github.com/aws/aws-sdk-go v1.55.7/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
51-
github.com/aws/aws-sdk-go-v2 v1.36.5 h1:0OF9RiEMEdDdZEMqF9MRjevyxAQcf6gY+E7vwBILFj0=
52-
github.com/aws/aws-sdk-go-v2 v1.36.5/go.mod h1:EYrzvCCN9CMUTa5+6lf6MM4tq3Zjp8UhSGR/cBsjai0=
51+
github.com/aws/aws-sdk-go-v2 v1.36.6 h1:zJqGjVbRdTPojeCGWn5IR5pbJwSQSBh5RWFTQcEQGdU=
52+
github.com/aws/aws-sdk-go-v2 v1.36.6/go.mod h1:EYrzvCCN9CMUTa5+6lf6MM4tq3Zjp8UhSGR/cBsjai0=
5353
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to=
5454
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2/go.mod h1:lPprDr1e6cJdyYeGXnRaJoP4Md+cDBvi2eOj00BlGmg=
5555
github.com/aws/aws-sdk-go-v2/config v1.27.11 h1:f47rANd2LQEYHda2ddSCKYId18/8BhSRM4BULGmfgNA=
@@ -58,10 +58,10 @@ github.com/aws/aws-sdk-go-v2/credentials v1.17.11 h1:YuIB1dJNf1Re822rriUOTxopaHH
5858
github.com/aws/aws-sdk-go-v2/credentials v1.17.11/go.mod h1:AQtFPsDH9bI2O+71anW6EKL+NcD7LG3dpKGMV4SShgo=
5959
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 h1:FVJ0r5XTHSmIHJV6KuDmdYhEpvlHpiSd38RQWhut5J4=
6060
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1/go.mod h1:zusuAeqezXzAB24LGuzuekqMAEgWkVYukBec3kr3jUg=
61-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.36 h1:SsytQyTMHMDPspp+spo7XwXTP44aJZZAC7fBV2C5+5s=
62-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.36/go.mod h1:Q1lnJArKRXkenyog6+Y+zr7WDpk4e6XlR6gs20bbeNo=
63-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.36 h1:i2vNHQiXUvKhs3quBR6aqlgJaiaexz/aNvdCktW/kAM=
64-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.36/go.mod h1:UdyGa7Q91id/sdyHPwth+043HhmP6yP9MBHgbZM0xo8=
61+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.37 h1:osMWfm/sC/L4tvEdQ65Gri5ZZDCUpuYJZbTTDrsn4I0=
62+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.37/go.mod h1:ZV2/1fbjOPr4G4v38G3Ww5TBT4+hmsK45s/rxu1fGy0=
63+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.37 h1:v+X21AvTb2wZ+ycg1gx+orkB/9U6L7AOp93R7qYxsxM=
64+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.37/go.mod h1:G0uM1kyssELxmJ2VZEfG0q2npObR3BAkF3c1VsfVnfs=
6565
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU=
6666
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY=
6767
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.36 h1:GMYy2EOWfzdP3wfVAGXBNKY5vK4K8vMET4sYOYltmqs=
@@ -72,8 +72,8 @@ github.com/aws/aws-sdk-go-v2/service/cloudformation v1.50.0 h1:Ap5tOJfeAH1hO2UQc
7272
github.com/aws/aws-sdk-go-v2/service/cloudformation v1.50.0/go.mod h1:/v2KYdCW4BaHKayenaWEXOOdxItIwEA3oU0XzuQY3F0=
7373
github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0 h1:DmmVmiLPlcntOcjWMRwDPMNx/wi2kAVrf2ZmSN5gkAg=
7474
github.com/aws/aws-sdk-go-v2/service/ec2 v1.159.0/go.mod h1:xejKuuRDjz6z5OqyeLsz01MlOqqW7CqpAB4PabNvpu8=
75-
github.com/aws/aws-sdk-go-v2/service/eks v1.64.0 h1:EYeOThTRysemFtC6J6h6b7dNg3jN03QuO5cg92ojIQE=
76-
github.com/aws/aws-sdk-go-v2/service/eks v1.64.0/go.mod h1:v1xXy6ea0PHtWkjFUvAUh6B/5wv7UF909Nru0dOIJDk=
75+
github.com/aws/aws-sdk-go-v2/service/eks v1.66.2 h1:gDvxe1rFYhU9sfA/S8TePGE7gfC0vB9pCs6B4zbm5Ng=
76+
github.com/aws/aws-sdk-go-v2/service/eks v1.66.2/go.mod h1:lpcShMkoQ94JiSVoEF1yE2WP40IV02bbnaT6oYP7cQo=
7777
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.6 h1:9grU/+HRwLXJV8XUjEPThJj/H+0oHkeNBFpSSfZekeg=
7878
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.29.6/go.mod h1:N4fs285CsnBHlAkzBpQapefR/noggTyF09fWs72EzB4=
7979
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.45.2 h1:vX70Z4lNSr7XsioU0uJq5yvxgI50sB66MvD+V/3buS4=

pkg/cloud/services/eks/mock_eksiface/eksapi_mock.go

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cloud/services/eks/pod_identity.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import (
2020
"context"
2121
"fmt"
2222

23-
"github.com/aws/aws-sdk-go/service/eks"
23+
"github.com/aws/aws-sdk-go-v2/service/eks"
24+
"github.com/aws/aws-sdk-go-v2/service/eks/types"
2425

2526
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
2627
ekspodidentities "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/eks/podidentities"
@@ -49,7 +50,7 @@ func (s *Service) reconcilePodIdentities(ctx context.Context) error {
4950
existingAssociations := s.translateAWSToPodAssociation(currentAssociations)
5051

5152
s.scope.Debug("creating eks pod identity association plan", "cluster", eksClusterName)
52-
podAssociationsPlan := ekspodidentities.NewPlan(eksClusterName, desiredAssociations, existingAssociations, s.EKSClient)
53+
podAssociationsPlan := ekspodidentities.NewPlan(eksClusterName, desiredAssociations, existingAssociations, s.EKSV2Client.Client)
5354
procedures, err := podAssociationsPlan.Create(ctx)
5455
if err != nil {
5556
s.scope.Error(err, "failed creating eks pod identity association plan")
@@ -69,14 +70,14 @@ func (s *Service) reconcilePodIdentities(ctx context.Context) error {
6970
return nil
7071
}
7172

72-
func (s *Service) listEksPodIdentities(ctx context.Context, eksClusterName string) ([]*eks.PodIdentityAssociationSummary, error) {
73+
func (s *Service) listEksPodIdentities(ctx context.Context, eksClusterName string) ([]types.PodIdentityAssociationSummary, error) {
7374
s.Debug("getting list of associated eks pod identities")
7475

7576
input := &eks.ListPodIdentityAssociationsInput{
7677
ClusterName: &eksClusterName,
7778
}
7879

79-
output, err := s.EKSClient.ListPodIdentityAssociationsWithContext(ctx, input)
80+
output, err := s.EKSClient.ListPodIdentityAssociations(ctx, input)
8081
if err != nil {
8182
return nil, fmt.Errorf("listing eks pod identity assocations: %w", err)
8283
}
@@ -101,7 +102,7 @@ func (s *Service) translateAPIToPodAssociation(assocs []ekscontrolplanev1.PodIde
101102
return converted
102103
}
103104

104-
func (s *Service) translateAWSToPodAssociation(assocs []*eks.PodIdentityAssociationSummary) []ekspodidentities.EKSPodIdentityAssociation {
105+
func (s *Service) translateAWSToPodAssociation(assocs []types.PodIdentityAssociationSummary) []ekspodidentities.EKSPodIdentityAssociation {
105106
converted := []ekspodidentities.EKSPodIdentityAssociation{}
106107

107108
for _, assoc := range assocs {

pkg/cloud/services/eks/service.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ type EKSAPI interface {
6262
TagResource(ctx context.Context, params *eks.TagResourceInput, optFns ...func(*eks.Options)) (*eks.TagResourceOutput, error)
6363
UntagResource(ctx context.Context, params *eks.UntagResourceInput, optFns ...func(*eks.Options)) (*eks.UntagResourceOutput, error)
6464
DisassociateIdentityProviderConfig(ctx context.Context, params *eks.DisassociateIdentityProviderConfigInput, optFns ...func(*eks.Options)) (*eks.DisassociateIdentityProviderConfigOutput, error)
65+
CreatePodIdentityAssociation(ctx context.Context, params *eks.CreatePodIdentityAssociationInput, optFns ...func(*eks.Options)) (*eks.CreatePodIdentityAssociationOutput, error)
66+
ListPodIdentityAssociations(ctx context.Context, params *eks.ListPodIdentityAssociationsInput, optFns ...func(*eks.Options)) (*eks.ListPodIdentityAssociationsOutput, error)
67+
DeletePodIdentityAssociation(ctx context.Context, params *eks.DeletePodIdentityAssociationInput, optFns ...func(*eks.Options)) (*eks.DeletePodIdentityAssociationOutput, error)
6568

6669
// Waiters for EKS Cluster
6770
WaitUntilClusterActive(ctx context.Context, params *eks.DescribeClusterInput, maxWait time.Duration) error
@@ -89,7 +92,8 @@ type Service struct {
8992
EC2Client ec2iface.EC2API
9093
EKSClient EKSAPI
9194
iam.IAMService
92-
STSClient stsiface.STSAPI
95+
STSClient stsiface.STSAPI
96+
EKSV2Client *EKSClient
9397
}
9498

9599
// ServiceOpts defines the functional arguments for the service.
@@ -110,6 +114,9 @@ func NewService(controlPlaneScope *scope.ManagedControlPlaneScope, opts ...Servi
110114
EKSClient: &EKSClient{
111115
Client: scope.NewEKSClient(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
112116
},
117+
EKSV2Client: &EKSClient{
118+
Client: scope.NewEKSClient(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
119+
},
113120
IAMService: iam.IAMService{
114121
Wrapper: &controlPlaneScope.Logger,
115122
IAMClient: scope.NewIAMClient(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),

pkg/eks/podidentities/plan.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ package podidentities
2020
import (
2121
"context"
2222

23-
"github.com/aws/aws-sdk-go/service/eks/eksiface"
23+
"github.com/aws/aws-sdk-go-v2/service/eks"
2424

2525
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/planner"
2626
)
2727

28+
// EKSAPI defines the EKS API interface.
29+
type EKSAPI interface {
30+
CreatePodIdentityAssociation(ctx context.Context, params *eks.CreatePodIdentityAssociationInput, optFns ...func(*eks.Options)) (*eks.CreatePodIdentityAssociationOutput, error)
31+
DeletePodIdentityAssociation(ctx context.Context, params *eks.DeletePodIdentityAssociationInput, optFns ...func(*eks.Options)) (*eks.DeletePodIdentityAssociationOutput, error)
32+
}
33+
2834
// NewPlan creates a new Plan to manage EKS pod identities.
29-
func NewPlan(clusterName string, desiredAssociations, currentAssociations []EKSPodIdentityAssociation, client eksiface.EKSAPI) planner.Plan {
35+
func NewPlan(clusterName string, desiredAssociations, currentAssociations []EKSPodIdentityAssociation, client EKSAPI) planner.Plan {
3036
return &plan{
3137
currentAssociations: currentAssociations,
3238
desiredAssociations: desiredAssociations,
@@ -39,7 +45,7 @@ func NewPlan(clusterName string, desiredAssociations, currentAssociations []EKSP
3945
type plan struct {
4046
currentAssociations []EKSPodIdentityAssociation
4147
desiredAssociations []EKSPodIdentityAssociation
42-
eksClient eksiface.EKSAPI
48+
eksClient EKSAPI
4349
clusterName string
4450
}
4551

pkg/eks/podidentities/plan_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestEKSPodIdentityAssociationsPlan(t *testing.T) {
5858
name: "no current and 1 desired",
5959
expect: func(m *mock_eksiface.MockEKSAPIMockRecorder) {
6060
m.
61-
CreatePodIdentityAssociation(gomock.Eq(&eks.CreatePodIdentityAssociationInput{
61+
CreatePodIdentityAssociation(gomock.Any(), gomock.Eq(&eks.CreatePodIdentityAssociationInput{
6262
Namespace: aws.String(namespace),
6363
RoleArn: aws.String(roleArn),
6464
ServiceAccount: aws.String(serviceAccount),
@@ -112,7 +112,7 @@ func TestEKSPodIdentityAssociationsPlan(t *testing.T) {
112112
name: "1 current and 0 desired",
113113
expect: func(m *mock_eksiface.MockEKSAPIMockRecorder) {
114114
m.
115-
DeletePodIdentityAssociation(gomock.Eq(&eks.DeletePodIdentityAssociationInput{
115+
DeletePodIdentityAssociation(gomock.Any(), gomock.Eq(&eks.DeletePodIdentityAssociationInput{
116116
AssociationId: aws.String(associationID),
117117
ClusterName: aws.String(clusterName),
118118
})).

pkg/eks/podidentities/procedures.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,28 @@ import (
2121
"errors"
2222
"fmt"
2323

24-
"github.com/aws/aws-sdk-go/aws"
25-
"github.com/aws/aws-sdk-go/service/eks"
26-
"github.com/aws/aws-sdk-go/service/eks/eksiface"
24+
"github.com/aws/aws-sdk-go-v2/aws"
25+
"github.com/aws/aws-sdk-go-v2/service/eks"
2726
)
2827

2928
// errPodIdentityAssociationNotFound defines an error for when an eks pod identity is not found.
3029
var errPodIdentityAssociationNotFound = errors.New("eks pod identity association not found")
3130

3231
// DeletePodIdentityAssociationProcedure is a procedure that will delete an EKS eks pod identity.
3332
type DeletePodIdentityAssociationProcedure struct {
34-
eksClient eksiface.EKSAPI
33+
eksClient EKSAPI
3534
clusterName string
3635
existingAssociationID string
3736
}
3837

3938
// Do implements the logic for the procedure.
40-
func (p *DeletePodIdentityAssociationProcedure) Do(_ context.Context) error {
39+
func (p *DeletePodIdentityAssociationProcedure) Do(ctx context.Context) error {
4140
input := &eks.DeletePodIdentityAssociationInput{
4241
AssociationId: aws.String(p.existingAssociationID),
4342
ClusterName: aws.String(p.clusterName),
4443
}
4544

46-
if _, err := p.eksClient.DeletePodIdentityAssociation(input); err != nil {
45+
if _, err := p.eksClient.DeletePodIdentityAssociation(ctx, input); err != nil {
4746
return fmt.Errorf("deleting eks pod identity %s: %w", p.existingAssociationID, err)
4847
}
4948

@@ -57,13 +56,13 @@ func (p *DeletePodIdentityAssociationProcedure) Name() string {
5756

5857
// CreatePodIdentityAssociationProcedure is a procedure that will create an EKS eks pod identity for a cluster.
5958
type CreatePodIdentityAssociationProcedure struct {
60-
eksClient eksiface.EKSAPI
59+
eksClient EKSAPI
6160
clusterName string
6261
newAssociation *EKSPodIdentityAssociation
6362
}
6463

6564
// Do implements the logic for the procedure.
66-
func (p *CreatePodIdentityAssociationProcedure) Do(_ context.Context) error {
65+
func (p *CreatePodIdentityAssociationProcedure) Do(ctx context.Context) error {
6766
if p.newAssociation == nil {
6867
return fmt.Errorf("getting desired eks pod identity for cluster %s: %w", p.clusterName, errPodIdentityAssociationNotFound)
6968
}
@@ -75,7 +74,7 @@ func (p *CreatePodIdentityAssociationProcedure) Do(_ context.Context) error {
7574
ServiceAccount: &p.newAssociation.ServiceAccountName,
7675
}
7776

78-
_, err := p.eksClient.CreatePodIdentityAssociation(input)
77+
_, err := p.eksClient.CreatePodIdentityAssociation(ctx, input)
7978
if err != nil {
8079
return fmt.Errorf("creating desired eks pod identity for cluster %s: %w", p.clusterName, err)
8180
}

0 commit comments

Comments
 (0)