Skip to content

Commit

Permalink
fix(artifacts): minor refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Peixuan Ding <dingpeixuan911@gmail.com>
  • Loading branch information
dinever committed Apr 13, 2021
1 parent fdc209a commit 513a4b5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package s3

import argos3 "github.com/argoproj/pkg/s3"

// s3TransientErrorCodes is a list of S3 error codes that are transient (retryable)
// Reference: https://github.com/minio/minio-go/blob/92fe50d14294782d96402deb861d442992038109/retry.go#L90-L102
var s3TransientErrorCodes = []string{
Expand All @@ -12,3 +14,16 @@ var s3TransientErrorCodes = []string{
"InternalError",
"SlowDown",
}

// isTransientS3Err checks if an minio.ErrorResponse error is transient (retryable)
func isTransientS3Err(err error) bool {
if err == nil {
return false
}
for _, transientErrCode := range s3TransientErrorCodes {
if argos3.IsS3ErrCode(err, transientErrCode) {
return true
}
}
return false
}
22 changes: 22 additions & 0 deletions workflow/artifacts/s3/errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package s3

import (
"errors"
"testing"

"github.com/minio/minio-go/v7"
"github.com/stretchr/testify/assert"
)

func TestIsTransientOSSErr(t *testing.T) {
for _, errCode := range s3TransientErrorCodes {
err := minio.ErrorResponse{Code: errCode}
assert.True(t, isTransientS3Err(err))
}

err := minio.ErrorResponse{Code: "NoSuchBucket"}
assert.False(t, isTransientS3Err(err))

nonOSSErr := errors.New("UnseenError")
assert.False(t, isTransientS3Err(nonOSSErr))
}
13 changes: 0 additions & 13 deletions workflow/artifacts/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,3 @@ func (s3Driver *ArtifactDriver) ListObjects(artifact *wfv1.Artifact) ([]string,

return files, err
}

// isTransientS3Err checks if an minio.ErrorResponse error is transient (retryable)
func isTransientS3Err(err error) bool {
if err == nil {
return false
}
for _, transientErrCode := range s3TransientErrorCodes {
if argos3.IsS3ErrCode(err, transientErrCode) {
return true
}
}
return false
}
14 changes: 0 additions & 14 deletions workflow/artifacts/s3/s3_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package s3

import (
"errors"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -360,16 +359,3 @@ func TestSaveS3Artifact(t *testing.T) {
})
}
}

func TestIsTransientOSSErr(t *testing.T) {
for _, errCode := range s3TransientErrorCodes {
err := minio.ErrorResponse{Code: errCode}
assert.True(t, isTransientS3Err(err))
}

err := minio.ErrorResponse{Code: "NoSuchBucket"}
assert.False(t, isTransientS3Err(err))

nonOSSErr := errors.New("UnseenError")
assert.False(t, isTransientS3Err(nonOSSErr))
}

0 comments on commit 513a4b5

Please sign in to comment.