Skip to content

Commit

Permalink
fix(gcs): backoff bool should be false if error is transient (#6577)
Browse files Browse the repository at this point in the history
Signed-off-by: AntoineDao <antoinedao1@gmail.com>
  • Loading branch information
AntoineDao authored and sarabala1979 committed Sep 3, 2021
1 parent 2af306a commit 940e993
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
28 changes: 24 additions & 4 deletions workflow/artifacts/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ func (g *ArtifactDriver) Load(inputArtifact *wfv1.Artifact, path string) error {
gcsClient, err := g.newGCSClient()
if err != nil {
log.Warnf("Failed to create new GCS client: %v", err)
return isTransientGCSErr(err), err
return !isTransientGCSErr(err), err
}
defer gcsClient.Close()
err = downloadObjects(gcsClient, inputArtifact.GCS.Bucket, inputArtifact.GCS.Key, path)
if err != nil {
log.Warnf("Failed to download objects from GCS: %v", err)
return isTransientGCSErr(err), err
return !isTransientGCSErr(err), err
}
return true, nil
})
Expand Down Expand Up @@ -203,12 +203,12 @@ func (g *ArtifactDriver) Save(path string, outputArtifact *wfv1.Artifact) error
log.Infof("GCS Save path: %s, key: %s", path, outputArtifact.GCS.Key)
client, err := g.newGCSClient()
if err != nil {
return isTransientGCSErr(err), err
return !isTransientGCSErr(err), err
}
defer client.Close()
err = uploadObjects(client, outputArtifact.GCS.Bucket, outputArtifact.GCS.Key, path)
if err != nil {
return isTransientGCSErr(err), err
return !isTransientGCSErr(err), err
}
return true, nil
})
Expand Down Expand Up @@ -294,5 +294,25 @@ func uploadObject(client *storage.Client, bucket, key, localPath string) error {
}

func (g *ArtifactDriver) ListObjects(artifact *wfv1.Artifact) ([]string, error) {
<<<<<<< HEAD
return nil, fmt.Errorf("ListObjects is currently not supported for this artifact type, but it will be in a future version")
=======
var files []string
err := waitutil.Backoff(defaultRetry,
func() (bool, error) {
log.Infof("GCS List bucekt: %s, key: %s", artifact.GCS.Bucket, artifact.GCS.Key)
client, err := g.newGCSClient()
if err != nil {
log.Warnf("Failed to create new GCS client: %v", err)
return !isTransientGCSErr(err), err
}
defer client.Close()
files, err = listByPrefix(client, artifact.GCS.Bucket, artifact.GCS.Key, "")
if err != nil {
return !isTransientGCSErr(err), err
}
return true, nil
})
return files, err
>>>>>>> 30340c427... fix(gcs): backoff bool should be false if error is transient (#6577)
}
3 changes: 3 additions & 0 deletions workflow/artifacts/gcs/gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"testing"

"google.golang.org/api/googleapi"

argoErrors "github.com/argoproj/argo-workflows/v3/errors"
)

type tlsHandshakeTimeoutError struct{}
Expand All @@ -21,6 +23,7 @@ func TestIsTransientGCSErr(t *testing.T) {
shouldretry bool
}{
{&googleapi.Error{Code: 0}, false},
{argoErrors.New(argoErrors.CodeNotFound, "no results for key: foo/bar"), false},
{&googleapi.Error{Code: 429}, true},
{&googleapi.Error{Code: 518}, true},
{&googleapi.Error{Code: 599}, true},
Expand Down

0 comments on commit 940e993

Please sign in to comment.