-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Sync eng/common directory with azure-sdk-tools for PR 14973 #46199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -434,11 +434,17 @@ function RemoveStorageAccount($Account) { | |||||||||
|
|
||||||||||
| try { | ||||||||||
| foreach ($container in $containers) { | ||||||||||
| $blobs = $container | Get-AzStorageBlob | ||||||||||
| foreach ($blob in $blobs) { | ||||||||||
| $shouldDelete = EnableBlobDeletion -Blob $blob -Container $container -StorageAccountName $Account.StorageAccountName -ResourceGroupName $Account.ResourceGroupName | ||||||||||
| if ($shouldDelete) { | ||||||||||
| $deleteNow += $blob | ||||||||||
| # VLW containers need version-aware cleanup: soft-delete causes deleted blobs to linger | ||||||||||
| # as non-current versions that block container deletion. See Remove-VlwContainerBlobs. | ||||||||||
| if (($container | Get-Member 'BlobContainerProperties') -and $container.BlobContainerProperties.HasImmutableStorageWithVersioning) { | ||||||||||
| Remove-VlwContainerBlobs -Container $container -StorageAccountName $Account.StorageAccountName -ResourceGroupName $Account.ResourceGroupName | ||||||||||
| } else { | ||||||||||
| $blobs = $container | Get-AzStorageBlob | ||||||||||
| foreach ($blob in $blobs) { | ||||||||||
| $shouldDelete = EnableBlobDeletion -Blob $blob -Container $container -StorageAccountName $Account.StorageAccountName -ResourceGroupName $Account.ResourceGroupName | ||||||||||
| if ($shouldDelete) { | ||||||||||
| $deleteNow += $blob | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
@@ -524,6 +530,41 @@ function EnableBlobDeletion($Blob, $Container, $StorageAccountName, $ResourceGro | |||||||||
| return $forceBlobDeletion | ||||||||||
| } | ||||||||||
|
|
||||||||||
| # In VLW (Versioned-Level WORM) containers with soft-delete enabled, deleting a blob creates a | ||||||||||
| # non-current version instead of truly removing it. A standard Get-AzStorageBlob listing can't | ||||||||||
| # see these leftovers, but they still block container deletion (409 Conflict on the management | ||||||||||
| # plane DELETE). Listing with -IncludeVersion -IncludeDeleted makes them visible so we can clear | ||||||||||
| # immutability policies / legal holds and delete each version individually. Multiple passes handle | ||||||||||
| # new non-current versions that surface after each round of deletions. | ||||||||||
| function Remove-VlwContainerBlobs($Container, $StorageAccountName, $ResourceGroupName) { | ||||||||||
| Write-Host "Cleaning VLW container '$($Container.Name)' versions and soft-deleted blobs in account '$StorageAccountName', group: $ResourceGroupName" | ||||||||||
|
|
||||||||||
| for ($round = 0; $round -lt 5; $round++) { | ||||||||||
|
||||||||||
| for ($round = 0; $round -lt 5; $round++) { | |
| $maxCleanupPasses = 5 | |
| for ($round = 0; $round -lt $maxCleanupPasses; $round++) { |
Copilot
AI
Apr 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set-AzStorageBlobLegalHold commonly does not support a -DisableLegalHold switch (many Az.Storage versions use a dedicated Clear-AzStorageBlobLegalHold cmdlet instead). Because the catch is empty, a parameter-binding failure here would be silently ignored, leaving legal holds in place and preventing deletions. Use the correct cmdlet/parameter set for clearing legal holds (and consider surfacing unexpected failures).
Copilot
AI
Apr 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple empty catch { } blocks make it very hard to distinguish expected/benign failures (e.g., missing immutability policy) from real problems (auth/permission issues, missing modules/parameters, API regressions). Consider narrowing what you suppress (e.g., only specific known error cases) and emitting at least Write-Verbose/Write-Warning for unexpected exceptions so failures don’t silently leave containers partially undeleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get-Member 'BlobContainerProperties'will emit an error when that member doesn’t exist; in runs where$ErrorActionPreference = 'Stop'(common in eng scripts), this can terminate the cleanup unexpectedly. Use a non-throwing property-existence check (e.g., PSObject properties) or add-ErrorAction SilentlyContinuetoGet-Memberand ensure the condition remains reliable.