@@ -54,7 +54,6 @@ import (
54
54
csicommon "sigs.k8s.io/azurefile-csi-driver/pkg/csi-common"
55
55
"sigs.k8s.io/azurefile-csi-driver/pkg/mounter"
56
56
fileutil "sigs.k8s.io/azurefile-csi-driver/pkg/util"
57
- "sigs.k8s.io/cloud-provider-azure/pkg/azclient/accountclient"
58
57
"sigs.k8s.io/cloud-provider-azure/pkg/azclient/fileshareclient"
59
58
azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
60
59
"sigs.k8s.io/cloud-provider-azure/pkg/provider/storage"
@@ -478,13 +477,11 @@ func (d *Driver) getFileShareQuota(ctx context.Context, accountOptions *storage.
478
477
if err != nil {
479
478
return - 1 , err
480
479
}
481
- fileClient , err = newAzureFileClient (accountName , accountKey , d .getStorageEndPointSuffix ())
482
- if err != nil {
480
+ if fileClient , err = newAzureFileClient (accountName , accountKey , d .getStorageEndPointSuffix ()); err != nil {
483
481
return - 1 , err
484
482
}
485
483
} else {
486
- fileClient , err = newAzureFileMgmtClient (d .cloud .ComputeClientFactory , accountOptions )
487
- if err != nil {
484
+ if fileClient , err = newAzureFileMgmtClient (d .cloud , accountOptions ); err != nil {
488
485
return - 1 , err
489
486
}
490
487
}
@@ -849,14 +846,9 @@ func (d *Driver) GetAccountInfo(ctx context.Context, volumeID string, secrets, r
849
846
if err != nil {
850
847
// 3. if failed to get account key from kubernetes secret, use cluster identity to get account key
851
848
klog .Warningf ("GetStorageAccountFromSecret(%s, %s) failed with error: %v" , secretName , secretNamespace , err )
852
- var accountClient accountclient.Interface
853
- accountClient , err = d .cloud .ComputeClientFactory .GetAccountClientForSub (subsID )
854
- if err != nil {
855
- return rgName , accountName , accountKey , fileShareName , diskName , subsID , err
856
- }
857
- if ! getAccountKeyFromSecret && accountClient != nil && accountName != "" {
849
+ if ! getAccountKeyFromSecret && accountName != "" {
858
850
klog .V (2 ).Infof ("use cluster identity to get account key from (%s, %s, %s)" , subsID , rgName , accountName )
859
- accountKey , err = d .cloud . GetStorageAccesskey (ctx , accountClient , accountName , rgName , getLatestAccountKey )
851
+ accountKey , err = d .GetStorageAccesskeyWithSubsID (ctx , subsID , accountName , rgName , getLatestAccountKey )
860
852
if err != nil {
861
853
klog .Errorf ("GetStorageAccesskey(%s, %s, %s) failed with error: %v" , subsID , rgName , accountName , err )
862
854
}
@@ -956,7 +948,7 @@ func (d *Driver) CreateFileShare(ctx context.Context, accountOptions *storage.Ac
956
948
return true , err
957
949
}
958
950
} else {
959
- if fileClient , err = newAzureFileMgmtClient (d .cloud . ComputeClientFactory , accountOptions ); err != nil {
951
+ if fileClient , err = newAzureFileMgmtClient (d .cloud , accountOptions ); err != nil {
960
952
return true , err
961
953
}
962
954
}
@@ -987,10 +979,9 @@ func (d *Driver) DeleteFileShare(ctx context.Context, subsID, resourceGroup, acc
987
979
}
988
980
err = fileClient .DeleteFileShare (ctx , shareName )
989
981
} else {
990
- var fileClient fileshareclient.Interface
991
- fileClient , err = d .cloud .ComputeClientFactory .GetFileShareClientForSub (subsID )
992
- if err != nil {
993
- return true , err
982
+ fileClient , errGetClient := d .getFileShareClientForSub (subsID )
983
+ if errGetClient != nil {
984
+ return true , errGetClient
994
985
}
995
986
err = fileClient .Delete (ctx , resourceGroup , accountName , shareName , nil )
996
987
}
@@ -1033,7 +1024,7 @@ func (d *Driver) ResizeFileShare(ctx context.Context, subsID, resourceGroup, acc
1033
1024
}
1034
1025
err = fileClient .ResizeFileShare (ctx , shareName , sizeGiB )
1035
1026
} else {
1036
- fileClient , err := d .cloud . ComputeClientFactory . GetFileShareClientForSub (subsID )
1027
+ fileClient , err := d .getFileShareClientForSub (subsID )
1037
1028
if err != nil {
1038
1029
return true , err
1039
1030
}
@@ -1098,7 +1089,7 @@ func (d *Driver) copyFileShare(ctx context.Context, req *csi.CreateVolumeRequest
1098
1089
1099
1090
// GetTotalAccountQuota returns the total quota in GB of all file shares in the storage account and the number of file shares
1100
1091
func (d * Driver ) GetTotalAccountQuota (ctx context.Context , subsID , resourceGroup , accountName string ) (int32 , int32 , error ) {
1101
- fileClient , err := d .cloud . ComputeClientFactory . GetFileShareClientForSub (subsID )
1092
+ fileClient , err := d .getFileShareClientForSub (subsID )
1102
1093
if err != nil {
1103
1094
return - 1 , - 1 , err
1104
1095
}
@@ -1117,7 +1108,7 @@ func (d *Driver) GetTotalAccountQuota(ctx context.Context, subsID, resourceGroup
1117
1108
1118
1109
// RemoveStorageAccountTag remove tag from storage account
1119
1110
func (d * Driver ) RemoveStorageAccountTag (ctx context.Context , subsID , resourceGroup , account , key string ) error {
1120
- if d .cloud == nil || d . cloud . ComputeClientFactory . GetAccountClient () == nil {
1111
+ if d .cloud == nil {
1121
1112
return fmt .Errorf ("cloud or StorageAccountClient is nil" )
1122
1113
}
1123
1114
// search in cache first
@@ -1165,12 +1156,7 @@ func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *storag
1165
1156
_ , accountKey , err := d .GetStorageAccountFromSecret (ctx , secretName , secretNamespace )
1166
1157
if err != nil {
1167
1158
klog .V (2 ).Infof ("could not get account(%s) key from secret(%s), error: %v, use cluster identity to get account key instead" , accountOptions .Name , secretName , err )
1168
- var accountClient accountclient.Interface
1169
- accountClient , err = d .cloud .ComputeClientFactory .GetAccountClientForSub (accountOptions .SubscriptionID )
1170
- if err != nil {
1171
- return "" , err
1172
- }
1173
- accountKey , err = d .cloud .GetStorageAccesskey (ctx , accountClient , accountName , accountOptions .ResourceGroup , accountOptions .GetLatestAccountKey )
1159
+ accountKey , err = d .GetStorageAccesskeyWithSubsID (ctx , accountOptions .SubscriptionID , accountOptions .Name , accountOptions .ResourceGroup , accountOptions .GetLatestAccountKey )
1174
1160
}
1175
1161
1176
1162
if err == nil && accountKey != "" {
@@ -1179,6 +1165,18 @@ func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *storag
1179
1165
return accountKey , err
1180
1166
}
1181
1167
1168
+ // GetStorageAccesskeyWithSubsID get Azure storage account key from storage account directly
1169
+ func (d * Driver ) GetStorageAccesskeyWithSubsID (ctx context.Context , subsID , account , resourceGroup string , getLatestAccountKey bool ) (string , error ) {
1170
+ if d .cloud == nil || d .cloud .ComputeClientFactory == nil {
1171
+ return "" , fmt .Errorf ("could not get account key: cloud or ComputeClientFactory is nil" )
1172
+ }
1173
+ accountClient , err := d .cloud .ComputeClientFactory .GetAccountClientForSub (subsID )
1174
+ if err != nil {
1175
+ return "" , err
1176
+ }
1177
+ return d .cloud .GetStorageAccesskey (ctx , accountClient , account , resourceGroup , getLatestAccountKey )
1178
+ }
1179
+
1182
1180
// GetStorageAccountFromSecret get storage account key from k8s secret
1183
1181
// return <accountName, accountKey, error>
1184
1182
func (d * Driver ) GetStorageAccountFromSecret (ctx context.Context , secretName , secretNamespace string ) (string , string , error ) {
@@ -1274,3 +1272,10 @@ func (d *Driver) getStorageEndPointSuffix() string {
1274
1272
}
1275
1273
return d .cloud .Environment .StorageEndpointSuffix
1276
1274
}
1275
+
1276
+ func (d * Driver ) getFileShareClientForSub (subscriptionID string ) (fileshareclient.Interface , error ) {
1277
+ if d .cloud == nil || d .cloud .ComputeClientFactory == nil {
1278
+ return nil , fmt .Errorf ("cloud or ComputeClientFactory is nil" )
1279
+ }
1280
+ return d .cloud .ComputeClientFactory .GetFileShareClientForSub (subscriptionID )
1281
+ }
0 commit comments