Skip to content

Commit 480d729

Browse files
committed
migrate azfile data plane client to track2 one
Signed-off-by: Fan Shang Xiang <shafan@microsoft.com>
1 parent 180793b commit 480d729

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+75
-9841
lines changed

go.mod

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ require (
1515
github.com/Azure/go-autorest/autorest/to v0.4.0
1616
github.com/container-storage-interface/spec v1.9.0
1717
github.com/golang/protobuf v1.5.4
18+
github.com/google/uuid v1.6.0
1819
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
1920
github.com/kubernetes-csi/csi-lib-utils v0.14.1
2021
github.com/kubernetes-csi/csi-proxy/client v1.0.1
2122
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
2223
github.com/onsi/ginkgo/v2 v2.20.2
2324
github.com/onsi/gomega v1.34.2
24-
github.com/pborman/uuid v1.2.0
2525
github.com/rubiojr/go-vhd v0.0.0-20200706105327-02e210299021
2626
github.com/stretchr/testify v1.9.0
2727
go.uber.org/mock v0.4.0
@@ -87,7 +87,6 @@ require (
8787
github.com/go-openapi/jsonreference v0.21.0 // indirect
8888
github.com/go-openapi/swag v0.23.0 // indirect
8989
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
90-
github.com/gofrs/uuid v4.4.0+incompatible // indirect
9190
github.com/gogo/protobuf v1.3.2 // indirect
9291
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
9392
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
@@ -97,7 +96,6 @@ require (
9796
github.com/google/go-cmp v0.6.0 // indirect
9897
github.com/google/gofuzz v1.2.0 // indirect
9998
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 // indirect
100-
github.com/google/uuid v1.6.0 // indirect
10199
github.com/gorilla/websocket v1.5.0 // indirect
102100
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
103101
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect

go.sum

-7
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,6 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
745745
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
746746
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
747747
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
748-
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
749-
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
750748
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
751749
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
752750
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
@@ -839,8 +837,6 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v
839837
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
840838
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
841839
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
842-
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
843-
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
844840
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
845841
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
846842
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
@@ -946,7 +942,6 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
946942
github.com/google/s2a-go v0.1.0/go.mod h1:OJpEgntRZo8ugHpF9hkoLJbS5dSI20XZeXJ9JVywLlM=
947943
github.com/google/s2a-go v0.1.3/go.mod h1:Ej+mSEMGRnqRzjc7VtF+jdBwYG5fuJfiZ8ELkjEwM0A=
948944
github.com/google/s2a-go v0.1.4/go.mod h1:Ej+mSEMGRnqRzjc7VtF+jdBwYG5fuJfiZ8ELkjEwM0A=
949-
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
950945
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
951946
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
952947
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -1131,8 +1126,6 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
11311126
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
11321127
github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU=
11331128
github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec=
1134-
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
1135-
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
11361129
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
11371130
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
11381131
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=

pkg/azurefile/azurefile.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-09-01/storage"
3232
"github.com/Azure/azure-storage-file-go/azfile"
3333
"github.com/container-storage-interface/spec/lib/go/csi"
34+
"github.com/google/uuid"
3435
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
35-
"github.com/pborman/uuid"
3636
"github.com/rubiojr/go-vhd/vhd"
3737
"google.golang.org/grpc"
3838
"google.golang.org/grpc/codes"
@@ -632,7 +632,7 @@ func getValidFileShareName(volumeName string) string {
632632
fileShareName = fileShareName[0:fileShareNameMaxLength]
633633
}
634634
if !checkShareNameBeginAndEnd(fileShareName) || len(fileShareName) < fileShareNameMinLength {
635-
fileShareName = util.GenerateVolumeName("pvc-file", uuid.NewUUID().String(), fileShareNameMaxLength)
635+
fileShareName = util.GenerateVolumeName("pvc-file", uuid.NewString(), fileShareNameMaxLength)
636636
klog.Warningf("the requested volume name (%q) is invalid, so it is regenerated as (%q)", volumeName, fileShareName)
637637
}
638638
fileShareName = strings.Replace(fileShareName, "--", "-", -1)
@@ -916,22 +916,27 @@ func (d *Driver) CreateFileShare(ctx context.Context, accountOptions *azure.Acco
916916
return wait.ExponentialBackoff(d.cloud.RequestBackoff(), func() (bool, error) {
917917
var err error
918918
if len(secrets) > 0 {
919-
accountName, accountKey, rerr := getStorageAccount(secrets)
920-
if rerr != nil {
921-
return true, rerr
919+
var accountName, accountKey string
920+
accountName, accountKey, err = getStorageAccount(secrets)
921+
if err != nil {
922+
return true, err
922923
}
923-
fileClient, rerr := newAzureFileClient(accountName, accountKey, d.getStorageEndPointSuffix(), &retry.Backoff{Steps: 1})
924-
if rerr != nil {
925-
return true, rerr
924+
var fileClient azureFileClient
925+
fileClient, err = newAzureFileClient(accountName, accountKey, d.getStorageEndPointSuffix(), &retry.Backoff{Steps: 1})
926+
if err != nil {
927+
return true, err
926928
}
927929
err = fileClient.CreateFileShare(ctx, shareOptions)
928930
} else {
929931
_, err = d.cloud.FileClient.WithSubscriptionID(accountOptions.SubscriptionID).CreateFileShare(ctx, accountOptions.ResourceGroup, accountOptions.Name, shareOptions, "")
930932
}
931-
if isRetriableError(err) {
932-
klog.Warningf("CreateFileShare(%s) on account(%s) failed with error(%v), waiting for retrying", shareOptions.Name, accountOptions.Name, err)
933-
sleepIfThrottled(err, fileOpThrottlingSleepSec)
934-
return false, nil
933+
if err != nil {
934+
if isRetriableError(err) {
935+
klog.Warningf("CreateFileShare(%s) on account(%s) failed with error(%v), waiting for retrying", shareOptions.Name, accountOptions.Name, err)
936+
sleepIfThrottled(err, fileOpThrottlingSleepSec)
937+
return false, nil
938+
}
939+
klog.Errorf("CreateFileShare(%s) on account(%s) failed with error(%v)", shareOptions.Name, accountOptions.Name, err)
935940
}
936941
return true, err
937942
})

pkg/azurefile/azurefile_dataplane_client.go

+49-39
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ package azurefile
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"net/http"
2324

25+
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
2426
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
25-
azs "github.com/Azure/azure-sdk-for-go/storage"
27+
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
28+
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
2629
"k8s.io/klog/v2"
2730

31+
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/utils"
2832
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/fileclient"
2933
"sigs.k8s.io/cloud-provider-azure/pkg/retry"
3034
)
3135

32-
const (
33-
useHTTPS = true
34-
)
35-
3636
var (
3737
// refer https://github.com/Azure/azure-sdk-for-go/blob/master/storage/client.go#L88.
3838
defaultValidStatusCodes = []int{
@@ -47,78 +47,88 @@ var (
4747
type azureFileDataplaneClient struct {
4848
accountName string
4949
accountKey string
50-
*azs.FileServiceClient
50+
*service.Client
5151
}
5252

5353
func newAzureFileClient(accountName, accountKey, storageEndpointSuffix string, backoff *retry.Backoff) (azureFileClient, error) {
5454
if storageEndpointSuffix == "" {
5555
storageEndpointSuffix = defaultStorageEndPointSuffix
5656
}
57-
58-
fileClient, err := azs.NewClient(accountName, accountKey, storageEndpointSuffix, azs.DefaultAPIVersion, useHTTPS)
57+
keyCred, err := service.NewSharedKeyCredential(accountName, accountKey)
5958
if err != nil {
6059
return nil, fmt.Errorf("error creating azure client: %v", err)
6160
}
62-
61+
storageEndpoint := fmt.Sprintf("https://%s.file."+storageEndpointSuffix, accountName)
62+
clientOps := utils.GetDefaultAzCoreClientOption()
6363
if backoff != nil {
64-
fileClient.Sender = &azs.DefaultSender{
65-
RetryAttempts: backoff.Steps,
66-
ValidStatusCodes: defaultValidStatusCodes,
67-
RetryDuration: backoff.Duration,
68-
}
64+
clientOps.Retry.MaxRetries = int32(backoff.Steps)
65+
clientOps.Retry.StatusCodes = defaultValidStatusCodes
66+
clientOps.Retry.RetryDelay = backoff.Duration
67+
}
68+
fileClient, err := service.NewClientWithSharedKeyCredential(storageEndpoint, keyCred, &service.ClientOptions{
69+
ClientOptions: clientOps,
70+
})
71+
if err != nil {
72+
return nil, fmt.Errorf("error creating azure client: %v", err)
6973
}
7074

7175
return &azureFileDataplaneClient{
72-
accountName: accountName,
73-
accountKey: accountKey,
74-
FileServiceClient: to.Ptr(fileClient.GetFileService()),
76+
accountName: accountName,
77+
accountKey: accountKey,
78+
Client: fileClient,
7579
}, nil
7680
}
7781

78-
func (f *azureFileDataplaneClient) CreateFileShare(_ context.Context, shareOptions *fileclient.ShareOptions) error {
82+
func (f *azureFileDataplaneClient) CreateFileShare(ctx context.Context, shareOptions *fileclient.ShareOptions) error {
7983
if shareOptions == nil {
8084
return fmt.Errorf("shareOptions of account(%s) is nil", f.accountName)
8185
}
82-
share := f.FileServiceClient.GetShareReference(shareOptions.Name)
83-
share.Properties.Quota = shareOptions.RequestGiB
84-
newlyCreated, err := share.CreateIfNotExists(nil)
86+
shareClient := f.Client.NewShareClient(shareOptions.Name)
87+
_, err := shareClient.Create(ctx, &share.CreateOptions{
88+
Quota: to.Ptr(int32(shareOptions.RequestGiB)),
89+
})
90+
8591
if err != nil {
8692
return fmt.Errorf("failed to create file share, err: %v", err)
8793
}
88-
if !newlyCreated {
89-
klog.V(2).Infof("file share(%s) under account(%s) already exists", shareOptions.Name, f.accountName)
90-
}
9194
return nil
9295
}
9396

9497
// delete a file share
95-
func (f *azureFileDataplaneClient) DeleteFileShare(_ context.Context, shareName string) error {
96-
return f.FileServiceClient.GetShareReference(shareName).Delete(nil)
98+
func (f *azureFileDataplaneClient) DeleteFileShare(ctx context.Context, shareName string) error {
99+
_, err := f.Client.NewShareClient(shareName).Delete(ctx, nil)
100+
return err
97101
}
98102

99-
func (f *azureFileDataplaneClient) ResizeFileShare(_ context.Context, shareName string, sizeGiB int) error {
100-
share := f.FileServiceClient.GetShareReference(shareName)
101-
if share.Properties.Quota >= sizeGiB {
103+
func (f *azureFileDataplaneClient) ResizeFileShare(ctx context.Context, shareName string, sizeGiB int) error {
104+
shareClient := f.Client.NewShareClient(shareName)
105+
shareProps, err := shareClient.GetProperties(ctx, nil)
106+
if err != nil {
107+
return fmt.Errorf("failed to set quota on file share %s, err: %v", shareName, err)
108+
}
109+
if *shareProps.Quota >= int32(sizeGiB) {
102110
klog.Warningf("file share size(%dGi) is already greater or equal than requested size(%dGi), accountName: %s, shareName: %s",
103-
share.Properties.Quota, sizeGiB, f.accountName, shareName)
111+
*shareProps.Quota, sizeGiB, f.accountName, shareName)
104112
return nil
105113
}
106-
share.Properties.Quota = sizeGiB
107-
if err := share.SetProperties(nil); err != nil {
114+
if _, err := shareClient.SetProperties(ctx, &share.SetPropertiesOptions{
115+
Quota: to.Ptr(int32(sizeGiB)),
116+
}); err != nil {
108117
return fmt.Errorf("failed to set quota on file share %s, err: %v", shareName, err)
109118
}
110119
klog.V(4).Infof("resize file share completed, accountName: %s, shareName: %s, sizeGiB: %d", f.accountName, shareName, sizeGiB)
111120
return nil
112121
}
113122

114-
func (f *azureFileDataplaneClient) GetFileShareQuota(_ context.Context, name string) (int, error) {
115-
share := f.FileServiceClient.GetShareReference(name)
116-
exists, err := share.Exists()
123+
func (f *azureFileDataplaneClient) GetFileShareQuota(ctx context.Context, name string) (int, error) {
124+
shareClient := f.Client.NewShareClient(name)
125+
shareProps, err := shareClient.GetProperties(ctx, nil)
117126
if err != nil {
127+
var respErr *azcore.ResponseError
128+
if errors.As(err, &respErr) && respErr != nil && respErr.StatusCode == http.StatusNotFound {
129+
return -1, nil
130+
}
118131
return -1, err
119132
}
120-
if !exists {
121-
return -1, nil
122-
}
123-
return share.Properties.Quota, nil
133+
return int(*shareProps.Quota), nil
124134
}

pkg/azurefile/azurefile_dataplane_client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestCreateFileShare(t *testing.T) {
5959
func TestNewAzureFileClient(t *testing.T) {
6060
_, actualErr := newAzureFileClient("ut", "ut", "ut", nil)
6161
if actualErr != nil {
62-
expectedErr := fmt.Errorf("error creating azure client: azure: account name is not valid: it must be between 3 and 24 characters, and only may contain numbers and lowercase letters: ut")
62+
expectedErr := fmt.Errorf("error creating azure client: decode account key: illegal base64 data at input byte 0")
6363
if !reflect.DeepEqual(actualErr, expectedErr) {
6464
t.Errorf("actualErr: (%v), expectedErr: (%v)", actualErr, expectedErr)
6565
}

pkg/azurefile/azurefile_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ func TestGetFileShareQuota(t *testing.T) {
10011001
mockedFileShareResp: storage.FileShare{},
10021002
mockedFileShareErr: nil,
10031003
expectedQuota: -1,
1004-
expectedError: fmt.Errorf("error creating azure client: azure: account name is not valid: it must be between 3 and 24 characters, and only may contain numbers and lowercase letters: ut"),
1004+
expectedError: fmt.Errorf("error creating azure client: decode account key: illegal base64 data at input byte 4"),
10051005
},
10061006
}
10071007

pkg/azurefile/controllerserver.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-09-01/storage"
3434
"github.com/Azure/azure-storage-file-go/azfile"
3535
"github.com/container-storage-interface/spec/lib/go/csi"
36-
"github.com/pborman/uuid"
36+
"github.com/google/uuid"
3737

3838
"google.golang.org/grpc/codes"
3939
"google.golang.org/grpc/status"
@@ -623,7 +623,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
623623
diskName = validFileShareName + vhdSuffix
624624
} else {
625625
// use uuid as vhd disk name if file share specified
626-
diskName = uuid.NewUUID().String() + vhdSuffix
626+
diskName = uuid.NewString() + vhdSuffix
627627
}
628628
diskSizeBytes := volumehelper.GiBToBytes(requestGiB)
629629
klog.V(2).Infof("begin to create vhd file(%s) size(%d) on share(%s) on account(%s) type(%s) rg(%s) location(%s)",

test/e2e/suite_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ import (
2828
"strings"
2929
"testing"
3030

31+
"github.com/google/uuid"
3132
"github.com/onsi/ginkgo/v2"
3233
"github.com/onsi/ginkgo/v2/reporters"
3334
"github.com/onsi/gomega"
34-
"github.com/pborman/uuid"
3535
"k8s.io/kubernetes/test/e2e/framework"
3636
"k8s.io/kubernetes/test/e2e/framework/config"
3737
"sigs.k8s.io/azurefile-csi-driver/pkg/azurefile"
@@ -143,7 +143,7 @@ var _ = ginkgo.BeforeSuite(func(ctx ginkgo.SpecContext) {
143143
driverOptions := azurefile.DriverOptions{
144144
NodeID: os.Getenv("nodeid"),
145145
DriverName: azurefile.DefaultDriverName,
146-
Endpoint: fmt.Sprintf("unix:///tmp/csi-%s.sock", uuid.NewUUID().String()),
146+
Endpoint: fmt.Sprintf("unix:///tmp/csi-%s.sock", uuid.NewString()),
147147
KubeConfig: kubeconfig,
148148
}
149149
azurefileDriver = azurefile.NewDriver(&driverOptions)

test/utils/credentials/credentials.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"html/template"
2222
"os"
2323

24-
"github.com/pborman/uuid"
24+
"github.com/google/uuid"
2525
)
2626

2727
const (
@@ -124,7 +124,7 @@ func CreateAzureCredentialFile(isAzureChinaCloud bool) (*Credentials, error) {
124124
}
125125

126126
if resourceGroup == "" {
127-
resourceGroup = ResourceGroupPrefix + uuid.NewUUID().String()
127+
resourceGroup = ResourceGroupPrefix + uuid.NewString()
128128
}
129129

130130
if location == "" {

vendor/github.com/Azure/azure-sdk-for-go/storage/README.md

-23
This file was deleted.

0 commit comments

Comments
 (0)