Skip to content

Commit

Permalink
Merge pull request #4805 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…4799-to-release-2.3

[release-2.3] 🐛 Delete VPC endpoints only if s3 bucket is enabled
  • Loading branch information
k8s-ci-robot authored Feb 21, 2024
2 parents 6cfd980 + 897de7a commit 1b49010
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
18 changes: 0 additions & 18 deletions controllers/awscluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,24 +711,6 @@ func mockedDeleteVPCCallsForNonExistentVPC(m *mocks.MockEC2APIMockRecorder) {
}

func mockedDeleteVPCCalls(m *mocks.MockEC2APIMockRecorder) {
m.DescribeVpcEndpointsPages(gomock.Eq(&ec2.DescribeVpcEndpointsInput{
Filters: []*ec2.Filter{
{
Name: aws.String("vpc-id"),
Values: aws.StringSlice([]string{"vpc-exists"}),
},
}}),
gomock.Any()).Do(func(_, y interface{}) {
funct := y.(func(page *ec2.DescribeVpcEndpointsOutput, lastPage bool) bool)
funct(&ec2.DescribeVpcEndpointsOutput{VpcEndpoints: []*ec2.VpcEndpoint{{
VpcEndpointId: aws.String("vpce-12345"),
}}}, true)
}).Return(nil).AnyTimes()

m.DeleteVpcEndpoints(gomock.Eq(&ec2.DeleteVpcEndpointsInput{
VpcEndpointIds: aws.StringSlice([]string{"vpce-12345"}),
})).Return(&ec2.DeleteVpcEndpointsOutput{}, nil).AnyTimes()

m.DescribeSubnetsWithContext(context.TODO(), gomock.Eq(&ec2.DescribeSubnetsInput{
Filters: []*ec2.Filter{
{
Expand Down
9 changes: 9 additions & 0 deletions pkg/cloud/services/network/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ func (s *Service) deleteVPCEndpoints() error {
return nil
}

// Gather all services that might have been enabled.
services := sets.New[string]()
if s.scope.Bucket() != nil {
services.Insert(fmt.Sprintf("com.amazonaws.%s.s3", s.scope.Region()))
}
if services.Len() == 0 {
return nil
}

// Get all existing endpoints.
endpoints, err := s.describeVPCEndpoints()
if err != nil {
Expand Down

0 comments on commit 1b49010

Please sign in to comment.