Skip to content

Commit df09e6c

Browse files
authored
Merge pull request #5193 from s3rj1k/eks-vpce-deletion
✨ feat: Remove owned VPCEs when deleting VPC.
2 parents 85759ce + 0c80965 commit df09e6c

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

controllers/awscluster_controller_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,18 @@ func mockedDeleteVPCCallsForNonExistentVPC(m *mocks.MockEC2APIMockRecorder) {
14761476
}
14771477

14781478
func mockedDeleteVPCCalls(m *mocks.MockEC2APIMockRecorder) {
1479+
m.DescribeVpcEndpointsPages(gomock.Eq(&ec2.DescribeVpcEndpointsInput{
1480+
Filters: []*ec2.Filter{
1481+
{
1482+
Name: aws.String("tag:sigs.k8s.io/cluster-api-provider-aws/cluster/test-cluster"),
1483+
Values: []*string{aws.String("owned")},
1484+
},
1485+
{
1486+
Name: aws.String("vpc-id"),
1487+
Values: []*string{aws.String("vpc-exists")},
1488+
},
1489+
},
1490+
}), gomock.Any()).Return(nil).AnyTimes()
14791491
m.DescribeSubnetsWithContext(context.TODO(), gomock.Eq(&ec2.DescribeSubnetsInput{
14801492
Filters: []*ec2.Filter{
14811493
{

pkg/cloud/services/network/vpc.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,8 @@ func (s *Service) deleteVPCEndpoints() error {
276276
return nil
277277
}
278278

279-
// Gather all services that might have been enabled.
280-
services := sets.New[string]()
281-
if s.scope.Bucket() != nil {
282-
services.Insert(fmt.Sprintf("com.amazonaws.%s.s3", s.scope.Region()))
283-
}
284-
if services.Len() == 0 {
285-
return nil
286-
}
287-
288279
// Get all existing endpoints.
289-
endpoints, err := s.describeVPCEndpoints()
280+
endpoints, err := s.describeVPCEndpoints(filter.EC2.ClusterOwned(s.scope.Name()))
290281
if err != nil {
291282
return errors.Wrap(err, "failed to describe vpc endpoints")
292283
}

test/e2e/data/e2e_eks_conf.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ intervals:
149149
default/wait-machine-status: ["20m", "10s"]
150150
default/wait-infra-subnets: ["5m", "30s"]
151151
default/wait-control-plane-upgrade: ["35m", "30s"]
152-
default/wait-addon-status: ["10m", "30s"]
152+
default/wait-addon-status: ["30m", "30s"]
153153
default/wait-create-identity: ["1m", "10s"]
154154
default/wait-deployment-ready: ["5m", "10s"]
155155
default/wait-loadbalancer-ready: ["5m", "30s"]

test/e2e/shared/suite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func Node1BeforeSuite(e2eCtx *E2EContext) []byte {
145145
success = false
146146
}
147147
return success
148-
}, 10*time.Minute, 5*time.Second).Should(BeTrue(), "Should've eventually succeeded creating an AWS CloudFormation stack")
148+
}, 45*time.Minute, 30*time.Second).Should(BeTrue(), "Should've eventually succeeded creating an AWS CloudFormation stack")
149149
}
150150

151151
ensureStackTags(e2eCtx.AWSSession, bootstrapTemplate.Spec.StackName, bootstrapTags)

test/e2e/suites/managed/eks_test.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package managed
2222
import (
2323
"context"
2424
"fmt"
25+
"time"
2526

2627
"github.com/onsi/ginkgo/v2"
2728
. "github.com/onsi/gomega"
@@ -76,15 +77,22 @@ var _ = ginkgo.Describe("[managed] [general] EKS cluster tests", func() {
7677
})
7778

7879
ginkgo.By("should set environment variables on the aws-node daemonset")
79-
CheckAwsNodeEnvVarsSet(ctx, func() UpdateAwsNodeVersionSpecInput {
80-
return UpdateAwsNodeVersionSpecInput{
81-
E2EConfig: e2eCtx.E2EConfig,
82-
BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy,
83-
AWSSession: e2eCtx.BootstrapUserAWSSession,
84-
Namespace: namespace,
85-
ClusterName: clusterName,
86-
}
87-
})
80+
Eventually(func() error {
81+
defer ginkgo.GinkgoRecover()
82+
CheckAwsNodeEnvVarsSet(ctx, func() UpdateAwsNodeVersionSpecInput {
83+
return UpdateAwsNodeVersionSpecInput{
84+
E2EConfig: e2eCtx.E2EConfig,
85+
BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy,
86+
AWSSession: e2eCtx.BootstrapUserAWSSession,
87+
Namespace: namespace,
88+
ClusterName: clusterName,
89+
}
90+
})
91+
return nil
92+
}).WithTimeout(5*time.Minute).WithPolling(10*time.Second).WithContext(ctx).Should(
93+
Succeed(),
94+
"Failed to verify AWS Node environment variables after 5 minutes of retries",
95+
)
8896

8997
ginkgo.By("should have the VPC CNI installed")
9098
CheckAddonExistsSpec(ctx, func() CheckAddonExistsSpecInput {

0 commit comments

Comments
 (0)