Skip to content

Commit ae8392c

Browse files
authored
Merge pull request #264 from andyzhangx/nfs-pv-volumeid-fix
fix: volumeid error in nfs pv
2 parents afe5aaa + dcc9036 commit ae8392c

File tree

4 files changed

+20
-46
lines changed

4 files changed

+20
-46
lines changed

pkg/blob/blob.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (d *Driver) Run(endpoint, kubeconfig string, testBool bool) {
155155
s.Wait()
156156
}
157157

158-
// get container info according to volume id, e.g.
158+
// GetContainerInfo get container info according to volume id, e.g.
159159
// input: "rg#f5713de20cde511e8ba4900#pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41"
160160
// output: rg, f5713de20cde511e8ba4900, pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41
161161
func GetContainerInfo(id string) (string, string, string, error) {
@@ -246,7 +246,7 @@ func isSASToken(key string) bool {
246246
}
247247

248248
// GetAuthEnv return <accountName, containerName, authEnv, error>
249-
func (d *Driver) GetAuthEnv(ctx context.Context, volumeID string, attrib, secrets map[string]string) (string, string, []string, error) {
249+
func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attrib, secrets map[string]string) (string, string, []string, error) {
250250
var (
251251
accountName string
252252
accountKey string
@@ -269,7 +269,9 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID string, attrib, secret
269269
keyVaultSecretName = v
270270
case "keyvaultsecretversion":
271271
keyVaultSecretVersion = v
272-
case "storageaccountname":
272+
case storageAccountField:
273+
accountName = v
274+
case "storageaccountname": // for compatibility
273275
accountName = v
274276
case "azurestorageauthtype":
275277
authEnv = append(authEnv, "AZURE_STORAGE_AUTH_TYPE="+v)
@@ -291,6 +293,10 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID string, attrib, secret
291293
}
292294
klog.V(2).Infof("volumeID(%s) authEnv: %s", volumeID, authEnv)
293295

296+
if protocol == nfs {
297+
return accountName, containerName, authEnv, err
298+
}
299+
294300
// 1. If keyVaultURL is not nil, preferentially use the key stored in key vault.
295301
// 2. Then if secrets map is not nil, use the key stored in the secrets map.
296302
// 3. Finally if both keyVaultURL and secrets map are nil, get the key from Azure.
@@ -390,6 +396,8 @@ func (d *Driver) GetStorageAccountAndContainer(ctx context.Context, volumeID str
390396
keyVaultSecretName = v
391397
case "keyvaultsecretversion":
392398
keyVaultSecretVersion = v
399+
case storageAccountField:
400+
accountName = v
393401
case "storageaccountname":
394402
accountName = v
395403
}

pkg/blob/blob_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ func TestIsSupportedProtocol(t *testing.T) {
440440
}
441441

442442
func TestGetAuthEnv(t *testing.T) {
443-
444443
testCases := []struct {
445444
name string
446445
testFunc func(t *testing.T)
@@ -473,7 +472,7 @@ func TestGetAuthEnv(t *testing.T) {
473472
RawError: fmt.Errorf("test"),
474473
}
475474
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), gomock.Any()).Return(accountListKeysResult, rerr).AnyTimes()
476-
_, _, _, err := d.GetAuthEnv(context.TODO(), volumeID, attrib, secret)
475+
_, _, _, err := d.GetAuthEnv(context.TODO(), volumeID, "", attrib, secret)
477476
expectedErr := fmt.Errorf("no key for storage account(f5713de20cde511e8ba4900) under resource group(rg), err Retriable: false, RetryAfter: 0s, HTTPStatusCode: 0, RawError: test")
478477
if !reflect.DeepEqual(err, expectedErr) {
479478
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
@@ -502,7 +501,7 @@ func TestGetAuthEnv(t *testing.T) {
502501
Keys: &accountkeylist,
503502
}
504503
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), gomock.Any()).Return(list, nil).AnyTimes()
505-
_, _, _, err := d.GetAuthEnv(context.TODO(), volumeID, attrib, secret)
504+
_, _, _, err := d.GetAuthEnv(context.TODO(), volumeID, "", attrib, secret)
506505
expectedErr := error(nil)
507506
if !reflect.DeepEqual(err, expectedErr) {
508507
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
@@ -523,7 +522,7 @@ func TestGetAuthEnv(t *testing.T) {
523522
secret["azurestorageaccountsastoken"] = "unit-test"
524523
secret["msisecret"] = "unit-test"
525524
secret["azurestoragespnclientsecret"] = "unit-test"
526-
_, _, _, err := d.GetAuthEnv(context.TODO(), volumeID, attrib, secret)
525+
_, _, _, err := d.GetAuthEnv(context.TODO(), volumeID, "", attrib, secret)
527526
expectedErr := fmt.Errorf("could not find containerName from attributes(map[]) or volumeID(rg#f5713de20cde511e8ba4900#pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41)")
528527
if !reflect.DeepEqual(err, expectedErr) {
529528
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)

pkg/blob/nodeserver.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,6 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
123123
attrib := req.GetVolumeContext()
124124
secrets := req.GetSecrets()
125125

126-
accountName, containerName, authEnv, err := d.GetAuthEnv(ctx, volumeID, attrib, secrets)
127-
if err != nil {
128-
return nil, err
129-
}
130-
131126
var blobStorageEndPoint, protocol string
132127
for k, v := range attrib {
133128
switch strings.ToLower(k) {
@@ -137,6 +132,12 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
137132
protocol = v
138133
}
139134
}
135+
136+
accountName, containerName, authEnv, err := d.GetAuthEnv(ctx, volumeID, protocol, attrib, secrets)
137+
if err != nil {
138+
return nil, err
139+
}
140+
140141
if strings.TrimSpace(blobStorageEndPoint) == "" {
141142
// server address is "accountname.blob.core.windows.net" by default
142143
blobStorageEndPoint = fmt.Sprintf("%s.blob.%s", accountName, d.cloud.Environment.StorageEndpointSuffix)

pkg/blob/nodeserver_test.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -317,40 +317,6 @@ func TestNodeStageVolume(t *testing.T) {
317317
}
318318
},
319319
},
320-
{
321-
name: "volume mount sensitive fail",
322-
testFunc: func(t *testing.T) {
323-
attrib := make(map[string]string)
324-
attrib["containername"] = "ut-container"
325-
attrib["server"] = "blob-endpoint"
326-
attrib["protocol"] = "nfs"
327-
secret := make(map[string]string)
328-
secret["accountname"] = "unit-test"
329-
accessType := csi.VolumeCapability_Mount{}
330-
req := &csi.NodeStageVolumeRequest{
331-
VolumeId: "rg#f5713de20cde511e8ba4900#pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41",
332-
StagingTargetPath: "right_mount",
333-
VolumeContext: attrib,
334-
Secrets: secret,
335-
VolumeCapability: &csi.VolumeCapability{
336-
AccessType: &accessType,
337-
},
338-
}
339-
d := NewFakeDriver()
340-
fakeMounter := &fakeMounter{}
341-
d.mounter = &mount.SafeFormatAndMount{
342-
Interface: fakeMounter,
343-
}
344-
_, err := d.NodeStageVolume(context.TODO(), req)
345-
expectedErr := status.Error(codes.Internal, "volume(rg#f5713de20cde511e8ba4900#pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41) mount \"blob-endpoint:/unit-test/ut-container\" on \"right_mount\" failed with fake MountSensitive: source error")
346-
if !reflect.DeepEqual(err, expectedErr) {
347-
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
348-
}
349-
// Clean up
350-
err = os.RemoveAll(req.StagingTargetPath)
351-
assert.NoError(t, err)
352-
},
353-
},
354320
}
355321
for _, tc := range testCases {
356322
t.Run(tc.name, tc.testFunc)

0 commit comments

Comments
 (0)