Skip to content

Commit 6cfae07

Browse files
committed
get subsID from volumeID
1 parent a73ee55 commit 6cfae07

File tree

5 files changed

+52
-21
lines changed

5 files changed

+52
-21
lines changed

docs/driver-parameters.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ k8s-azure-created-by: azure
5151
pvc-92a4d7f2-f23b-4904-bad4-2cbfcff6e388
5252
```
5353

54+
- VolumeId is identifier for the volume generated after volume is created by plugin successfully, the format of VolumeId is: `rg#accountName#containerName#uuid#secretNamespace#subsID`
55+
5456
### Static Provisioning(bring your own storage container)
5557
> [blobfuse example](../deploy/example/pv-blobfuse-csi.yaml)
5658

pkg/blob/blob.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const (
4949
DefaultDriverName = "blob.csi.azure.com"
5050
blobCSIDriverName = "blob_csi_driver"
5151
separator = "#"
52-
volumeIDTemplate = "%s#%s#%s#%s#%s"
52+
volumeIDTemplate = "%s#%s#%s#%s#%s#%s"
5353
secretNameTemplate = "azure-storage-account-%s-secret"
5454
serverNameField = "server"
5555
storageEndpointSuffixField = "storageendpointsuffix"
@@ -266,20 +266,25 @@ func (d *Driver) Run(endpoint, kubeconfig string, testBool bool) {
266266
}
267267

268268
// GetContainerInfo get container info according to volume id, e.g.
269-
// input: "rg#f5713de20cde511e8ba4900#containerName#uuid"
270-
// output: rg, f5713de20cde511e8ba4900, containerName
271-
// input: "rg#f5713de20cde511e8ba4900#containerName#uuid#namespace"
272-
// output: rg, f5713de20cde511e8ba4900, containerName, namespace
273-
func GetContainerInfo(id string) (string, string, string, string, error) {
269+
// input: "rg#f5713de20cde511e8ba4900#containerName#uuid#"
270+
// output: rg, f5713de20cde511e8ba4900, containerName, "" , ""
271+
// input: "rg#f5713de20cde511e8ba4900#containerName#uuid#namespace#"
272+
// output: rg, f5713de20cde511e8ba4900, containerName, namespace, ""
273+
// input: "rg#f5713de20cde511e8ba4900#containerName#uuid#namespace#subsID"
274+
// output: rg, f5713de20cde511e8ba4900, containerName, namespace, subsID
275+
func GetContainerInfo(id string) (string, string, string, string, string, error) {
274276
segments := strings.Split(id, separator)
275277
if len(segments) < 3 {
276-
return "", "", "", "", fmt.Errorf("error parsing volume id: %q, should at least contain two #", id)
278+
return "", "", "", "", "", fmt.Errorf("error parsing volume id: %q, should at least contain two #", id)
277279
}
278-
var secretNamespace string
280+
var secretNamespace, subsID string
279281
if len(segments) > 4 {
280282
secretNamespace = segments[4]
281283
}
282-
return segments[0], segments[1], segments[2], secretNamespace, nil
284+
if len(segments) > 5 {
285+
subsID = segments[5]
286+
}
287+
return segments[0], segments[1], segments[2], secretNamespace, subsID, nil
283288
}
284289

285290
// A container name must be a valid DNS name, conforming to the following naming rules:
@@ -323,7 +328,7 @@ func isSASToken(key string) bool {
323328

324329
// GetAuthEnv return <accountName, containerName, authEnv, error>
325330
func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attrib, secrets map[string]string) (string, string, string, string, []string, error) {
326-
rgName, accountName, containerName, secretNamespace, err := GetContainerInfo(volumeID)
331+
rgName, accountName, containerName, secretNamespace, _, err := GetContainerInfo(volumeID)
327332
if err != nil {
328333
// ignore volumeID parsing error
329334
klog.V(2).Infof("parsing volumeID(%s) return with error: %v", volumeID, err)
@@ -530,7 +535,7 @@ func (d *Driver) GetStorageAccountAndContainer(ctx context.Context, volumeID str
530535
} else {
531536
if len(secrets) == 0 {
532537
var rgName string
533-
rgName, accountName, containerName, _, err = GetContainerInfo(volumeID)
538+
rgName, accountName, containerName, _, _, err = GetContainerInfo(volumeID)
534539
if err != nil {
535540
return "", "", "", "", err
536541
}

pkg/blob/blob_test.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ func TestGetContainerInfo(t *testing.T) {
173173
account string
174174
container string
175175
namespace string
176+
subsID string
176177
expectedError error
177178
}{
178179
{
@@ -241,13 +242,38 @@ func TestGetContainerInfo(t *testing.T) {
241242
container: "",
242243
expectedError: fmt.Errorf("error parsing volume id: \"\", should at least contain two #"),
243244
},
245+
{
246+
volumeID: "rg#f5713de20cde511e8ba4900#container#uuid#namespace#subsID",
247+
rg: "rg",
248+
account: "f5713de20cde511e8ba4900",
249+
container: "container",
250+
namespace: "namespace",
251+
subsID: "subsID",
252+
expectedError: nil,
253+
},
254+
{
255+
volumeID: "rg#f5713de20cde511e8ba4900#container###subsID",
256+
rg: "rg",
257+
account: "f5713de20cde511e8ba4900",
258+
container: "container",
259+
subsID: "subsID",
260+
expectedError: nil,
261+
},
262+
{
263+
volumeID: "rg#f5713de20cde511e8ba4900#container#uuid#namespace#",
264+
rg: "rg",
265+
account: "f5713de20cde511e8ba4900",
266+
container: "container",
267+
namespace: "namespace",
268+
expectedError: nil,
269+
},
244270
}
245271

246272
for _, test := range tests {
247-
rg, account, container, ns, err := GetContainerInfo(test.volumeID)
273+
rg, account, container, ns, subsID, err := GetContainerInfo(test.volumeID)
248274
if !reflect.DeepEqual(rg, test.rg) || !reflect.DeepEqual(account, test.account) ||
249275
!reflect.DeepEqual(container, test.container) || !reflect.DeepEqual(err, test.expectedError) ||
250-
!reflect.DeepEqual(ns, test.namespace) {
276+
!reflect.DeepEqual(ns, test.namespace) || !reflect.DeepEqual(subsID, test.subsID) {
251277
t.Errorf("input: %q, GetContainerInfo rg: %q, rg: %q, account: %q, account: %q, container: %q, container: %q, namespace: %q, namespace: %q, err: %q, expectedError: %q", test.volumeID, rg, test.rg, account, test.account,
252278
container, test.container, ns, test.namespace, err, test.expectedError)
253279
}

pkg/blob/controllerserver.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
338338
// not necessary for dynamic container name creation since volumeID already contains volume name
339339
uuid = volName
340340
}
341-
volumeID = fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, validContainerName, uuid, secretNamespace)
341+
volumeID = fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, validContainerName, uuid, secretNamespace, subsID)
342342
klog.V(2).Infof("create container %s on storage account %s successfully", validContainerName, accountName)
343343

344344
if useDataPlaneAPI {
@@ -374,7 +374,7 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
374374
}
375375
defer d.volumeLocks.Release(volumeID)
376376

377-
resourceGroupName, accountName, containerName, _, err := GetContainerInfo(volumeID)
377+
resourceGroupName, accountName, containerName, _, subsID, err := GetContainerInfo(volumeID)
378378
if err != nil {
379379
// According to CSI Driver Sanity Tester, should succeed when an invalid volume id is used
380380
klog.Errorf("GetContainerInfo(%s) in DeleteVolume failed with error: %v", volumeID, err)
@@ -402,8 +402,7 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
402402
resourceGroupName = d.cloud.ResourceGroup
403403
}
404404
klog.V(2).Infof("deleting container(%s) rg(%s) account(%s) volumeID(%s)", containerName, resourceGroupName, accountName, volumeID)
405-
// TODO: get subscriptionID from volumeID OR request parameter
406-
if err := d.DeleteBlobContainer(ctx, "", resourceGroupName, accountName, containerName, secrets); err != nil {
405+
if err := d.DeleteBlobContainer(ctx, subsID, resourceGroupName, accountName, containerName, secrets); err != nil {
407406
return nil, status.Errorf(codes.Internal, "failed to delete container(%s) under rg(%s) account(%s) volumeID(%s), error: %v", containerName, resourceGroupName, accountName, volumeID, err)
408407
}
409408

@@ -422,7 +421,7 @@ func (d *Driver) ValidateVolumeCapabilities(ctx context.Context, req *csi.Valida
422421
return nil, status.Error(codes.InvalidArgument, err.Error())
423422
}
424423

425-
resourceGroupName, accountName, containerName, _, err := GetContainerInfo(volumeID)
424+
resourceGroupName, accountName, containerName, _, subsID, err := GetContainerInfo(volumeID)
426425
if err != nil {
427426
klog.Errorf("GetContainerInfo(%s) in ValidateVolumeCapabilities failed with error: %v", volumeID, err)
428427
return nil, status.Error(codes.NotFound, err.Error())
@@ -443,8 +442,7 @@ func (d *Driver) ValidateVolumeCapabilities(ctx context.Context, req *csi.Valida
443442
if resourceGroupName == "" {
444443
resourceGroupName = d.cloud.ResourceGroup
445444
}
446-
// TODO: get subscriptionID from volumeID OR request parameter
447-
blobContainer, retryErr := d.cloud.BlobClient.GetContainer(ctx, "", resourceGroupName, accountName, containerName)
445+
blobContainer, retryErr := d.cloud.BlobClient.GetContainer(ctx, subsID, resourceGroupName, accountName, containerName)
448446
err = retryErr.Error()
449447
if err != nil {
450448
return nil, status.Error(codes.Internal, err.Error())

test/e2e/testsuites/pre_provisioned_existing_credentials_tester.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type PreProvisionedExistingCredentialsTest struct {
3939
func (t *PreProvisionedExistingCredentialsTest) Run(client clientset.Interface, namespace *v1.Namespace) {
4040
for _, pod := range t.Pods {
4141
for n, volume := range pod.Volumes {
42-
resourceGroupName, accountName, containerName, _, err := blob.GetContainerInfo(volume.VolumeID)
42+
resourceGroupName, accountName, containerName, _, _, err := blob.GetContainerInfo(volume.VolumeID)
4343
if err != nil {
4444
framework.ExpectNoError(err, fmt.Sprintf("Error GetContainerInfo from volumeID(%s): %v", volume.VolumeID, err))
4545
return

0 commit comments

Comments
 (0)