Skip to content

Commit

Permalink
fix: allow azure blobs to not exist when deleting (#11070)
Browse files Browse the repository at this point in the history
Signed-off-by: Roel Arents <roel.arents@kadaster.nl>
Signed-off-by: Dirc <e.e.cornet@gmail.com>
Co-authored-by: Dirc <e.e.cornet@gmail.com>
Co-authored-by: Yuan Tang <terrytangyuan@gmail.com>
  • Loading branch information
3 people committed May 25, 2023
1 parent 55dc31d commit 32c76c8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions workflow/artifacts/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (azblobDriver *ArtifactDriver) Delete(artifact *wfv1.Artifact) error {
}

if !isDir {
return DeleteBlob(containerClient, artifact.Azure.Blob)
return DeleteBlob(containerClient, artifact.Azure.Blob, true)
} else {
files, err := azblobDriver.ListObjects(artifact)
if err != nil {
Expand All @@ -335,26 +335,31 @@ func (azblobDriver *ArtifactDriver) Delete(artifact *wfv1.Artifact) error {
continue
}

if err := DeleteBlob(containerClient, file); err != nil {
if err := DeleteBlob(containerClient, file, true); err != nil {
return err
}
}
if directoryFile != "" {
return DeleteBlob(containerClient, directoryFile)
return DeleteBlob(containerClient, directoryFile, true)
}
}
return nil
}

func DeleteBlob(containerClient *azblob.ContainerClient, blobName string) error {
func DeleteBlob(containerClient *azblob.ContainerClient, blobName string, allowNonExistent bool) error {
blobClient, err := containerClient.NewBlobClient(blobName)
if err != nil {
return fmt.Errorf("unable to create Azure Blob client for %s: %s", blobName, err)
}

_, err = blobClient.Delete(context.TODO(), nil)
if err != nil {
return fmt.Errorf("unable to delete Azure Blob %s: %s", blobName, err)
if allowNonExistent && IsAzureError(err, azblob.StorageErrorCodeBlobNotFound) {
log.Debugf("blob to delete '%s' does not exist: %s", blobName, err)
return nil
} else {
return fmt.Errorf("unable to delete Azure Blob %s: %s", blobName, err)
}
}

return err
Expand Down

0 comments on commit 32c76c8

Please sign in to comment.