Skip to content

Commit adf901f

Browse files
Danil-Grigorevk0da
authored andcommitted
Rebase on AWS SDK v2
Signed-off-by: Danil Grigorev <[email protected]>
1 parent b9e8a4c commit adf901f

File tree

8 files changed

+95
-24
lines changed

8 files changed

+95
-24
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
@@ -3141,6 +3141,7 @@ spec:
31413141
to "default" namespace.
31423142
type: string
31433143
required:
3144+
- roleARN
31443145
- serviceAccountName
31453146
- serviceAccountNamespace
31463147
type: object

controlplane/eks/controllers/awsmanagedcontrolplane_controller_test.go

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

972972
eksRec.UpdateClusterConfig(ctx, gomock.AssignableToTypeOf(&eks.UpdateClusterConfigInput{})).After(waitUntilClusterActiveCall).Return(&eks.UpdateClusterConfigOutput{}, nil)
973-
eksRec.ListPodIdentityAssociationsWqithContext(context.TODO(), gomock.Eq(&eks.ListPodIdentityAssociationsInput{
973+
eksRec.ListPodIdentityAssociations(context.TODO(), gomock.Eq(&eks.ListPodIdentityAssociationsInput{
974974
ClusterName: aws.String("test-cluster"),
975975
})).Return(&eks.ListPodIdentityAssociationsOutput{
976-
Associations: []*eks.PodIdentityAssociationSummary{},
976+
Associations: []ekstypes.PodIdentityAssociationSummary{},
977977
}, nil)
978978

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

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: 5 additions & 4 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"
@@ -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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/common"
3030
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/eks/iam"
3131
stsservice "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/sts"
32+
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/eks/podidentities"
3233
)
3334

3435
// EKSAPI defines the EKS API interface.
@@ -62,6 +63,8 @@ type EKSAPI interface {
6263
TagResource(ctx context.Context, params *eks.TagResourceInput, optFns ...func(*eks.Options)) (*eks.TagResourceOutput, error)
6364
UntagResource(ctx context.Context, params *eks.UntagResourceInput, optFns ...func(*eks.Options)) (*eks.UntagResourceOutput, error)
6465
DisassociateIdentityProviderConfig(ctx context.Context, params *eks.DisassociateIdentityProviderConfigInput, optFns ...func(*eks.Options)) (*eks.DisassociateIdentityProviderConfigOutput, error)
66+
ListPodIdentityAssociations(ctx context.Context, params *eks.ListPodIdentityAssociationsInput, optFns ...func(*eks.Options)) (*eks.ListPodIdentityAssociationsOutput, error)
67+
podidentities.EKSAPIPodIdentity
6568

6669
// Waiters for EKS Cluster
6770
WaitUntilClusterActive(ctx context.Context, params *eks.DescribeClusterInput, maxWait time.Duration) error

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+
// EKSAPIPodIdentity defines the EKS API interface.
29+
type EKSAPIPodIdentity 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 EKSAPIPodIdentity) 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 EKSAPIPodIdentity
4349
clusterName string
4450
}
4551

pkg/eks/podidentities/plan_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import (
2121
"testing"
2222
"time"
2323

24-
"github.com/aws/aws-sdk-go/aws"
25-
"github.com/aws/aws-sdk-go/service/eks"
24+
"github.com/aws/aws-sdk-go-v2/aws"
25+
"github.com/aws/aws-sdk-go-v2/service/eks"
26+
"github.com/aws/aws-sdk-go-v2/service/eks/types"
2627
"github.com/golang/mock/gomock"
2728
. "github.com/onsi/gomega"
2829

@@ -58,14 +59,14 @@ func TestEKSPodIdentityAssociationsPlan(t *testing.T) {
5859
name: "no current and 1 desired",
5960
expect: func(m *mock_eksiface.MockEKSAPIMockRecorder) {
6061
m.
61-
CreatePodIdentityAssociation(gomock.Eq(&eks.CreatePodIdentityAssociationInput{
62+
CreatePodIdentityAssociation(gomock.Any(), gomock.Eq(&eks.CreatePodIdentityAssociationInput{
6263
Namespace: aws.String(namespace),
6364
RoleArn: aws.String(roleArn),
6465
ServiceAccount: aws.String(serviceAccount),
6566
ClusterName: aws.String(clusterName),
6667
})).
6768
Return(&eks.CreatePodIdentityAssociationOutput{
68-
Association: &eks.PodIdentityAssociation{
69+
Association: &types.PodIdentityAssociation{
6970
AssociationArn: aws.String(responseAssociationArn),
7071
AssociationId: aws.String(associationID),
7172
Namespace: aws.String(namespace),
@@ -112,12 +113,12 @@ func TestEKSPodIdentityAssociationsPlan(t *testing.T) {
112113
name: "1 current and 0 desired",
113114
expect: func(m *mock_eksiface.MockEKSAPIMockRecorder) {
114115
m.
115-
DeletePodIdentityAssociation(gomock.Eq(&eks.DeletePodIdentityAssociationInput{
116+
DeletePodIdentityAssociation(gomock.Any(), gomock.Eq(&eks.DeletePodIdentityAssociationInput{
116117
AssociationId: aws.String(associationID),
117118
ClusterName: aws.String(clusterName),
118119
})).
119120
Return(&eks.DeletePodIdentityAssociationOutput{
120-
Association: &eks.PodIdentityAssociation{
121+
Association: &types.PodIdentityAssociation{
121122
AssociationArn: aws.String(responseAssociationArn),
122123
AssociationId: aws.String(associationID),
123124
Namespace: aws.String(namespace),

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 EKSAPIPodIdentity
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 EKSAPIPodIdentity
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)