Skip to content

Commit

Permalink
Delete all blobs when container has immutability
Browse files Browse the repository at this point in the history
  • Loading branch information
benbp authored and azure-sdk committed Nov 5, 2024
1 parent 80ef9d3 commit f435610
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions eng/common/scripts/Helpers/Resource-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,9 @@ function RemoveStorageAccount($Account) {
if ($container.BlobContainerProperties.HasImmutableStorageWithVersioning) {
try {
# Use AzRm cmdlet as deletion will only work through ARM with the immutability policies defined on the blobs
# If blob deletion takes longer then the container delete
# will fail, so retry a couple times
Retry -Action { Remove-AzRmStorageContainer -Name $container.Name -StorageAccountName $Account.StorageAccountName -ResourceGroupName $Account.ResourceGroupName -Force } -Attempts 2
#$container | Remove-AzStorageContainer
# Add a retry in case blob deletion has not finished in time for container deletion, but not too many that we end up
# getting throttled by ARM/SRP if things are actually in a stuck state
Retry -Attempts 1 -Action { Remove-AzRmStorageContainer -Name $container.Name -StorageAccountName $Account.StorageAccountName -ResourceGroupName $Account.ResourceGroupName -Force }
} catch {
Write-Host "Container removal failed: $($container.Name), account: $($Account.storageAccountName), group: $($Account.ResourceGroupName)"
Write-Warning "Ignoring the error and trying to delete the storage account"
Expand All @@ -362,7 +361,7 @@ function RemoveStorageAccount($Account) {
}
}

function EnableBlobDeletion($Blob, $StorageAccountName, $ResourceGroupName) {
function EnableBlobDeletion($Blob, $Container, $StorageAccountName, $ResourceGroupName) {
# Some properties like immutability policies require the blob to be
# deleted before the container can be deleted
$forceBlobDeletion = $false
Expand Down Expand Up @@ -396,6 +395,10 @@ function EnableBlobDeletion($Blob, $StorageAccountName, $ResourceGroupName) {
$Blob.ICloudBlob.BreakLease()
}

if ($container.BlobContainerProperties.HasImmutableStorageWithVersioning) {
$forceBlobDeletion = $true
}

return $forceBlobDeletion
}

Expand Down

0 comments on commit f435610

Please sign in to comment.