Skip to content

Commit 2374d77

Browse files
fix e2e job
1 parent 86dd894 commit 2374d77

File tree

6 files changed

+30
-23
lines changed

6 files changed

+30
-23
lines changed

pkg/cloud/services/network/eips_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ import (
2323
"github.com/aws/aws-sdk-go-v2/service/ec2"
2424
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
2525
"github.com/aws/aws-sdk-go/aws"
26-
"github.com/aws/aws-sdk-go/aws/awserr"
26+
"github.com/aws/smithy-go"
2727
"github.com/golang/mock/gomock"
2828
. "github.com/onsi/gomega"
29-
"github.com/pkg/errors"
3029
"k8s.io/apimachinery/pkg/runtime"
3130
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3231

@@ -104,7 +103,7 @@ func TestServiceReleaseAddresses(t *testing.T) {
104103
},
105104
}, nil)
106105
m.DisassociateAddress(context.TODO(), gomock.AssignableToTypeOf(&ec2.DisassociateAddressInput{})).Return(nil, nil).Times(2)
107-
m.ReleaseAddress(context.TODO(), gomock.AssignableToTypeOf(&ec2.ReleaseAddressInput{})).Return(nil, awserr.New(awserrors.AuthFailure, awserrors.AuthFailure, errors.Errorf(awserrors.AuthFailure)))
106+
m.ReleaseAddress(context.TODO(), gomock.AssignableToTypeOf(&ec2.ReleaseAddressInput{})).Return(nil, &smithy.GenericAPIError{Code: awserrors.AuthFailure, Message: awserrors.AuthFailure})
108107
m.ReleaseAddress(context.TODO(), gomock.AssignableToTypeOf(&ec2.ReleaseAddressInput{})).Return(nil, nil)
109108
},
110109
},
@@ -121,7 +120,7 @@ func TestServiceReleaseAddresses(t *testing.T) {
121120
},
122121
}, nil)
123122
m.DisassociateAddress(context.TODO(), gomock.AssignableToTypeOf(&ec2.DisassociateAddressInput{})).Return(nil, nil).Times(2)
124-
m.ReleaseAddress(context.TODO(), gomock.AssignableToTypeOf(&ec2.ReleaseAddressInput{})).Return(nil, awserr.New(awserrors.InUseIPAddress, awserrors.InUseIPAddress, errors.Errorf(awserrors.InUseIPAddress)))
123+
m.ReleaseAddress(context.TODO(), gomock.AssignableToTypeOf(&ec2.ReleaseAddressInput{})).Return(nil, &smithy.GenericAPIError{Code: awserrors.InUseIPAddress, Message: awserrors.InUseIPAddress})
125124
m.ReleaseAddress(context.TODO(), gomock.AssignableToTypeOf(&ec2.ReleaseAddressInput{})).Return(nil, nil)
126125
},
127126
},
@@ -138,7 +137,7 @@ func TestServiceReleaseAddresses(t *testing.T) {
138137
},
139138
}, nil)
140139
m.DisassociateAddress(context.TODO(), gomock.AssignableToTypeOf(&ec2.DisassociateAddressInput{})).Return(nil, nil).Times(2)
141-
m.ReleaseAddress(context.TODO(), gomock.AssignableToTypeOf(&ec2.ReleaseAddressInput{})).Return(nil, awserr.New("dependency-failure", "dependency-failure", errors.Errorf("dependency-failure")))
140+
m.ReleaseAddress(context.TODO(), gomock.AssignableToTypeOf(&ec2.ReleaseAddressInput{})).Return(nil, &smithy.GenericAPIError{Code: "dependency-failure", Message: "dependency-failure"})
142141
},
143142
wantErr: true,
144143
},

pkg/cloud/services/network/vpc.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ func (s *Service) ensureManagedVPCAttributes(vpc *infrav1.VPCSpec) error {
326326
if code, ok := awserrors.Code(errors.Cause(err)); ok && code == awserrors.VPCNotFound {
327327
return err
328328
}
329+
// Also check for smithy errors
330+
if smithyErr := awserrors.ParseSmithyError(err); smithyErr != nil && smithyErr.ErrorCode() == awserrors.VPCNotFound {
331+
return err
332+
}
329333
errs = append(errs, errors.Wrap(err, "failed to describe enableDnsHostnames vpc attribute"))
330334
} else if !aws.BoolValue(vpcAttr.EnableDnsHostnames.Value) {
331335
attrInput := &ec2.ModifyVpcAttributeInput{
@@ -349,6 +353,10 @@ func (s *Service) ensureManagedVPCAttributes(vpc *infrav1.VPCSpec) error {
349353
if code, ok := awserrors.Code(errors.Cause(err)); ok && code == awserrors.VPCNotFound {
350354
return err
351355
}
356+
// Also check for smithy errors
357+
if smithyErr := awserrors.ParseSmithyError(err); smithyErr != nil && smithyErr.ErrorCode() == awserrors.VPCNotFound {
358+
return err
359+
}
352360
errs = append(errs, errors.Wrap(err, "failed to describe enableDnsSupport vpc attribute"))
353361
} else if !aws.BoolValue(vpcAttr.EnableDnsSupport.Value) {
354362
attrInput := &ec2.ModifyVpcAttributeInput{

pkg/cloud/services/network/vpc_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"github.com/aws/aws-sdk-go-v2/service/ec2"
2424
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
2525
"github.com/aws/aws-sdk-go/aws"
26-
"github.com/aws/aws-sdk-go/aws/awserr"
2726
"github.com/aws/aws-sdk-go/aws/request"
27+
"github.com/aws/smithy-go"
2828
"github.com/golang/mock/gomock"
2929
. "github.com/onsi/gomega"
3030
"github.com/pkg/errors"
@@ -33,7 +33,6 @@ import (
3333
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3434

3535
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
36-
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/awserrors"
3736
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
3837
"sigs.k8s.io/cluster-api-provider-aws/v2/test/mocks"
3938
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -414,7 +413,7 @@ func TestReconcileVPC(t *testing.T) {
414413
Values: []string{string(types.VpcStatePending), string(types.VpcStateAvailable)},
415414
},
416415
},
417-
})).Return(nil, awserr.New("404", "http not found err", errors.New("err")))
416+
})).Return(nil, &smithy.GenericAPIError{Code: "404", Message: "http not found err"})
418417
},
419418
},
420419
{
@@ -464,7 +463,7 @@ func TestReconcileVPC(t *testing.T) {
464463
},
465464
},
466465
}, nil)
467-
m.DescribeVpcAttribute(context.TODO(), gomock.AssignableToTypeOf(&ec2.DescribeVpcAttributeInput{})).Return(nil, awserr.New("InvalidVpcID.NotFound", "not found", nil))
466+
m.DescribeVpcAttribute(context.TODO(), gomock.AssignableToTypeOf(&ec2.DescribeVpcAttributeInput{})).Return(nil, &smithy.GenericAPIError{Code: "InvalidVpcID.NotFound", Message: "not found"})
468467
m.DescribeVpcAttribute(context.TODO(), gomock.AssignableToTypeOf(&ec2.DescribeVpcAttributeInput{})).
469468
DoAndReturn(describeVpcAttributeTrue).AnyTimes()
470469
},
@@ -494,7 +493,7 @@ func TestReconcileVPC(t *testing.T) {
494493
},
495494
},
496495
}, nil)
497-
m.DescribeVpcAttribute(context.TODO(), gomock.AssignableToTypeOf(&ec2.DescribeVpcAttributeInput{})).AnyTimes().Return(nil, awserrors.NewFailedDependency("failed dependency"))
496+
m.DescribeVpcAttribute(context.TODO(), gomock.AssignableToTypeOf(&ec2.DescribeVpcAttributeInput{})).AnyTimes().Return(nil, &smithy.GenericAPIError{Code: "FailedDependency", Message: "failed dependency"})
498497
},
499498
},
500499
{
@@ -510,7 +509,7 @@ func TestReconcileVPC(t *testing.T) {
510509
},
511510
},
512511
})).Return(&ec2.DescribeVpcsOutput{Vpcs: []types.Vpc{}}, nil)
513-
m.CreateVpc(context.TODO(), gomock.AssignableToTypeOf(&ec2.CreateVpcInput{})).After(describeVPCByNameCall).Return(nil, awserrors.NewFailedDependency("failed dependency"))
512+
m.CreateVpc(context.TODO(), gomock.AssignableToTypeOf(&ec2.CreateVpcInput{})).After(describeVPCByNameCall).Return(nil, &smithy.GenericAPIError{Code: "FailedDependency", Message: "failed dependency"})
514513
},
515514
},
516515
{
@@ -610,7 +609,7 @@ func TestDeleteVPC(t *testing.T) {
610609
expect: func(m *mocks.MockEC2APIMockRecorder) {
611610
m.DeleteVpc(context.TODO(), gomock.Eq(&ec2.DeleteVpcInput{
612611
VpcId: aws.String("managed-vpc"),
613-
})).Return(nil, awserrors.NewFailedDependency("failed dependency"))
612+
})).Return(nil, &smithy.GenericAPIError{Code: "FailedDependency", Message: "failed dependency"})
614613
},
615614
},
616615
{
@@ -636,7 +635,7 @@ func TestDeleteVPC(t *testing.T) {
636635
expect: func(m *mocks.MockEC2APIMockRecorder) {
637636
m.DeleteVpc(context.TODO(), gomock.Eq(&ec2.DeleteVpcInput{
638637
VpcId: aws.String("managed-vpc"),
639-
})).Return(nil, awserr.New("InvalidVpcID.NotFound", "not found", nil))
638+
})).Return(nil, &smithy.GenericAPIError{Code: "InvalidVpcID.NotFound", Message: "not found"})
640639
},
641640
},
642641
}

pkg/cloud/services/ssm/secret_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3737

3838
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
39-
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/awserrors"
4039
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
4140
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/ssm/mock_ssmiface"
4241
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -275,7 +274,7 @@ func TestServiceDelete(t *testing.T) {
275274
expect: func(m *mock_ssmiface.MockSSMAPIMockRecorder) {
276275
m.DeleteParameter(context.TODO(), gomock.Eq(&ssm.DeleteParameterInput{
277276
Name: aws.String("prefix/0"),
278-
})).Return(nil, awserrors.NewFailedDependency("failed dependency"))
277+
})).Return(nil, &smithy.GenericAPIError{Code: "FailedDependency", Message: "failed dependency"})
279278
m.DeleteParameter(context.TODO(), gomock.Eq(&ssm.DeleteParameterInput{
280279
Name: aws.String("prefix/1"),
281280
})).Return(nil, &mockAPIError{
@@ -284,11 +283,11 @@ func TestServiceDelete(t *testing.T) {
284283
})
285284
m.DeleteParameter(context.TODO(), gomock.Eq(&ssm.DeleteParameterInput{
286285
Name: aws.String("prefix/2"),
287-
})).Return(nil, awserrors.NewConflict("new conflict"))
286+
})).Return(nil, &smithy.GenericAPIError{Code: "Conflict", Message: "new conflict"})
288287
},
289288
wantErr: true,
290289
check: func(err error) {
291-
if err.Error() != "[failed dependency, new conflict]" {
290+
if err.Error() != "[api error FailedDependency: failed dependency, api error Conflict: new conflict]" {
292291
t.Fatalf("Unexpected error: %v", err)
293292
}
294293
},

pkg/cloud/services/wait/wait.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ func WaitForWithRetryable(backoff wait.Backoff, condition wait.ConditionFunc, re
6868

6969
// If the returned error isn't empty, check if the error is a retryable one,
7070
// or return immediately.
71-
smithyErr := awserrors.ParseSmithyError(err)
72-
if smithyErr == nil {
71+
code, ok := awserrors.Code(errors.Cause(err))
72+
if !ok {
7373
return false, err
7474
}
75-
76-
code := smithyErr.ErrorCode()
75+
if smithyErr := awserrors.ParseSmithyError(err); smithyErr != nil {
76+
code = smithyErr.ErrorCode()
77+
}
78+
// Also check for smithy errors
7779
for _, r := range retryableErrors {
7880
if code == r {
7981
// We should retry.

test/e2e/suites/managed/gc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var _ = ginkgo.Describe("[managed] [gc] EKS Cluster external resource GC tests",
5555
clusterName = fmt.Sprintf("%s-%s", specName, util.RandomString(6))
5656

5757
ginkgo.By("default iam role should exist")
58-
VerifyRoleExistsAndOwned(ctx, ekscontrolplanev1.DefaultEKSControlPlaneRole, clusterName, false, e2eCtx.BootstrapUserAWSSessionV2)
58+
VerifyRoleExistsAndOwned(ctx, ekscontrolplanev1.DefaultEKSControlPlaneRole, clusterName, false, e2eCtx.AWSSessionV2)
5959

6060
ginkgo.By("should create an EKS control plane")
6161
ManagedClusterSpec(ctx, func() ManagedClusterSpecInput {
@@ -178,7 +178,7 @@ var _ = ginkgo.Describe("[managed] [gc] EKS Cluster external resource GC tests",
178178
clusterName = fmt.Sprintf("%s-%s", specName, util.RandomString(6))
179179

180180
ginkgo.By("default iam role should exist")
181-
VerifyRoleExistsAndOwned(ctx, ekscontrolplanev1.DefaultEKSControlPlaneRole, clusterName, false, e2eCtx.BootstrapUserAWSSessionV2)
181+
VerifyRoleExistsAndOwned(ctx, ekscontrolplanev1.DefaultEKSControlPlaneRole, clusterName, false, e2eCtx.AWSSessionV2)
182182

183183
ginkgo.By("should create an EKS control plane")
184184
ManagedClusterSpec(ctx, func() ManagedClusterSpecInput {

0 commit comments

Comments
 (0)