Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement OpenStream func of OSS artifactdriver. Part of #8489 #12908

Merged
merged 1 commit into from
May 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 39 additions & 3 deletions workflow/artifacts/oss/oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,45 @@ func (ossDriver *ArtifactDriver) Load(inputArtifact *wfv1.Artifact, path string)
return err
}

func (ossDriver *ArtifactDriver) OpenStream(a *wfv1.Artifact) (io.ReadCloser, error) {
// todo: this is a temporary implementation which loads file to disk first
return common.LoadToStream(a, ossDriver)
// OpenStream opens a stream reader for an artifact from OSS compliant storage
func (ossDriver *ArtifactDriver) OpenStream(inputArtifact *wfv1.Artifact) (io.ReadCloser, error) {
var stream io.ReadCloser
err := waitutil.Backoff(defaultRetry,
func() (bool, error) {
log.Infof("OSS OpenStream, key: %s", inputArtifact.OSS.Key)
osscli, err := ossDriver.newOSSClient()
if err != nil {
return !isTransientOSSErr(err), err
}
bucketName := inputArtifact.OSS.Bucket
err = setBucketLogging(osscli, bucketName)
if err != nil {
return !isTransientOSSErr(err), err
}
bucket, err := osscli.Bucket(bucketName)
if err != nil {
return !isTransientOSSErr(err), err
}
s, origErr := bucket.GetObject(inputArtifact.OSS.Key)
if origErr == nil {
stream = s
return true, nil
}
if !IsOssErrCode(err, "NoSuchKey") {
return !isTransientOSSErr(origErr), fmt.Errorf("failed to get file: %w", origErr)
}
isDir, err := IsOssDirectory(bucket, inputArtifact.OSS.Key)
if err != nil {
return !isTransientOSSErr(err), fmt.Errorf("failed to test if %s/%s is a directory: %w", bucketName, inputArtifact.OSS.Key, err)
}
if !isDir {
return false, origErr
}
// directory case:
// todo: make a .tgz file which can be streamed to user
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we implement this in the same PR?

Copy link
Contributor Author

@AlbeeSo AlbeeSo Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that OSS SDK (or S3 also) does not currently support operations like "GetObjectsWithPrefix" to a .tgz file. So the only way might be to list objects with prefix first, load, tar them then and stream the .tgz file to user finally, more like a "LoadToStream" way.
https://github.com/argoproj/argo-workflows/blob/34967127bfe304da0f72dc1dba63558a1609b2d0/server/artifacts/artifact_server.go#L184C1-L233C36
Maybe it would be better to still return an html page?

return false, errors.New(errors.CodeNotImplemented, "Directory Stream capability currently unimplemented for OSS")
})
return stream, err
}

// Save stores an artifact to OSS compliant storage, e.g., uploading a local file to OSS bucket
Expand Down