Skip to content

Commit cd14bc2

Browse files
authored
Merge pull request #3056 from k8s-infra-cherrypick-robot/cherry-pick-3053-to-release-1.35
[release-1.35] fix: createFolderIfNotExist does not work when using NFS protocol
2 parents a97d61c + 5aff3fa commit cd14bc2

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

pkg/azurefile/azurefile.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,13 @@ func (d *Driver) GetAccountInfo(ctx context.Context, volumeID string, secrets, r
881881
}
882882
if protocol == nfs && fileShareName != "" {
883883
// nfs protocol does not need account key, return directly
884-
return rgName, accountName, accountKey, fileShareName, diskName, subsID, tenantID, tokenFilePath, err
884+
// unless createFolderIfNotExist is set with a folderName, which requires account key for data plane API
885+
needAccountKey := strings.EqualFold(getValueInMap(reqContext, createFolderIfNotExistField), trueValue)
886+
hasFolder := getValueInMap(reqContext, folderNameField) != ""
887+
if !needAccountKey || !hasFolder {
888+
return rgName, accountName, accountKey, fileShareName, diskName, subsID, tenantID, tokenFilePath, err
889+
}
890+
klog.V(2).Infof("NFS protocol with createFolderIfNotExist may require an account key for data plane API access")
885891
}
886892

887893
if secretNamespace == "" {

pkg/azurefile/azurefile_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,24 @@ func TestGetAccountInfo(t *testing.T) {
810810
expectFileShareName: "test_sharename",
811811
expectDiskName: "",
812812
},
813+
{
814+
volumeID: "uniqe-volumeid-nfs-createfolder",
815+
rgName: "vol_nfs",
816+
secrets: emptySecret,
817+
reqContext: map[string]string{
818+
resourceGroupField: "vol_nfs",
819+
storageAccountField: "test_accountname",
820+
shareNameField: "test_sharename",
821+
protocolField: "nfs",
822+
createFolderIfNotExistField: "true",
823+
folderNameField: "testfolder",
824+
},
825+
expectErr: false,
826+
err: nil,
827+
expectAccountName: "test_accountname",
828+
expectFileShareName: "test_sharename",
829+
expectDiskName: "",
830+
},
813831
{
814832
volumeID: "invalid_getLatestAccountKey_value##",
815833
rgName: "vol_2",
@@ -858,9 +876,10 @@ func TestGetAccountInfo(t *testing.T) {
858876
mockStorageAccountsClient := mock_accountclient.NewMockInterface(ctrl)
859877
d.cloud.ComputeClientFactory = mock_azclient.NewMockClientFactory(ctrl)
860878
d.cloud.ComputeClientFactory.(*mock_azclient.MockClientFactory).EXPECT().GetAccountClient().Return(mockStorageAccountsClient).AnyTimes()
879+
d.cloud.ComputeClientFactory.(*mock_azclient.MockClientFactory).EXPECT().GetAccountClientForSub(gomock.Any()).Return(mockStorageAccountsClient, nil).AnyTimes()
861880
d.kubeClient = clientSet
862881
d.cloud.Environment = &azclient.Environment{StorageEndpointSuffix: "abc"}
863-
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), test.rgName).Return(key, nil).AnyTimes()
882+
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), gomock.Any()).Return(key, nil).AnyTimes()
864883
rgName, accountName, _, fileShareName, diskName, _, _, _, err := d.GetAccountInfo(context.Background(), test.volumeID, test.secrets, test.reqContext)
865884
if test.expectErr && err == nil {
866885
t.Errorf("Unexpected non-error")

0 commit comments

Comments
 (0)