Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Delete all blobs when container has immutability
  • Loading branch information
benbp authored and azure-sdk committed Nov 6, 2024
commit fb2ce9ce0e427de1ce87b09ad99232f4a22c91a9
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