@@ -166,7 +166,7 @@ const (
166
166
accountLimitExceedManagementAPI = "TotalSharesProvisionedCapacityExceedsAccountLimit"
167
167
accountLimitExceedDataPlaneAPI = "specified share does not exist"
168
168
169
- fileShareNotFound = "ErrorCode= ShareNotFound"
169
+ fileShareNotFound = "ShareNotFound"
170
170
statusCodeNotFound = "StatusCode=404"
171
171
httpCodeNotFound = "HTTPStatusCode: 404"
172
172
@@ -196,6 +196,8 @@ const (
196
196
FSGroupChangeNone = "None"
197
197
// define tag value delimiter and default is comma
198
198
tagValueDelimiterField = "tagvaluedelimiter"
199
+ // for data plane API
200
+ oauth = "oauth"
199
201
)
200
202
201
203
var (
@@ -260,7 +262,7 @@ type Driver struct {
260
262
accountCacheMap azcache.Resource
261
263
// a map storing all secret names created by this driver <secretCacheKey, "">
262
264
secretCacheMap azcache.Resource
263
- // a map storing all volumes using data plane API <volumeID, "" >
265
+ // a map storing all volumes using data plane API <volumeID, value >
264
266
dataPlaneAPIVolMap sync.Map
265
267
// a timed cache storing all storage accounts that are using data plane API temporarily
266
268
dataPlaneAPIAccountCache azcache.Resource
@@ -473,25 +475,27 @@ func (d *Driver) Run(ctx context.Context) error {
473
475
}
474
476
475
477
// getFileShareQuota return (-1, nil) means file share does not exist
476
- func (d * Driver ) getFileShareQuota (ctx context.Context , accountOptions * storage.AccountOptions , fileShareName string , secrets map [string ]string ) (int , error ) {
478
+ func (d * Driver ) getFileShareQuota (ctx context.Context , accountOptions * storage.AccountOptions , fileShareName string , secrets map [string ]string , useDataPlaneAPI string ) (int , error ) {
477
479
var fileClient azureFileClient
478
480
var err error
479
481
if len (secrets ) > 0 {
480
- accountName , accountKey , err := getStorageAccount (secrets )
481
- if err != nil {
482
- return - 1 , err
482
+ accountName , accountKey , rerr := getStorageAccount (secrets )
483
+ if rerr != nil {
484
+ return - 1 , rerr
483
485
}
484
486
storageEndPointSuffix := d .getStorageEndPointSuffix ()
485
487
if accountOptions != nil && accountOptions .StorageEndpointSuffix != "" {
486
488
storageEndPointSuffix = accountOptions .StorageEndpointSuffix
487
489
}
488
- if fileClient , err = newAzureFileClient (accountName , accountKey , storageEndPointSuffix ); err != nil {
489
- return - 1 , err
490
- }
490
+ fileClient , err = newAzureFileClient (accountName , accountKey , storageEndPointSuffix )
491
+ } else if d . cloud != nil && d . cloud . AuthProvider != nil && strings . EqualFold ( useDataPlaneAPI , oauth ) {
492
+ fileClient , err = newAzureFileClientWithOAuth ( d . cloud . AuthProvider . GetAzIdentity (), accountOptions . Name , d . getStorageEndPointSuffix ())
491
493
} else {
492
- if fileClient , err = newAzureFileMgmtClient (d .cloud , accountOptions ); err != nil {
493
- return - 1 , err
494
- }
494
+ fileClient , err = newAzureFileMgmtClient (d .cloud , accountOptions )
495
+ }
496
+
497
+ if err != nil {
498
+ return - 1 , err
495
499
}
496
500
quota , err := fileClient .GetFileShareQuota (ctx , fileShareName )
497
501
if err != nil {
@@ -709,7 +713,7 @@ func getDirectoryClient(accountName, accountKey, storageEndpointSuffix, fileShar
709
713
if u == nil {
710
714
return nil , fmt .Errorf ("parse fileURLTemplate error: url is nil" )
711
715
}
712
- serviceURL := fmt . Sprintf ( "https://%s.file.%s/" , accountName , storageEndpointSuffix )
716
+ serviceURL := getFileServiceURL ( accountName , storageEndpointSuffix )
713
717
714
718
serviceClient , err := service .NewClientWithSharedKeyCredential (serviceURL , credential , nil )
715
719
if err != nil {
@@ -942,7 +946,7 @@ func isSupportedFSGroupChangePolicy(policy string) bool {
942
946
}
943
947
944
948
// CreateFileShare creates a file share
945
- func (d * Driver ) CreateFileShare (ctx context.Context , accountOptions * storage.AccountOptions , shareOptions * ShareOptions , secrets map [string ]string ) error {
949
+ func (d * Driver ) CreateFileShare (ctx context.Context , accountOptions * storage.AccountOptions , shareOptions * ShareOptions , secrets map [string ]string , useDataPlaneAPI string ) error {
946
950
return wait .ExponentialBackoff (getBackOff (d .cloud .Config ), func () (bool , error ) {
947
951
var err error
948
952
var fileClient azureFileClient
@@ -959,12 +963,20 @@ func (d *Driver) CreateFileShare(ctx context.Context, accountOptions *storage.Ac
959
963
if fileClient , err = newAzureFileClient (accountName , accountKey , storageEndPointSuffix ); err != nil {
960
964
return true , err
961
965
}
966
+ } else if d .cloud != nil && d .cloud .AuthProvider != nil && strings .EqualFold (useDataPlaneAPI , oauth ) {
967
+ fileClient , err = newAzureFileClientWithOAuth (d .cloud .AuthProvider .GetAzIdentity (), accountOptions .Name , d .getStorageEndPointSuffix ())
962
968
} else {
963
- if fileClient , err = newAzureFileMgmtClient (d .cloud , accountOptions ); err != nil {
964
- return true , err
965
- }
969
+ fileClient , err = newAzureFileMgmtClient (d .cloud , accountOptions )
966
970
}
971
+ if err != nil {
972
+ return true , err
973
+ }
974
+
967
975
if err = fileClient .CreateFileShare (ctx , shareOptions ); err != nil {
976
+ if strings .Contains (err .Error (), "ShareAlreadyExists" ) {
977
+ klog .Warningf ("CreateFileShare(%s) on account(%s) failed with error(%v), return as success" , shareOptions .Name , accountOptions .Name , err )
978
+ return true , nil
979
+ }
968
980
if isRetriableError (err ) {
969
981
klog .Warningf ("CreateFileShare(%s) on account(%s) failed with error(%v), waiting for retrying" , shareOptions .Name , accountOptions .Name , err )
970
982
sleepIfThrottled (err , fileOpThrottlingSleepSec )
@@ -977,7 +989,7 @@ func (d *Driver) CreateFileShare(ctx context.Context, accountOptions *storage.Ac
977
989
}
978
990
979
991
// DeleteFileShare deletes a file share using storage account name and key
980
- func (d * Driver ) DeleteFileShare (ctx context.Context , subsID , resourceGroup , accountName , shareName string , secrets map [string ]string ) error {
992
+ func (d * Driver ) DeleteFileShare (ctx context.Context , subsID , resourceGroup , accountName , shareName string , secrets map [string ]string , useDataPlaneAPI string ) error {
981
993
return wait .ExponentialBackoff (getBackOff (d .cloud .Config ), func () (bool , error ) {
982
994
var err error
983
995
if len (secrets ) > 0 {
@@ -990,6 +1002,12 @@ func (d *Driver) DeleteFileShare(ctx context.Context, subsID, resourceGroup, acc
990
1002
return true , rerr
991
1003
}
992
1004
err = fileClient .DeleteFileShare (ctx , shareName )
1005
+ } else if d .cloud != nil && d .cloud .AuthProvider != nil && strings .EqualFold (useDataPlaneAPI , oauth ) {
1006
+ fileClient , rerr := newAzureFileClientWithOAuth (d .cloud .AuthProvider .GetAzIdentity (), accountName , d .getStorageEndPointSuffix ())
1007
+ if rerr != nil {
1008
+ return true , rerr
1009
+ }
1010
+ err = fileClient .DeleteFileShare (ctx , shareName )
993
1011
} else {
994
1012
fileClient , errGetClient := d .getFileShareClientForSub (subsID )
995
1013
if errGetClient != nil {
@@ -1022,7 +1040,7 @@ func (d *Driver) DeleteFileShare(ctx context.Context, subsID, resourceGroup, acc
1022
1040
}
1023
1041
1024
1042
// ResizeFileShare resizes a file share
1025
- func (d * Driver ) ResizeFileShare (ctx context.Context , subsID , resourceGroup , accountName , shareName string , sizeGiB int , secrets map [string ]string ) error {
1043
+ func (d * Driver ) ResizeFileShare (ctx context.Context , subsID , resourceGroup , accountName , shareName string , sizeGiB int , secrets map [string ]string , useDataPlaneAPI string ) error {
1026
1044
return wait .ExponentialBackoff (getBackOff (d .cloud .Config ), func () (bool , error ) {
1027
1045
var err error
1028
1046
if len (secrets ) > 0 {
@@ -1035,14 +1053,20 @@ func (d *Driver) ResizeFileShare(ctx context.Context, subsID, resourceGroup, acc
1035
1053
return true , rerr
1036
1054
}
1037
1055
err = fileClient .ResizeFileShare (ctx , shareName , sizeGiB )
1056
+ } else if d .cloud != nil && d .cloud .AuthProvider != nil && strings .EqualFold (useDataPlaneAPI , oauth ) {
1057
+ fileClient , rerr := newAzureFileClientWithOAuth (d .cloud .AuthProvider .GetAzIdentity (), accountName , d .getStorageEndPointSuffix ())
1058
+ if rerr != nil {
1059
+ return true , rerr
1060
+ }
1061
+ err = fileClient .ResizeFileShare (ctx , shareName , sizeGiB )
1038
1062
} else {
1039
- fileClient , err := d .getFileShareClientForSub (subsID )
1040
- if err != nil {
1041
- return true , err
1063
+ fileClient , rerr := d .getFileShareClientForSub (subsID )
1064
+ if rerr != nil {
1065
+ return true , rerr
1042
1066
}
1043
- fileShare , err := fileClient .Get (ctx , resourceGroup , accountName , shareName , nil )
1044
- if err != nil {
1045
- return true , err
1067
+ fileShare , rerr := fileClient .Get (ctx , resourceGroup , accountName , shareName , nil )
1068
+ if rerr != nil {
1069
+ return true , rerr
1046
1070
}
1047
1071
if ptr .Deref (fileShare .FileShareProperties .ShareQuota , 0 ) >= int32 (sizeGiB ) {
1048
1072
klog .Warningf ("file share size(%dGi) is already greater or equal than requested size(%dGi), accountName: %s, shareName: %s" ,
@@ -1051,7 +1075,6 @@ func (d *Driver) ResizeFileShare(ctx context.Context, subsID, resourceGroup, acc
1051
1075
}
1052
1076
fileShare .FileShareProperties .ShareQuota = to .Ptr (int32 (sizeGiB ))
1053
1077
_ , err = fileClient .Update (ctx , resourceGroup , accountName , shareName , * fileShare )
1054
- return true , err
1055
1078
}
1056
1079
if isRetriableError (err ) {
1057
1080
klog .Warningf ("ResizeFileShare(%s) on account(%s) with new size(%d) failed with error(%v), waiting for retrying" , shareName , accountName , sizeGiB , err )
@@ -1232,20 +1255,21 @@ func (d *Driver) getSubnetResourceID(vnetResourceGroup, vnetName, subnetName str
1232
1255
return fmt .Sprintf (subnetTemplate , subsID , vnetResourceGroup , vnetName , subnetName )
1233
1256
}
1234
1257
1235
- func (d * Driver ) useDataPlaneAPI (ctx context.Context , volumeID , accountName string ) bool {
1236
- _ , useDataPlaneAPI := d .dataPlaneAPIVolMap .Load (volumeID )
1258
+ func (d * Driver ) useDataPlaneAPI (ctx context.Context , volumeID , accountName string ) string {
1259
+ v , useDataPlaneAPI := d .dataPlaneAPIVolMap .Load (volumeID )
1237
1260
if useDataPlaneAPI {
1238
- return true
1261
+ return v .( string )
1239
1262
}
1240
1263
1241
1264
cache , err := d .dataPlaneAPIAccountCache .Get (ctx , accountName , azcache .CacheReadTypeDefault )
1242
1265
if err != nil {
1243
1266
klog .Errorf ("get(%s) from dataPlaneAPIAccountCache failed with error: %v" , accountName , err )
1267
+ return ""
1244
1268
}
1245
1269
if cache != nil {
1246
- return true
1270
+ return cache .( string )
1247
1271
}
1248
- return false
1272
+ return ""
1249
1273
}
1250
1274
1251
1275
func (d * Driver ) SetAzureCredentials (ctx context.Context , accountName , accountKey , secretName , secretNamespace string ) (string , error ) {
0 commit comments