Skip to content

Commit 1be50c0

Browse files
committed
feat: add matchTags parameter in storage class
1 parent ee6db05 commit 1be50c0

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

docs/driver-parameters.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ containerName | specify the existing container(directory) name | existing contai
1717
containerNamePrefix | specify Azure storage directory prefix created by driver | can only contain lowercase letters, numbers, hyphens, and length should be less than 21 | No |
1818
server | specify Azure storage account server address | existing server address, e.g. `accountname.privatelink.blob.core.windows.net` | No | if empty, driver will use default `accountname.blob.core.windows.net` or other sovereign cloud account address
1919
allowBlobPublicAccess | Allow or disallow public access to all blobs or containers for storage account created by driver | `true`,`false` | No | `false`
20-
storageEndpointSuffix | specify Azure storage endpoint suffix | `core.windows.net` | No | if empty, driver will use default storage endpoint suffix according to cloud environment, e.g. `core.windows.net`
20+
storageEndpointSuffix | specify Azure storage endpoint suffix | `core.windows.net`, `core.chinacloudapi.cn`, etc | No | if empty, driver will use default storage endpoint suffix according to cloud environment
2121
tags | [tags](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-resources) would be created in newly created storage account | tag format: 'foo=aaa,bar=bbb' | No | ""
22+
matchTags | whether matching tags when driver tries to find a suitable storage account | `true`,`false` | No | `false`
2223
--- | **Following parameters are only for blobfuse** | --- | --- |
2324
subscriptionID | specify Azure subscription ID in which blob storage directory will be created | Azure subscription ID | No | if not empty, `resourceGroup` must be provided
2425
storeAccountKey | whether store account key to k8s secret <br><br> Note: <br> `false` means driver would leverage kubelet identity to get account key | `true`,`false` | No | `true`

pkg/blob/blob.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const (
5252
serverNameField = "server"
5353
storageEndpointSuffixField = "storageendpointsuffix"
5454
tagsField = "tags"
55+
matchTagsField = "matchtags"
5556
protocolField = "protocol"
5657
accountNameField = "accountname"
5758
accountKeyField = "accountkey"

pkg/blob/controllerserver.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
7070
var storageAccountType, subsID, resourceGroup, location, account, containerName, containerNamePrefix, protocol, customTags, secretName, secretNamespace, pvcNamespace string
7171
var isHnsEnabled *bool
7272
var vnetResourceGroup, vnetName, subnetName string
73+
var matchTags bool
7374
// set allowBlobPublicAccess as false by default
7475
allowBlobPublicAccess := to.BoolPtr(false)
7576

@@ -100,6 +101,8 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
100101
protocol = v
101102
case tagsField:
102103
customTags = v
104+
case matchTagsField:
105+
matchTags = strings.EqualFold(v, trueValue)
103106
case secretNameField:
104107
secretName = v
105108
case secretNamespaceField:
@@ -144,6 +147,10 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
144147
}
145148
}
146149

150+
if matchTags && account != "" {
151+
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("matchTags must set as false when storageAccount(%s) is provided", account))
152+
}
153+
147154
if subsID != "" && subsID != d.cloud.SubscriptionID {
148155
if protocol == nfs {
149156
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("NFS protocol is not supported in cross subscription(%s)", subsID))
@@ -225,6 +232,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
225232
EnableHTTPSTrafficOnly: enableHTTPSTrafficOnly,
226233
VirtualNetworkResourceIDs: vnetResourceIDs,
227234
Tags: tags,
235+
MatchTags: matchTags,
228236
IsHnsEnabled: isHnsEnabled,
229237
EnableNfsV3: enableNfsV3,
230238
AllowBlobPublicAccess: allowBlobPublicAccess,

pkg/blob/controllerserver_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,30 @@ func TestCreateVolume(t *testing.T) {
171171
}
172172
},
173173
},
174+
{
175+
name: "storageAccount and matchTags conflict",
176+
testFunc: func(t *testing.T) {
177+
d := NewFakeDriver()
178+
d.cloud = &azure.Cloud{}
179+
mp := map[string]string{
180+
storageAccountField: "abc",
181+
matchTagsField: "true",
182+
}
183+
req := &csi.CreateVolumeRequest{
184+
Name: "unit-test",
185+
VolumeCapabilities: stdVolumeCapabilities,
186+
Parameters: mp,
187+
}
188+
d.Cap = []*csi.ControllerServiceCapability{
189+
controllerServiceCapability,
190+
}
191+
_, err := d.CreateVolume(context.Background(), req)
192+
expectedErr := status.Errorf(codes.InvalidArgument, "matchTags must set as false when storageAccount(abc) is provided")
193+
if !reflect.DeepEqual(err, expectedErr) {
194+
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
195+
}
196+
},
197+
},
174198
{
175199
name: "containerName and containerNamePrefix could not be specified together",
176200
testFunc: func(t *testing.T) {

test/e2e/dynamic_provisioning_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,12 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Dynamic Provisioning", func() {
426426
},
427427
}
428428
test := testsuites.DynamicallyProvisionedResizeVolumeTest{
429-
CSIDriver: testDriver,
430-
Pods: pods,
431-
StorageClassParameters: map[string]string{"skuName": "Standard_LRS"},
429+
CSIDriver: testDriver,
430+
Pods: pods,
431+
StorageClassParameters: map[string]string{
432+
"skuName": "Standard_LRS",
433+
"matchTags": "true",
434+
},
432435
}
433436
test.Run(cs, ns)
434437
})

0 commit comments

Comments
 (0)