Skip to content

🐛 fix: clean up orphaned ENIs before subnet deletion at teardown#6073

Merged
kubernetes-prow[bot] merged 3 commits into
kubernetes-sigs:mainfrom
damdo:fix/eni-cleanup-during-deletion
Jul 2, 2026
Merged

🐛 fix: clean up orphaned ENIs before subnet deletion at teardown#6073
kubernetes-prow[bot] merged 3 commits into
kubernetes-sigs:mainfrom
damdo:fix/eni-cleanup-during-deletion

Conversation

@damdo

@damdo damdo commented Jun 25, 2026

Copy link
Copy Markdown
Member

What type of PR is this?

/kind bug

What this PR does / why we need it:

After NLB deletion during cluster teardown, AWS asynchronously cleans up the NLB's cross-AZ ENIs, a process that can take up to 1 hour. CAPA proceeds immediately to security group and subnet deletion with no ENI cleanup step, causing DependencyViolation errors that block cluster deletion until the e2e test times out.

This PR adds a deleteOrphanedENIs() step in DeleteNetwork(), right before subnet deletion. It discovers ENIs in the VPC that are:

  • in available state (not attached to any instance or service)
  • referencing one of the cluster's security groups (scoped to only this cluster's ENIs)

This targets exactly the ENIs blocking SG/subnet deletion without touching other clusters' ENIs sharing the same VPC.

Which issue(s) this PR fixes:
Fixes #6067

Special notes for your reviewer:

The ENI cleanup is non-fatal: if it fails, the error is logged and subnet deletion proceeds (which will fail with DependencyViolation and trigger a requeue, as before). On the next reconcile, the ENIs that have since become available are cleaned up, unblocking both SG and subnet deletion.

No new service factory, interface, or controller wiring is needed, the implementation lives entirely in the existing network service's DeleteNetwork() flow.

Checklist:

  • squashed commits
  • includes documentation
  • includes emoji in title
  • adds unit tests
  • adds or updates e2e tests

Release note:

fix: clean up orphaned network interfaces (ENIs) before subnet deletion during cluster teardown, preventing DependencyViolation errors caused by NLB ENIs that AWS cleans up asynchronously after load balancer deletion.

@kubernetes-prow kubernetes-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. kind/bug Categorizes issue or PR as related to a bug. needs-priority labels Jun 25, 2026
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 25, 2026
@damdo
damdo marked this pull request as draft June 25, 2026 10:12
@damdo damdo reopened this Jun 25, 2026
@damdo

damdo commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

/test pull-cluster-api-provider-aws-e2e

3 similar comments
@damdo

damdo commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

/test pull-cluster-api-provider-aws-e2e

@damdo

damdo commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

/test pull-cluster-api-provider-aws-e2e

@damdo

damdo commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

/test pull-cluster-api-provider-aws-e2e

@damdo damdo changed the title WIP: 🐛 Clean up orphaned ENIs before subnet deletion during cluster teardown 🐛 Clean up orphaned ENIs before subnet deletion during cluster teardown Jun 30, 2026
@damdo
damdo marked this pull request as ready for review June 30, 2026 08:29
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 30, 2026
@kubernetes-prow
kubernetes-prow Bot requested a review from fiunchinho June 30, 2026 08:29
@damdo damdo closed this Jun 30, 2026
@damdo damdo reopened this Jun 30, 2026
After NLB deletion, AWS asynchronously cleans up the NLB's cross-AZ ENIs,
which can take up to 1 hour. CAPA proceeds immediately to SG/subnet
deletion with no ENI cleanup step, causing DependencyViolation errors
that block cluster deletion until the e2e test times out.

Add a deleteOrphanedENIs() step in DeleteNetwork(), before subnet deletion.
It discovers ENIs in the VPC that are in "available" state and reference
the cluster's security groups, then deletes them. This targets exactly the
ENIs blocking SG/subnet deletion without touching other clusters' ENIs.

Signed-off-by: Damiano Donati <damiano.donati@gmail.com>
@damdo
damdo force-pushed the fix/eni-cleanup-during-deletion branch from fbbe945 to baaa412 Compare June 30, 2026 08:32
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jun 30, 2026
@damdo damdo changed the title 🐛 Clean up orphaned ENIs before subnet deletion during cluster teardown 🐛 fix: clean up orphaned ENIs before subnet deletion at teardown Jun 30, 2026
@damdo

damdo commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

@damdo

damdo commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

/assign @richardcase @dlipovetsky @AndiDog @nrb @clebs

@kubernetes-prow
kubernetes-prow Bot requested review from AndiDog, clebs and nrb July 1, 2026 08:36
@damdo

damdo commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

/test pull-cluster-api-provider-aws-e2e

@damdo
damdo force-pushed the fix/eni-cleanup-during-deletion branch from b6cc2c7 to b50a84c Compare July 1, 2026 09:23
@damdo

damdo commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

/test pull-cluster-api-provider-aws-e2e-blocking

@damdo

damdo commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

/test pull-cluster-api-provider-aws-e2e

@clebs

clebs commented Jul 1, 2026

Copy link
Copy Markdown
Member

/lgtm

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 1, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: 21c960c01953b683f99f4b10a068790c8e49785b

@nrb nrb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One missed context.TODO(), otherwise 👍

Comment thread pkg/cloud/services/network/enis.go Outdated
eniID := aws.ToString(eni.NetworkInterfaceId)
s.scope.Debug("Deleting orphaned network interface", "eni-id", eniID)

if _, err := s.EC2Client.DeleteNetworkInterface(context.TODO(), &ec2.DeleteNetworkInterfaceInput{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if _, err := s.EC2Client.DeleteNetworkInterface(context.TODO(), &ec2.DeleteNetworkInterfaceInput{
if _, err := s.EC2Client.DeleteNetworkInterface(ctx, &ec2.DeleteNetworkInterfaceInput{

ENI deletion operations now consistently use the passed reconciliation
context instead of context.TODO(), ensuring proper timeout semantics
throughout the entire ENI cleanup phase.
@kubernetes-prow kubernetes-prow Bot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 2, 2026
@kubernetes-prow
kubernetes-prow Bot requested a review from nrb July 2, 2026 07:54
@kubernetes-prow

kubernetes-prow Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@damdo: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-provider-aws-apidiff-main 151ad7e link false /test pull-cluster-api-provider-aws-apidiff-main

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@damdo

damdo commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

/test pull-cluster-api-provider-aws-e2e

@damdo

damdo commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

/test pull-cluster-api-provider-aws-build-docker

@damdo

damdo commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

build-docker is ooming, I've created: kubernetes/test-infra#37376

@damdo

damdo commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

/test pull-cluster-api-provider-aws-build-docker

@clebs

clebs commented Jul 2, 2026

Copy link
Copy Markdown
Member

/lgtm

Re-tagging after fixing docker OOM issue.

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 2, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: bf3a730ae5f5bb3bfc6be1e7b74f4043be8ee531

@damdo

damdo commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

/test pull-cluster-api-provider-aws-e2e-eks

@damdo

damdo commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

/unhold

@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 2, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit b33921c into kubernetes-sigs:main Jul 2, 2026
18 of 19 checks passed
@damdo

damdo commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

/cherry-pick release-2.11

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@damdo: new pull request created: #6091

Details

In response to this:

/cherry-pick release-2.11

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flake] Orphaned ENIs block security group and subnet deletion during cluster teardown

7 participants