Skip to content

Sync eng/common directory with azure-sdk-tools for PR 14973#46199

Open
azure-sdk wants to merge 2 commits intomainfrom
sync-eng/common-storage/supportSoftDeletedBlobsDuringResourceCleanup-14973
Open

Sync eng/common directory with azure-sdk-tools for PR 14973#46199
azure-sdk wants to merge 2 commits intomainfrom
sync-eng/common-storage/supportSoftDeletedBlobsDuringResourceCleanup-14973

Conversation

@azure-sdk
Copy link
Copy Markdown
Collaborator

Sync eng/common directory with azure-sdk-tools for PR Azure/azure-sdk-tools#14973 See eng/common workflow

ibrandes and others added 2 commits April 8, 2026 18:31
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@azure-sdk azure-sdk requested a review from ibrandes April 8, 2026 18:40
@azure-sdk azure-sdk requested a review from a team as a code owner April 8, 2026 18:40
@azure-sdk azure-sdk added EngSys This issue is impacting the engineering system. Central-EngSys This issue is owned by the Engineering System team. labels Apr 8, 2026
Copilot AI review requested due to automatic review settings April 8, 2026 18:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Syncs eng/common with changes from azure-sdk-tools PR 14973, improving storage account cleanup by adding version-aware deletion for VLW (versioned immutable) blob containers so containers can be deleted successfully.

Changes:

  • Adds VLW-container detection during storage account cleanup and routes those containers through specialized cleanup.
  • Introduces Remove-VlwContainerBlobs to delete soft-deleted blobs and non-current versions (including clearing legal hold / immutability policy).
  • Adds inline documentation explaining why standard blob listing doesn’t unblock container deletion in VLW scenarios.

Comment on lines +439 to +441
if (($container | Get-Member 'BlobContainerProperties') -and $container.BlobContainerProperties.HasImmutableStorageWithVersioning) {
Remove-VlwContainerBlobs -Container $container -StorageAccountName $Account.StorageAccountName -ResourceGroupName $Account.ResourceGroupName
} else {
Copy link

Copilot AI Apr 8, 2026

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 SilentlyContinue to Get-Member and ensure the condition remains reliable.

Copilot uses AI. Check for mistakes.
Comment on lines +551 to +552
try { $blob | Set-AzStorageBlobLegalHold -DisableLegalHold | Out-Null } catch { }
try { $blob | Remove-AzStorageBlobImmutabilityPolicy | Out-Null } catch { }
Copy link

Copilot AI Apr 8, 2026

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 uses AI. Check for mistakes.
Comment on lines +549 to +561
# Unconditionally clear legal holds and immutability policies. Errors are expected for
# soft-deleted blobs or blobs that don't have these set.
try { $blob | Set-AzStorageBlobLegalHold -DisableLegalHold | Out-Null } catch { }
try { $blob | Remove-AzStorageBlobImmutabilityPolicy | Out-Null } catch { }
try {
$blob | Remove-AzStorageBlob -Force
} catch {
# Deleting the current version by version ID returns 403
# (OperationNotAllowedOnRootBlob); fall back to base blob deletion.
try {
Remove-AzStorageBlob -Container $Container.Name -Blob $blob.Name -Context $Container.Context -Force
} catch { }
}
Copy link

Copilot AI Apr 8, 2026

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.

Copilot uses AI. Check for mistakes.
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++) {
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

The retry bound 5 is a magic number. Consider making it a named constant or a parameter (defaulting to 5) so callers can tune the behavior and future maintainers understand/adjust the limit without editing logic.

Suggested change
for ($round = 0; $round -lt 5; $round++) {
$maxCleanupPasses = 5
for ($round = 0; $round -lt $maxCleanupPasses; $round++) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Central-EngSys This issue is owned by the Engineering System team. EngSys This issue is impacting the engineering system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants