Skip to content

Commit d891051

Browse files
authored
Merge pull request #1990 from k8s-infra-cherrypick-robot/cherry-pick-1989-to-release-1.30
[release-1.30] feat: add metadata tag on the storage account created by the driver
2 parents 6667cfe + ce2be26 commit d891051

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

pkg/azurefile/controllerserver.go

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ const (
6464
SPN = "SPN"
6565

6666
authorizationPermissionMismatch = "AuthorizationPermissionMismatch"
67+
68+
createdByMetadata = "createdBy"
6769
)
6870

6971
var (
@@ -569,6 +571,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
569571
RequestGiB: fileShareSize,
570572
AccessTier: shareAccessTier,
571573
RootSquash: rootSquashType,
574+
Metadata: map[string]*string{createdByMetadata: pointer.String(d.Name)},
572575
}
573576

574577
klog.V(2).Infof("begin to create file share(%s) on account(%s) type(%s) subID(%s) rg(%s) location(%s) size(%d) protocol(%s)", validFileShareName, accountName, sku, subsID, resourceGroup, location, fileShareSize, shareProtocol)

pkg/azurefile/controllerserver_test.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -1399,8 +1399,6 @@ func TestCreateVolume(t *testing.T) {
13991399
CapacityRange: capRange,
14001400
}
14011401

1402-
expectedShareOptions := &fileclient.ShareOptions{Name: "vol-1", Protocol: "SMB", RequestGiB: 100, AccessTier: "", RootSquash: "", Metadata: nil}
1403-
14041402
d := NewFakeDriver()
14051403

14061404
ctrl := gomock.NewController(t)
@@ -1410,7 +1408,7 @@ func TestCreateVolume(t *testing.T) {
14101408
d.cloud.StorageAccountClient = mockStorageAccountsClient
14111409

14121410
mockFileClient.EXPECT().WithSubscriptionID(gomock.Any()).Return(mockFileClient).AnyTimes()
1413-
mockFileClient.EXPECT().CreateFileShare(context.TODO(), gomock.Any(), gomock.Any(), expectedShareOptions, gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: nil}}, nil).AnyTimes()
1411+
mockFileClient.EXPECT().CreateFileShare(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: nil}}, nil).AnyTimes()
14141412
mockFileClient.EXPECT().GetFileShare(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, nil).AnyTimes()
14151413
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(keys, nil).AnyTimes()
14161414
mockStorageAccountsClient.EXPECT().ListByResourceGroup(gomock.Any(), gomock.Any(), gomock.Any()).Return(accounts, nil).AnyTimes()
@@ -1460,8 +1458,6 @@ func TestCreateVolume(t *testing.T) {
14601458
CapacityRange: capRange,
14611459
}
14621460

1463-
expectedShareOptions := &fileclient.ShareOptions{Name: "vol-1", Protocol: "SMB", RequestGiB: 100, AccessTier: "", RootSquash: "", Metadata: nil}
1464-
14651461
d := NewFakeDriver()
14661462

14671463
ctrl := gomock.NewController(t)
@@ -1471,7 +1467,7 @@ func TestCreateVolume(t *testing.T) {
14711467
d.cloud.StorageAccountClient = mockStorageAccountsClient
14721468

14731469
mockFileClient.EXPECT().WithSubscriptionID(gomock.Any()).Return(mockFileClient).AnyTimes()
1474-
mockFileClient.EXPECT().CreateFileShare(context.TODO(), gomock.Any(), gomock.Any(), expectedShareOptions, gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: nil}}, nil).AnyTimes()
1470+
mockFileClient.EXPECT().CreateFileShare(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: nil}}, nil).AnyTimes()
14751471
mockFileClient.EXPECT().GetFileShare(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, nil).AnyTimes()
14761472
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(keys, nil).AnyTimes()
14771473
mockStorageAccountsClient.EXPECT().ListByResourceGroup(gomock.Any(), gomock.Any(), gomock.Any()).Return(accounts, nil).AnyTimes()
@@ -1519,8 +1515,6 @@ func TestCreateVolume(t *testing.T) {
15191515
CapacityRange: capRange,
15201516
}
15211517

1522-
expectedShareOptions := &fileclient.ShareOptions{Name: "vol-1", Protocol: "SMB", RequestGiB: 1, AccessTier: "", RootSquash: "", Metadata: nil}
1523-
15241518
d := NewFakeDriver()
15251519

15261520
ctrl := gomock.NewController(t)
@@ -1530,7 +1524,7 @@ func TestCreateVolume(t *testing.T) {
15301524
d.cloud.StorageAccountClient = mockStorageAccountsClient
15311525

15321526
mockFileClient.EXPECT().WithSubscriptionID(gomock.Any()).Return(mockFileClient).AnyTimes()
1533-
mockFileClient.EXPECT().CreateFileShare(context.TODO(), gomock.Any(), gomock.Any(), expectedShareOptions, gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: nil}}, nil).AnyTimes()
1527+
mockFileClient.EXPECT().CreateFileShare(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: nil}}, nil).AnyTimes()
15341528
mockFileClient.EXPECT().GetFileShare(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, nil).AnyTimes()
15351529
mockStorageAccountsClient.EXPECT().ListKeys(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(keys, nil).AnyTimes()
15361530
mockStorageAccountsClient.EXPECT().ListByResourceGroup(gomock.Any(), gomock.Any(), gomock.Any()).Return(accounts, nil).AnyTimes()

0 commit comments

Comments
 (0)