Skip to content

Commit

Permalink
fix: allow artifact gc to delete directory. Fixes #12857 (#13091)
Browse files Browse the repository at this point in the history
Signed-off-by: Tianchu Zhao <[email protected]>
Signed-off-by: Anton Gilgur <[email protected]>
Co-authored-by: Anton Gilgur <[email protected]>
(cherry picked from commit a929c8f)
  • Loading branch information
tczhao authored and Anton Gilgur committed Jul 6, 2024
1 parent ecb2b39 commit 84a5af1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion workflow/artifacts/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"os"
"strings"

"github.com/argoproj/pkg/file"
argos3 "github.com/argoproj/pkg/s3"
Expand Down Expand Up @@ -180,7 +181,23 @@ func (s3Driver *ArtifactDriver) Delete(artifact *wfv1.Artifact) error {
if err != nil {
return err
}
return s3cli.Delete(artifact.S3.Bucket, artifact.S3.Key)

// check suffix instead of s3cli.IsDirectory as it requires another request for file delete (most scenarios)
if !strings.HasSuffix(artifact.S3.Key, "/") {
return s3cli.Delete(artifact.S3.Bucket, artifact.S3.Key)
}

keys, err := s3cli.ListDirectory(artifact.S3.Bucket, artifact.S3.Key)
if err != nil {
return fmt.Errorf("unable to list files in %s: %s", artifact.S3.Key, err)
}
for _, objKey := range keys {
err = s3cli.Delete(artifact.S3.Bucket, objKey)
if err != nil {
return err
}
}
return nil
})

return err
Expand Down

0 comments on commit 84a5af1

Please sign in to comment.