From 27c8991e2c8a1572646584ec0cd9c145c8b781a3 Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Tue, 20 Feb 2024 06:13:52 -0800 Subject: [PATCH] :bug: Delete VPC endpoints only if s3 bucket is enabled Signed-off-by: Vince Prignano --- controllers/awscluster_controller_test.go | 18 ------------------ pkg/cloud/services/network/vpc.go | 9 +++++++++ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/controllers/awscluster_controller_test.go b/controllers/awscluster_controller_test.go index d97e18d4db..affda6cdc8 100644 --- a/controllers/awscluster_controller_test.go +++ b/controllers/awscluster_controller_test.go @@ -827,24 +827,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{ { diff --git a/pkg/cloud/services/network/vpc.go b/pkg/cloud/services/network/vpc.go index 9758ec45e1..1e01961e83 100644 --- a/pkg/cloud/services/network/vpc.go +++ b/pkg/cloud/services/network/vpc.go @@ -276,6 +276,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 {