Skip to content

Commit

Permalink
Remove owned VPCEs when deleting VPC.
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rj1k committed Nov 4, 2024
1 parent 8d7cb44 commit c96b645
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
12 changes: 12 additions & 0 deletions controllers/awscluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,18 @@ func mockedDeleteVPCCallsForNonExistentVPC(m *mocks.MockEC2APIMockRecorder) {
}

func mockedDeleteVPCCalls(m *mocks.MockEC2APIMockRecorder) {
m.DescribeVpcEndpointsPages(gomock.Eq(&ec2.DescribeVpcEndpointsInput{
Filters: []*ec2.Filter{
{
Name: aws.String("tag-key"),
Values: []*string{aws.String("sigs.k8s.io/cluster-api-provider-aws/cluster/test-cluster")},
},
{
Name: aws.String("vpc-id"),
Values: []*string{aws.String("vpc-exists")},
},
},
}), gomock.Any()).Return(nil).AnyTimes()
m.DescribeSubnetsWithContext(context.TODO(), gomock.Eq(&ec2.DescribeSubnetsInput{
Filters: []*ec2.Filter{
{
Expand Down
11 changes: 1 addition & 10 deletions pkg/cloud/services/network/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,8 @@ 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()
endpoints, err := s.describeVPCEndpoints(filter.EC2.Cluster(s.scope.Name()))
if err != nil {
return errors.Wrap(err, "failed to describe vpc endpoints")
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/shared/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func Node1BeforeSuite(e2eCtx *E2EContext) []byte {
success = false
}
return success
}, 10*time.Minute, 5*time.Second).Should(BeTrue(), "Should've eventually succeeded creating an AWS CloudFormation stack")
}, 30*time.Minute, 15*time.Second).Should(BeTrue(), "Should've eventually succeeded creating an AWS CloudFormation stack")
}

ensureStackTags(e2eCtx.AWSSession, bootstrapTemplate.Spec.StackName, bootstrapTags)
Expand Down

0 comments on commit c96b645

Please sign in to comment.