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 <evantczhao@gmail.com>
Signed-off-by: Anton Gilgur <4970083+agilgur5@users.noreply.github.com>
Co-authored-by: Anton Gilgur <4970083+agilgur5@users.noreply.github.com>
  • Loading branch information
tczhao and agilgur5 authored Jul 3, 2024
1 parent d1f2f01 commit a929c8f
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 a929c8f

Please sign in to comment.