Skip to content

Handle Azure NIC reservation during VM deletion#359

Merged
apoorvajagtap merged 1 commit into
rancher:masterfrom
apoorvajagtap:8916-azureresources
Jun 26, 2026
Merged

Handle Azure NIC reservation during VM deletion#359
apoorvajagtap merged 1 commit into
rancher:masterfrom
apoorvajagtap:8916-azureresources

Conversation

@apoorvajagtap

@apoorvajagtap apoorvajagtap commented Feb 9, 2026

Copy link
Copy Markdown

Issue: rancher/rancher#47903

Azure may temporarily retain NIC reservations after VM deletion or failed VM provisioning, causing cleanup to fail with the NicReservedForAnotherVm error.

This commit:

  • Implements exponential backoff retry for reserved NIC deletion (2s initial, capped at 180s total).
  • Handles context cancellation during wait periods

This improves cleanup reliability by preventing orphaned NICs and, consequently, orphaned Public IPs.

Test Validation:

  • Please refer To Reproduce section on the issue.

@apoorvajagtap apoorvajagtap marked this pull request as draft February 9, 2026 10:27
@apoorvajagtap apoorvajagtap force-pushed the 8916-azureresources branch 4 times, most recently from da29daa to a1a26d4 Compare February 9, 2026 18:49
@apoorvajagtap

Copy link
Copy Markdown
Author

I think proactively detaching NICs from VMs during cleanup could be a more robust approach, as it would help avoid orphaned resources and also allow for better parallelization. If this sounds like a preferable alternative, I’d be happy to explore its feasibility. (ref)

@apoorvajagtap apoorvajagtap marked this pull request as ready for review February 9, 2026 19:02
@apoorvajagtap apoorvajagtap changed the title [WIP] Handle Azure NIC reservation during VM deletion Handle Azure NIC reservation during VM deletion Feb 9, 2026
@apoorvajagtap apoorvajagtap requested review from a team and jakefhyde February 9, 2026 19:06
Comment thread drivers/azure/azure.go Outdated

@jakefhyde jakefhyde left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 nit

@snasovich snasovich requested a review from a team April 8, 2026 16:53
jakefhyde
jakefhyde previously approved these changes Jun 2, 2026
@snasovich snasovich requested a review from a team June 3, 2026 21:30
@jiaqiluo jiaqiluo requested a review from Copilot June 9, 2026 18:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves Azure resource cleanup reliability by handling the transient NicReservedForAnotherVm condition that can occur after VM deletion or failed provisioning, which otherwise can leave orphaned NICs (and consequently Public IPs).

Changes:

  • Adds a maxRetryDuration constant (180s) used to wait out Azure’s NIC reservation window.
  • Updates DeleteNetworkInterfaceIfExists to detect the NIC-reserved error, wait, and retry NIC deletion once, while respecting context cancellation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread drivers/azure/azureutil/azureutil.go
Comment thread drivers/azure/azureutil/azureutil.go Outdated

@jiaqiluo jiaqiluo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left one comment. Also, please review the Copilot comments.

FYI, this repo is not branched for Rancher release lines, so you might need to backport the changes to other lines.

Comment thread drivers/azure/azureutil/azureutil.go Outdated
@Sahota1225 Sahota1225 requested a review from a team June 16, 2026 15:17
@apoorvajagtap apoorvajagtap merged commit a057776 into rancher:master Jun 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants