Skip to content

Commit ceef0ab

Browse files
fix lint error
1 parent c65596b commit ceef0ab

32 files changed

+232
-1954
lines changed

controlplane/eks/controllers/awsmanagedcontrolplane_controller_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"
3333
"github.com/aws/aws-sdk-go-v2/service/iam"
3434
iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
35-
stsrequest "github.com/aws/aws-sdk-go/aws/request"
3635
"github.com/aws/aws-sdk-go/service/sts"
3736
"github.com/aws/smithy-go"
3837
"github.com/golang/mock/gomock"
@@ -948,12 +947,9 @@ func mockedEKSCluster(ctx context.Context, g *WithT, eksRec *mock_eksiface.MockE
948947
})).Return(
949948
clusterSgDesc, nil)
950949

951-
req, err := http.NewRequest(http.MethodGet, "foobar", http.NoBody)
950+
_, err := http.NewRequest(http.MethodGet, "foobar", http.NoBody)
952951
g.Expect(err).To(BeNil())
953-
stsRec.GetCallerIdentityRequest(&sts.GetCallerIdentityInput{}).Return(&stsrequest.Request{
954-
HTTPRequest: req,
955-
Operation: &stsrequest.Operation{},
956-
}, &sts.GetCallerIdentityOutput{})
952+
stsRec.GetCallerIdentity(gomock.Any(), gomock.Any(), gomock.Any()).Return(&sts.GetCallerIdentityOutput{}, nil)
957953

958954
eksRec.TagResource(ctx, &eks.TagResourceInput{
959955
ResourceArn: clusterARN,

controlplane/rosa/controllers/rosacontrolplane_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func TestRosaControlPlaneReconcileStatusVersion(t *testing.T) {
295295
stsMock := mock_stsiface.NewMockSTSAPI(mockCtrl)
296296

297297
getCallerIdentityResult := &sts.GetCallerIdentityOutput{Account: aws.String("foo"), Arn: aws.String("arn:aws:iam::123456789012:rosa/foo")}
298-
stsMock.EXPECT().GetCallerIdentity(gomock.Any()).Return(getCallerIdentityResult, nil).Times(1)
298+
stsMock.EXPECT().GetCallerIdentity(gomock.Any(), gomock.Any(), gomock.Any()).Return(getCallerIdentityResult, nil).Times(1)
299299

300300
expect := func(m *mocks.MockOCMClientMockRecorder) {
301301
m.ValidateHypershiftVersion(gomock.Any(), gomock.Any()).DoAndReturn(func(clusterId string, nodePoolID string) (bool, error) {

exp/controllers/rosamachinepool_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ func TestRosaMachinePoolReconcile(t *testing.T) {
547547
test.expect(ocmMock.EXPECT())
548548

549549
stsMock := mock_stsiface.NewMockSTSAPI(mockCtrl)
550-
stsMock.EXPECT().GetCallerIdentity(gomock.Any()).Times(1)
550+
stsMock.EXPECT().GetCallerIdentity(gomock.Any(), gomock.Any(), gomock.Any()).Times(1)
551551

552552
r := ROSAMachinePoolReconciler{
553553
Recorder: recorder,
@@ -642,7 +642,7 @@ func TestRosaMachinePoolReconcile(t *testing.T) {
642642
expect(ocmMock.EXPECT())
643643

644644
stsMock := mock_stsiface.NewMockSTSAPI(mockCtrl)
645-
stsMock.EXPECT().GetCallerIdentity(gomock.Any()).Times(1)
645+
stsMock.EXPECT().GetCallerIdentity(gomock.Any(), gomock.Any(), gomock.Any()).Times(1)
646646

647647
r := ROSAMachinePoolReconciler{
648648
Recorder: recorder,

pkg/cloud/services/eks/config.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,11 @@ func (s *Service) createBaseKubeConfig(cluster *ekstypes.Cluster, userName strin
301301
func (s *Service) generateToken() (string, error) {
302302
eksClusterName := s.scope.KubernetesClusterName()
303303

304-
// Create a presign client for STS
305-
presignClient := sts.NewPresignClient(s.STSClient)
306-
307304
// Create the GetCallerIdentity input
308305
input := &sts.GetCallerIdentityInput{}
309306

310307
// Presign the request
311-
presignedReq, err := presignClient.PresignGetCallerIdentity(context.TODO(), input)
308+
presignedReq, err := s.STSPresignClient.PresignGetCallerIdentity(context.TODO(), input)
312309
if err != nil {
313310
return "", fmt.Errorf("presigning AWS get caller identity: %w", err)
314311
}

pkg/cloud/services/eks/config_test.go

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ package eks
22

33
import (
44
"context"
5-
"net/http"
6-
"net/url"
75
"testing"
86

97
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"
8+
"github.com/aws/aws-sdk-go-v2/service/sts"
109
"github.com/aws/aws-sdk-go/aws"
11-
"github.com/aws/aws-sdk-go/aws/request"
12-
"github.com/aws/aws-sdk-go/service/sts"
1310
"github.com/golang/mock/gomock"
1411
. "github.com/onsi/gomega"
1512
corev1 "k8s.io/api/core/v1"
@@ -21,7 +18,7 @@ import (
2118
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2219
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
2320
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
24-
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/sts/mock_stsiface"
21+
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/s3/mock_stsiface"
2522
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2623
"sigs.k8s.io/cluster-api/util/secret"
2724
)
@@ -42,20 +39,7 @@ func Test_createCAPIKubeconfigSecret(t *testing.T) {
4239
serviceFunc: func() *Service {
4340
mockCtrl := gomock.NewController(t)
4441
stsMock := mock_stsiface.NewMockSTSAPI(mockCtrl)
45-
op := request.Request{
46-
Operation: &request.Operation{Name: "GetCallerIdentity",
47-
HTTPMethod: "POST",
48-
HTTPPath: "/",
49-
},
50-
HTTPRequest: &http.Request{
51-
Header: make(http.Header),
52-
URL: &url.URL{
53-
Scheme: "https",
54-
Host: "F00BA4.gr4.us-east-2.eks.amazonaws.com",
55-
},
56-
},
57-
}
58-
stsMock.EXPECT().GetCallerIdentityRequest(gomock.Any()).Return(&op, &sts.GetCallerIdentityOutput{})
42+
stsMock.EXPECT().GetCallerIdentity(gomock.Any(), gomock.Any(), gomock.Any()).Return(&sts.GetCallerIdentityOutput{}, nil)
5943

6044
scheme := runtime.NewScheme()
6145
_ = infrav1.AddToScheme(scheme)
@@ -151,20 +135,7 @@ func Test_updateCAPIKubeconfigSecret(t *testing.T) {
151135
serviceFunc: func(tc testCase) *Service {
152136
mockCtrl := gomock.NewController(t)
153137
stsMock := mock_stsiface.NewMockSTSAPI(mockCtrl)
154-
op := request.Request{
155-
Operation: &request.Operation{Name: "GetCallerIdentity",
156-
HTTPMethod: "POST",
157-
HTTPPath: "/",
158-
},
159-
HTTPRequest: &http.Request{
160-
Header: make(http.Header),
161-
URL: &url.URL{
162-
Scheme: "https",
163-
Host: "F00BA4.gr4.us-east-2.eks.amazonaws.com",
164-
},
165-
},
166-
}
167-
stsMock.EXPECT().GetCallerIdentityRequest(gomock.Any()).Return(&op, &sts.GetCallerIdentityOutput{})
138+
stsMock.EXPECT().GetCallerIdentity(gomock.Any(), gomock.Any(), gomock.Any()).Return(&sts.GetCallerIdentityOutput{}, nil)
168139

169140
scheme := runtime.NewScheme()
170141
_ = infrav1.AddToScheme(scheme)

pkg/cloud/services/eks/service.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,16 @@ type Service struct {
8989
EC2Client common.EC2API
9090
EKSClient EKSAPI
9191
iam.IAMService
92-
STSClient *sts.Client
92+
STSClient STSAPI
93+
STSPresignClient *sts.PresignClient
94+
}
95+
96+
type STSAPI interface {
97+
GetCallerIdentity(ctx context.Context, params *sts.GetCallerIdentityInput, optFns ...func(*sts.Options)) (*sts.GetCallerIdentityOutput, error)
9398
}
9499

100+
var _ STSAPI = &sts.Client{}
101+
95102
// ServiceOpts defines the functional arguments for the service.
96103
type ServiceOpts func(s *Service)
97104

@@ -104,6 +111,9 @@ func WithIAMClient(client *http.Client) ServiceOpts {
104111

105112
// NewService returns a new service given the api clients.
106113
func NewService(controlPlaneScope *scope.ManagedControlPlaneScope, opts ...ServiceOpts) *Service {
114+
stsClient := scope.NewSTSClient(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane)
115+
stsPresignClient := sts.NewPresignClient(stsClient)
116+
107117
s := &Service{
108118
scope: controlPlaneScope,
109119
EC2Client: scope.NewEC2Client(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
@@ -115,7 +125,8 @@ func NewService(controlPlaneScope *scope.ManagedControlPlaneScope, opts ...Servi
115125
IAMClient: scope.NewIAMClient(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
116126
Client: http.DefaultClient,
117127
},
118-
STSClient: scope.NewSTSClient(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
128+
STSClient: stsClient,
129+
STSPresignClient: stsPresignClient,
119130
}
120131

121132
for _, opt := range opts {

pkg/cloud/services/s3/mock_stsiface/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ limitations under the License.
1717
// Package mock_stsiface provides a mock implementation for the STSAPI interface.
1818
// Run go generate to regenerate this mock.
1919
//
20-
//go:generate ../../../../../hack/tools/bin/mockgen -destination stsapi_mock.go -package mock_stsiface github.com/aws/aws-sdk-go/service/sts/stsiface STSAPI
20+
//go:generate ../../../../../hack/tools/bin/mockgen -destination stsapi_mock.go -package mock_stsiface sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/s3 STSAPI
2121
//go:generate /usr/bin/env bash -c "cat ../../../../../hack/boilerplate/boilerplate.generatego.txt stsapi_mock.go > _stsapi_mock.go && mv _stsapi_mock.go stsapi_mock.go"
2222
package mock_stsiface //nolint:stylecheck

0 commit comments

Comments
 (0)