Sync eng/common directory with azure-sdk-tools for PR 14973#48731
Sync eng/common directory with azure-sdk-tools for PR 14973#48731
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Syncs eng/common with updates from azure-sdk-tools PR 14973, adding special-case cleanup for VLW (Versioned-Level WORM) containers to ensure storage container/account deletion succeeds when versioning + soft-delete leave behind non-current versions.
Changes:
- Add VLW-aware blob cleanup path during storage account removal.
- Introduce
Remove-VlwContainerBlobsto enumerate and delete blob versions / soft-deleted blobs and clear holds/policies.
| if (($container | Get-Member 'BlobContainerProperties') -and $container.BlobContainerProperties.HasImmutableStorageWithVersioning) { | ||
| Remove-VlwContainerBlobs -Container $container -StorageAccountName $Account.StorageAccountName -ResourceGroupName $Account.ResourceGroupName | ||
| } else { |
There was a problem hiding this comment.
Get-Member is relatively expensive and is executed once per container in the deletion loop. Prefer a property existence check via PSObject.Properties (or equivalent) instead of Get-Member so this scales better when many containers are present.
|
|
||
| for ($round = 0; $round -lt 5; $round++) { | ||
| $found = $false | ||
| $blobs = @($Container | Get-AzStorageBlob -IncludeVersion -IncludeDeleted -ErrorAction SilentlyContinue) |
There was a problem hiding this comment.
Using -ErrorAction SilentlyContinue here can mask real failures (auth/permission issues, transient storage errors). If listing fails, $blobs becomes empty and the function will silently stop, likely leaving the container undeletable. Recommend handling errors explicitly (e.g., capture and emit a warning/error) so the caller has actionable diagnostics when cleanup cannot proceed.
| $blobs = @($Container | Get-AzStorageBlob -IncludeVersion -IncludeDeleted -ErrorAction SilentlyContinue) | |
| try { | |
| $blobs = @($Container | Get-AzStorageBlob -IncludeVersion -IncludeDeleted -ErrorAction Stop) | |
| } catch { | |
| Write-Error "Failed to list blobs for VLW container '$($Container.Name)' in storage account '$StorageAccountName', resource group '$ResourceGroupName'. Cleanup cannot continue. $($_.Exception.Message)" | |
| throw | |
| } |
| 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++) { |
There was a problem hiding this comment.
The hard-coded max pass count (5) is a magic number that’s difficult to tune if behavior changes. Consider making it a parameter with a default (or at least a named constant) and, if the limit is reached while still finding blobs, return/throw a clear failure so the caller knows cleanup may be incomplete.
| # 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" |
There was a problem hiding this comment.
Write-Host is difficult to control in CI logs (can’t be suppressed via standard preference variables and can be noisy). Prefer Write-Verbose/Write-Information (or whatever this script uses elsewhere) so callers can opt into detailed logging without always emitting host output.
| Write-Host "Cleaning VLW container '$($Container.Name)' versions and soft-deleted blobs in account '$StorageAccountName', group: $ResourceGroupName" | |
| Write-Verbose "Cleaning VLW container '$($Container.Name)' versions and soft-deleted blobs in account '$StorageAccountName', group: $ResourceGroupName" |
Sync eng/common directory with azure-sdk-tools for PR Azure/azure-sdk-tools#14973 See eng/common workflow