Skip to content

Commit a929c8f

Browse files
tczhaoagilgur5
andauthored
fix: allow artifact gc to delete directory. Fixes argoproj#12857 (argoproj#13091)
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>
1 parent d1f2f01 commit a929c8f

File tree

1 file changed

+18
-1
lines changed
  • workflow/artifacts/s3

1 file changed

+18
-1
lines changed

workflow/artifacts/s3/s3.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"os"
10+
"strings"
1011

1112
"github.com/argoproj/pkg/file"
1213
argos3 "github.com/argoproj/pkg/s3"
@@ -180,7 +181,23 @@ func (s3Driver *ArtifactDriver) Delete(artifact *wfv1.Artifact) error {
180181
if err != nil {
181182
return err
182183
}
183-
return s3cli.Delete(artifact.S3.Bucket, artifact.S3.Key)
184+
185+
// check suffix instead of s3cli.IsDirectory as it requires another request for file delete (most scenarios)
186+
if !strings.HasSuffix(artifact.S3.Key, "/") {
187+
return s3cli.Delete(artifact.S3.Bucket, artifact.S3.Key)
188+
}
189+
190+
keys, err := s3cli.ListDirectory(artifact.S3.Bucket, artifact.S3.Key)
191+
if err != nil {
192+
return fmt.Errorf("unable to list files in %s: %s", artifact.S3.Key, err)
193+
}
194+
for _, objKey := range keys {
195+
err = s3cli.Delete(artifact.S3.Bucket, objKey)
196+
if err != nil {
197+
return err
198+
}
199+
}
200+
return nil
184201
})
185202

186203
return err

0 commit comments

Comments
 (0)