@@ -22,9 +22,11 @@ import (
22
22
"net/http"
23
23
24
24
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
25
- azs "github.com/Azure/azure-sdk-for-go/storage"
25
+ "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
26
+ "github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
26
27
"k8s.io/klog/v2"
27
28
29
+ "sigs.k8s.io/cloud-provider-azure/pkg/azclient/utils"
28
30
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/fileclient"
29
31
"sigs.k8s.io/cloud-provider-azure/pkg/retry"
30
32
)
@@ -47,78 +49,84 @@ var (
47
49
type azureFileDataplaneClient struct {
48
50
accountName string
49
51
accountKey string
50
- * azs. FileServiceClient
52
+ * service. Client
51
53
}
52
54
53
55
func newAzureFileClient (accountName , accountKey , storageEndpointSuffix string , backoff * retry.Backoff ) (azureFileClient , error ) {
54
56
if storageEndpointSuffix == "" {
55
57
storageEndpointSuffix = defaultStorageEndPointSuffix
56
58
}
57
-
58
- fileClient , err := azs .NewClient (accountName , accountKey , storageEndpointSuffix , azs .DefaultAPIVersion , useHTTPS )
59
+ keyCred , err := service .NewSharedKeyCredential (accountName , accountKey )
59
60
if err != nil {
60
61
return nil , fmt .Errorf ("error creating azure client: %v" , err )
61
62
}
62
-
63
+ storageEndpoint := fmt .Sprintf ("https://%s.file." + defaultStorageEndPointSuffix , accountName )
64
+ clientOps := utils .GetDefaultAzCoreClientOption ()
63
65
if backoff != nil {
64
- fileClient .Sender = & azs.DefaultSender {
65
- RetryAttempts : backoff .Steps ,
66
- ValidStatusCodes : defaultValidStatusCodes ,
67
- RetryDuration : backoff .Duration ,
68
- }
66
+ clientOps .Retry .MaxRetries = int32 (backoff .Steps )
67
+ clientOps .Retry .StatusCodes = defaultValidStatusCodes
68
+ clientOps .Retry .RetryDelay = backoff .Duration
69
+ }
70
+ fileClient , err := service .NewClientWithSharedKeyCredential (storageEndpoint , keyCred , & service.ClientOptions {
71
+ ClientOptions : clientOps ,
72
+ })
73
+ if err != nil {
74
+ return nil , fmt .Errorf ("error creating azure client: %v" , err )
69
75
}
70
76
71
77
return & azureFileDataplaneClient {
72
- accountName : accountName ,
73
- accountKey : accountKey ,
74
- FileServiceClient : to . Ptr ( fileClient . GetFileService ()) ,
78
+ accountName : accountName ,
79
+ accountKey : accountKey ,
80
+ Client : fileClient ,
75
81
}, nil
76
82
}
77
83
78
- func (f * azureFileDataplaneClient ) CreateFileShare (_ context.Context , shareOptions * fileclient.ShareOptions ) error {
84
+ func (f * azureFileDataplaneClient ) CreateFileShare (ctx context.Context , shareOptions * fileclient.ShareOptions ) error {
79
85
if shareOptions == nil {
80
86
return fmt .Errorf ("shareOptions of account(%s) is nil" , f .accountName )
81
87
}
82
- share := f .FileServiceClient .GetShareReference (shareOptions .Name )
83
- share .Properties .Quota = shareOptions .RequestGiB
84
- newlyCreated , err := share .CreateIfNotExists (nil )
88
+ shareClient := f .Client .NewShareClient (shareOptions .Name )
89
+ _ , err := shareClient .Create (ctx , & share.CreateOptions {
90
+ Quota : to .Ptr (int32 (shareOptions .RequestGiB )),
91
+ })
92
+
85
93
if err != nil {
86
94
return fmt .Errorf ("failed to create file share, err: %v" , err )
87
95
}
88
- if ! newlyCreated {
89
- klog .V (2 ).Infof ("file share(%s) under account(%s) already exists" , shareOptions .Name , f .accountName )
90
- }
91
96
return nil
92
97
}
93
98
94
99
// delete a file share
95
- func (f * azureFileDataplaneClient ) DeleteFileShare (_ context.Context , shareName string ) error {
96
- return f .FileServiceClient .GetShareReference (shareName ).Delete (nil )
100
+ func (f * azureFileDataplaneClient ) DeleteFileShare (ctx context.Context , shareName string ) error {
101
+ _ , err := f .Client .NewShareClient (shareName ).Delete (ctx , nil )
102
+ return err
97
103
}
98
104
99
- func (f * azureFileDataplaneClient ) ResizeFileShare (_ context.Context , shareName string , sizeGiB int ) error {
100
- share := f .FileServiceClient .GetShareReference (shareName )
101
- if share .Properties .Quota >= sizeGiB {
105
+ func (f * azureFileDataplaneClient ) ResizeFileShare (ctx context.Context , shareName string , sizeGiB int ) error {
106
+ shareClient := f .Client .NewShareClient (shareName )
107
+ shareProps , err := shareClient .GetProperties (ctx , nil )
108
+ if err != nil {
109
+ return fmt .Errorf ("failed to set quota on file share %s, err: %v" , shareName , err )
110
+ }
111
+ if * shareProps .Quota >= int32 (sizeGiB ) {
102
112
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 )
113
+ * shareProps .Quota , sizeGiB , f .accountName , shareName )
104
114
return nil
105
115
}
106
- share .Properties .Quota = sizeGiB
107
- if err := share .SetProperties (nil ); err != nil {
116
+ if _ , err := shareClient .SetProperties (ctx , & share.SetPropertiesOptions {
117
+ Quota : to .Ptr (int32 (sizeGiB )),
118
+ }); err != nil {
108
119
return fmt .Errorf ("failed to set quota on file share %s, err: %v" , shareName , err )
109
120
}
110
121
klog .V (4 ).Infof ("resize file share completed, accountName: %s, shareName: %s, sizeGiB: %d" , f .accountName , shareName , sizeGiB )
111
122
return nil
112
123
}
113
124
114
- func (f * azureFileDataplaneClient ) GetFileShareQuota (_ context.Context , name string ) (int , error ) {
115
- share := f .FileServiceClient . GetShareReference (name )
116
- exists , err := share . Exists ( )
125
+ func (f * azureFileDataplaneClient ) GetFileShareQuota (ctx context.Context , name string ) (int , error ) {
126
+ shareClient := f .Client . NewShareClient (name )
127
+ shareProps , err := shareClient . GetProperties ( ctx , nil )
117
128
if err != nil {
118
129
return - 1 , err
119
130
}
120
- if ! exists {
121
- return - 1 , nil
122
- }
123
- return share .Properties .Quota , nil
131
+ return int (* shareProps .Quota ), nil
124
132
}
0 commit comments