Skip to content

Commit

Permalink
Fix errors with 1007 backport
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Thapar <[email protected]>
  • Loading branch information
vthapar committed Sep 26, 2024
1 parent 741981a commit a6f0732
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
3 changes: 3 additions & 0 deletions pkg/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ package aws

import (
"context"
"fmt"
"regexp"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
Expand Down
31 changes: 22 additions & 9 deletions pkg/aws/aws_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
. "github.com/onsi/gomega"
"github.com/submariner-io/admiral/pkg/mock"
"github.com/submariner-io/cloud-prepare/pkg/aws/client/fake"
"k8s.io/utils/ptr"
)

const (
Expand Down Expand Up @@ -66,6 +67,7 @@ type fakeAWSClientBase struct {
awsClient *fake.MockInterface
mockCtrl *gomock.Controller
vpcID string
subnets []types.Subnet
describeSubnetsErr error
authorizeSecurityGroupIngressErr error
createTagsErr error
Expand All @@ -76,6 +78,7 @@ func (f *fakeAWSClientBase) beforeEach() {
f.mockCtrl = gomock.NewController(GinkgoT())
f.awsClient = fake.NewMockInterface(f.mockCtrl)
f.vpcID = vpcID
f.subnets = []types.Subnet{newSubnet(availabilityZone1, subnetID1), newSubnet(availabilityZone2, subnetID2)}
f.describeSubnetsErr = nil
f.authorizeSecurityGroupIngressErr = nil
f.createTagsErr = nil
Expand Down Expand Up @@ -112,18 +115,15 @@ func (f *fakeAWSClientBase) expectDescribeVpcs(vpcID string) {
}, types.Filter{
Name: awssdk.String("tag:kubernetes.io/cluster/" + infraID),
Values: []string{"owned"},
}, {
Name: ptr.To(providerAWSTagPrefix + infraID),
Values: []string{"owned"},
}}}).Matches))).Return(&ec2.DescribeVpcsOutput{Vpcs: vpcs}, nil).Maybe()
})).Return(&ec2.DescribeVpcsOutput{Vpcs: vpcs}, nil).AnyTimes()
}

func (f *fakeAWSClientBase) expectValidateAuthorizeSecurityGroupIngress(authErr error) *mock.Call {
return f.awsClient.EXPECT().AuthorizeSecurityGroupIngress(mock.Anything,
mock.MatchedBy((&authorizeSecurityGroupIngressInputMatcher{ec2.AuthorizeSecurityGroupIngressInput{
func (f *fakeAWSClientBase) expectValidateAuthorizeSecurityGroupIngress(authErr error) *gomock.Call {
return f.awsClient.EXPECT().AuthorizeSecurityGroupIngress(gomock.Any(),
mock.Eq((&authorizeSecurityGroupIngressInputMatcher{ec2.AuthorizeSecurityGroupIngressInput{
DryRun: ptr.To(true),
GroupId: ptr.To(workerGroupID),
}}).Matches)).Return(&ec2.AuthorizeSecurityGroupIngressOutput{}, authErr).Call
}}).Matches)).Return(&ec2.AuthorizeSecurityGroupIngressOutput{}, authErr)
}

func (f *fakeAWSClientBase) expectAuthorizeSecurityGroupIngress(srcGroup string, ipPerm *types.IpPermission) {
Expand All @@ -149,7 +149,7 @@ func (f *fakeAWSClientBase) expectValidateRevokeSecurityGroupIngress(retErr erro
func (f *fakeAWSClientBase) expectDescribePublicSubnets(retSubnets ...types.Subnet) {
f.awsClient.EXPECT().DescribeSubnets(gomock.Any(), eqFilters(types.Filter{
Name: awssdk.String("tag:Name"),
Values: []string{infraID + "-public-" + region + "*"},
Values: []string{infraID + "*-public-" + region + "*"},
}, types.Filter{
Name: awssdk.String("vpc-id"),
Values: []string{f.vpcID},
Expand All @@ -159,6 +159,19 @@ func (f *fakeAWSClientBase) expectDescribePublicSubnets(retSubnets ...types.Subn
})).Return(&ec2.DescribeSubnetsOutput{Subnets: retSubnets}, f.describeSubnetsErr).AnyTimes()
}

func (f *fakeAWSClientBase) expectDescribePublicSubnetsSigs(retSubnets ...types.Subnet) {
f.awsClient.EXPECT().DescribeSubnets(gomock.Any(), eqFilters(types.Filter{
Name: awssdk.String("tag:Name"),
Values: []string{infraID + "*-public-" + region + "*"},
}, types.Filter{
Name: awssdk.String("vpc-id"),
Values: []string{f.vpcID},
}, types.Filter{
Name: awssdk.String(clusterFilterTagNameSigs),
Values: []string{"owned"},
})).Return(&ec2.DescribeSubnetsOutput{Subnets: retSubnets}, f.describeSubnetsErr).AnyTimes()
}

func (f *fakeAWSClientBase) expectDescribeGatewaySubnets(retSubnets ...types.Subnet) {
f.awsClient.EXPECT().DescribeSubnets(gomock.Any(), eqFilters(types.Filter{
Name: awssdk.String("tag:submariner.io/gateway"),
Expand Down
4 changes: 4 additions & 0 deletions pkg/aws/securitygroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,7 @@ func (ac *awsCloud) revokePortsFromGroup(group *types.SecurityGroup) error {

return errors.Wrap(err, "error revoking AWS security group ingress")
}

func withInfraIDPrefix(s string) string {
return "{infraID}" + s
}
4 changes: 3 additions & 1 deletion pkg/aws/vpcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func (ac *awsCloud) getVpcID() (string, error) {
return vpcIDStr, nil
}

ownedFilters := ac.filterByCurrentCluster()
ownedFilters := []types.Filter{
ac.filterByCurrentCluster(),
}
vpcName := ac.withAWSInfo("{infraID}-vpc")

filters := []types.Filter{
Expand Down

0 comments on commit a6f0732

Please sign in to comment.