Skip to content

Commit dc6e96a

Browse files
committed
feat: NFSv3 account dynamic creation support
1 parent 3732fd9 commit dc6e96a

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

pkg/blob/blob.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ const (
8383

8484
// containerMaxSize is the max size of the blob container. See https://docs.microsoft.com/en-us/azure/storage/blobs/scalability-targets#scale-targets-for-blob-storage
8585
containerMaxSize = 100 * util.TiB
86+
87+
subnetTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s"
8688
)
8789

8890
var (
@@ -536,3 +538,18 @@ func (d *Driver) GetStorageAccesskeyFromSecret(accountName, secretNamespace stri
536538

537539
return string(secret.Data[defaultSecretAccountKey][:]), nil
538540
}
541+
542+
// getSubnetResourceID get default subnet resource ID from cloud provider config
543+
func (d *Driver) getSubnetResourceID() string {
544+
subsID := d.cloud.SubscriptionID
545+
if len(d.cloud.NetworkResourceSubscriptionID) > 0 {
546+
subsID = d.cloud.NetworkResourceSubscriptionID
547+
}
548+
549+
rg := d.cloud.ResourceGroup
550+
if len(d.cloud.VnetResourceGroup) > 0 {
551+
rg = d.cloud.VnetResourceGroup
552+
}
553+
554+
return fmt.Sprintf(subnetTemplate, subsID, rg, d.cloud.VnetName, d.cloud.SubnetName)
555+
}

pkg/blob/controllerserver.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-02-01/storage"
2828
azstorage "github.com/Azure/azure-sdk-for-go/storage"
29+
"github.com/Azure/go-autorest/autorest/to"
2930
"github.com/container-storage-interface/spec/lib/go/csi"
3031

3132
"k8s.io/apimachinery/pkg/util/wait"
@@ -111,16 +112,21 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
111112
}
112113

113114
enableHTTPSTrafficOnly := true
115+
accountKind := string(storage.KindStorageV2)
116+
var vnetResourceIDs []string
117+
var isHnsEnabled, enableNfsV3 *bool
114118
if protocol == nfs {
115-
if account == "" {
116-
return nil, status.Errorf(codes.InvalidArgument, "storage account must be specified when provisioning nfs file share")
117-
}
118119
enableHTTPSTrafficOnly = false
120+
isHnsEnabled = to.BoolPtr(true)
121+
enableNfsV3 = to.BoolPtr(true)
122+
// set VirtualNetworkResourceIDs for storage account firewall setting
123+
vnetResourceID := d.getSubnetResourceID()
124+
klog.V(2).Infof("set vnetResourceID(%s) for NFS protocol", vnetResourceID)
125+
vnetResourceIDs = []string{vnetResourceID}
119126
// NFS protocol does not need account key
120127
storeAccountKey = storeAccountKeyFalse
121128
}
122129

123-
accountKind := string(storage.KindStorageV2)
124130
if strings.HasPrefix(strings.ToLower(storageAccountType), "premium") {
125131
accountKind = string(storage.KindBlockBlobStorage)
126132
}
@@ -137,13 +143,16 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
137143
}
138144

139145
accountOptions := &azure.AccountOptions{
140-
Name: account,
141-
Type: storageAccountType,
142-
Kind: accountKind,
143-
ResourceGroup: resourceGroup,
144-
Location: location,
145-
EnableHTTPSTrafficOnly: enableHTTPSTrafficOnly,
146-
Tags: tags,
146+
Name: account,
147+
Type: storageAccountType,
148+
Kind: accountKind,
149+
ResourceGroup: resourceGroup,
150+
Location: location,
151+
EnableHTTPSTrafficOnly: enableHTTPSTrafficOnly,
152+
VirtualNetworkResourceIDs: vnetResourceIDs,
153+
Tags: tags,
154+
IsHnsEnabled: isHnsEnabled,
155+
EnableNfsV3: enableNfsV3,
147156
}
148157

149158
var accountKey string

pkg/blob/controllerserver_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -143,28 +143,6 @@ func TestCreateVolume(t *testing.T) {
143143
}
144144
},
145145
},
146-
{
147-
name: "storageacount empty while nfs",
148-
testFunc: func(t *testing.T) {
149-
d := NewFakeDriver()
150-
d.cloud = &azure.Cloud{}
151-
mp := make(map[string]string)
152-
mp["protocol"] = "nfs"
153-
req := &csi.CreateVolumeRequest{
154-
Name: "unit-test",
155-
VolumeCapabilities: stdVolumeCapabilities,
156-
Parameters: mp,
157-
}
158-
d.Cap = []*csi.ControllerServiceCapability{
159-
controllerServiceCapability,
160-
}
161-
_, err := d.CreateVolume(context.Background(), req)
162-
expectedErr := status.Errorf(codes.InvalidArgument, "storage account must be specified when provisioning nfs file share")
163-
if !reflect.DeepEqual(err, expectedErr) {
164-
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
165-
}
166-
},
167-
},
168146
{
169147
name: "tags error",
170148
testFunc: func(t *testing.T) {

0 commit comments

Comments
 (0)