diff --git a/controllers/awscluster_controller_test.go b/controllers/awscluster_controller_test.go index 1ab83dfd8a..7d4055c239 100644 --- a/controllers/awscluster_controller_test.go +++ b/controllers/awscluster_controller_test.go @@ -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{ { diff --git a/pkg/cloud/services/network/vpc.go b/pkg/cloud/services/network/vpc.go index 94face8454..e0142ca2e0 100644 --- a/pkg/cloud/services/network/vpc.go +++ b/pkg/cloud/services/network/vpc.go @@ -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 {