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

[WIP]test: create file share with data plane api using Oauth #2320

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions pkg/azurefile/azurefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,13 @@ func (d *Driver) CreateFileShare(ctx context.Context, accountOptions *azure.Acco
if fileClient, err = newAzureFileClient(accountName, accountKey, d.getStorageEndPointSuffix(), &retry.Backoff{Steps: 1}); err != nil {
return true, err
}
} else if accountOptions.Name != "" {
return true, CreateFileShareWithOAuth(ctx, d.cloud.AuthProvider.GetAzIdentity(), accountOptions.Name, shareOptions, d.getStorageEndPointSuffix(), &retry.Backoff{Steps: 1})
/*
if fileClient, err = newAzureFileClientWithOAuth(d.cloud.AuthProvider.GetAzIdentity(), accountOptions.Name, d.getStorageEndPointSuffix(), &retry.Backoff{Steps: 1}); err != nil {
return true, err
}
*/
} else {
if fileClient, err = newAzureFileMgmtClient(d.cloud.ComputeClientFactory, accountOptions); err != nil {
return true, err
Expand Down
51 changes: 51 additions & 0 deletions pkg/azurefile/azurefile_dataplane_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"fmt"
"net/http"

"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
Expand Down Expand Up @@ -76,6 +77,56 @@
}, nil
}

func newAzureFileClientWithOAuth(cred azcore.TokenCredential, accountName, storageEndpointSuffix string, backoff *retry.Backoff) (azureFileClient, error) {

Check failure on line 80 in pkg/azurefile/azurefile_dataplane_client.go

View workflow job for this annotation

GitHub Actions / Go Lint

func `newAzureFileClientWithOAuth` is unused (unused)

Check failure on line 80 in pkg/azurefile/azurefile_dataplane_client.go

View workflow job for this annotation

GitHub Actions / Go Lint

func `newAzureFileClientWithOAuth` is unused (unused)
if storageEndpointSuffix == "" {
storageEndpointSuffix = defaultStorageEndPointSuffix
}
storageEndpoint := fmt.Sprintf("https://%s.file."+storageEndpointSuffix, accountName)
clientOps := utils.GetDefaultAzCoreClientOption()
if backoff != nil {
clientOps.Retry.MaxRetries = int32(backoff.Steps)
clientOps.Retry.StatusCodes = defaultValidStatusCodes
clientOps.Retry.RetryDelay = backoff.Duration
}
fileClient, err := service.NewClient(storageEndpoint, cred, &service.ClientOptions{
ClientOptions: clientOps,
})
if err != nil {
return nil, fmt.Errorf("error creating azure client: %v", err)
}

klog.V(2).Infof("created azure file client with oauth, accountName: %s", accountName)

return &azureFileDataplaneClient{
accountName: accountName,
Client: fileClient,
}, nil
}

func CreateFileShareWithOAuth(ctx context.Context, cred azcore.TokenCredential, accountName string, shareOptions *ShareOptions, storageEndpointSuffix string, backoff *retry.Backoff) error {
if storageEndpointSuffix == "" {
storageEndpointSuffix = defaultStorageEndPointSuffix
}
storageEndpoint := fmt.Sprintf("https://%s.file.%s/%s", accountName, storageEndpointSuffix, shareOptions.Name)
clientOps := utils.GetDefaultAzCoreClientOption()
if backoff != nil {
clientOps.Retry.MaxRetries = int32(backoff.Steps)
clientOps.Retry.StatusCodes = defaultValidStatusCodes
clientOps.Retry.RetryDelay = backoff.Duration
}
shareClient, err := share.NewClient(storageEndpoint, cred, &share.ClientOptions{
ClientOptions: clientOps,
})
if err != nil {
return fmt.Errorf("error creating azure client: %v", err)
}
klog.V(2).Infof("created azure file share %s with oauth, accountName: %s", shareOptions.Name, accountName)
_, err = shareClient.Create(ctx, &share.CreateOptions{
Quota: to.Ptr(int32(shareOptions.RequestGiB)),
})
return err
}

func (f *azureFileDataplaneClient) CreateFileShare(ctx context.Context, shareOptions *ShareOptions) error {
if shareOptions == nil {
return fmt.Errorf("shareOptions of account(%s) is nil", f.accountName)
Expand Down
Loading