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

Add azure_remote_url and corresponding test. #4629

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flyteadmin/pkg/common/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type CloudProvider = string
const (
AWS CloudProvider = "aws"
GCP CloudProvider = "gcp"
Azure CloudProvider = "azure"
Sandbox CloudProvider = "sandbox"
Local CloudProvider = "local"
None CloudProvider = "none"
Expand Down
6 changes: 5 additions & 1 deletion flyteadmin/pkg/data/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ func GetRemoteDataHandler(cfg RemoteDataHandlerConfig) RemoteDataHandler {
return &remoteDataHandler{
remoteURL: implementations.NewGCPRemoteURL(cfg.SigningPrincipal, signedURLDuration),
}

case common.Azure:
signedURLDuration := time.Minute * time.Duration(cfg.SignedURLDurationMinutes)
return &remoteDataHandler{
remoteURL: implementations.NewAzureRemoteURL(*cfg.RemoteDataStoreClient, signedURLDuration),
}
case common.Local:
logger.Infof(context.TODO(), "setting up local signer ----- ")
// Since minio = aws s3, we are creating the same client but using the config primitives from aws
Expand Down
46 changes: 46 additions & 0 deletions flyteadmin/pkg/data/implementations/azure_remote_url.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package implementations

import (
"context"
"github.com/flyteorg/flyte/flyteadmin/pkg/data/interfaces"
"github.com/flyteorg/flyte/flyteadmin/pkg/errors"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flyte/flytestdlib/storage"
"github.com/flyteorg/stow"
"google.golang.org/grpc/codes"
"time"
)

type AzureRemoteURL struct {
remoteDataStoreClient storage.DataStore
presignDuration time.Duration
}

func (n *AzureRemoteURL) Get(ctx context.Context, uri string) (admin.UrlBlob, error) {
metadata, err := n.remoteDataStoreClient.Head(ctx, storage.DataReference(uri))
if err != nil {
return admin.UrlBlob{}, errors.NewFlyteAdminErrorf(codes.Internal,
"failed to get metadata for uri: %s with err: %v", uri, err)
}

signedUri, err := n.remoteDataStoreClient.CreateSignedURL(ctx, storage.DataReference(uri), storage.SignedURLProperties{
Scope: stow.ClientMethodGet,
ExpiresIn: n.presignDuration,
})
if err != nil {
return admin.UrlBlob{}, errors.NewFlyteAdminErrorf(codes.Internal,
"failed to get metadata for uri: %s with err: %v", uri, err)
}

return admin.UrlBlob{
Url: signedUri.URL.String(),
Bytes: metadata.Size(),
}, nil
}

func NewAzureRemoteURL(remoteDataStoreClient storage.DataStore, presignDuration time.Duration) interfaces.RemoteURLInterface {
return &AzureRemoteURL{

Check failure on line 42 in flyteadmin/pkg/data/implementations/azure_remote_url.go

View workflow job for this annotation

GitHub Actions / compile

cannot use &AzureRemoteURL{…} (value of type *AzureRemoteURL) as interfaces.RemoteURLInterface value in return statement: *AzureRemoteURL does not implement interfaces.RemoteURLInterface (wrong type for method Get)
remoteDataStoreClient: remoteDataStoreClient,
presignDuration: presignDuration,
}
}
38 changes: 38 additions & 0 deletions flyteadmin/pkg/data/implementations/azure_remote_url_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package implementations

import (
"context"
commonMocks "github.com/flyteorg/flyte/flyteadmin/pkg/common/mocks"
"github.com/flyteorg/flyte/flytestdlib/storage"
"github.com/stretchr/testify/assert"
"testing"
)

type mockMetadata struct{}

func (m mockMetadata) Exists() bool {
return true
}

func (m mockMetadata) Size() int64 {
return 1
}

func (m mockMetadata) Etag() string {
return "etag"
}

func TestAzureGet(t *testing.T) {
inputUri := "abfs//test/data"
mockStorage := commonMocks.GetMockStorageClient()
mockStorage.ComposedProtobufStore.(*commonMocks.TestDataStore).HeadCb =
func(ctx context.Context, reference storage.DataReference) (storage.Metadata, error) {
return mockMetadata{}, nil
}
remoteURL := AzureRemoteURL{
remoteDataStoreClient: *mockStorage, presignDuration: 1,
}

result, _ := remoteURL.Get(context.TODO(), inputUri)
assert.Contains(t, inputUri, result.Url)
}
Loading