diff --git a/pkg/blob/blob.go b/pkg/blob/blob.go index 7271bdd97..304458980 100644 --- a/pkg/blob/blob.go +++ b/pkg/blob/blob.go @@ -720,6 +720,12 @@ func isSupportedContainerNamePrefix(prefix string) bool { return true } +// isNFSProtocol checks if the protocol is NFS or AZNFS +func isNFSProtocol(protocol string) bool { + protocol = strings.ToLower(protocol) + return protocol == NFS || protocol == AZNFS +} + // get storage account from secrets map func getStorageAccount(secrets map[string]string) (string, string, error) { if secrets == nil { diff --git a/pkg/blob/blob_test.go b/pkg/blob/blob_test.go index 4b22b7ae6..426f75d99 100644 --- a/pkg/blob/blob_test.go +++ b/pkg/blob/blob_test.go @@ -1659,3 +1659,46 @@ func TestIsSupportedAccessTier(t *testing.T) { } } } + +func TestIsNFSProtocol(t *testing.T) { + tests := []struct { + protocol string + expectedResult bool + }{ + { + protocol: "", + expectedResult: false, + }, + { + protocol: "NFS", + expectedResult: true, + }, + { + protocol: "nfs", + expectedResult: true, + }, + { + protocol: "Nfs", + expectedResult: true, + }, + { + protocol: "NFSv3", + expectedResult: false, + }, + { + protocol: "aznfs", + expectedResult: true, + }, + { + protocol: "azNfs", + expectedResult: true, + }, + } + + for _, test := range tests { + result := isNFSProtocol(test.protocol) + if result != test.expectedResult { + t.Errorf("isNFSVolume(%s) returned with %v, not equal to %v", test.protocol, result, test.expectedResult) + } + } +} diff --git a/pkg/blob/controllerserver.go b/pkg/blob/controllerserver.go index 1268ed968..120915701 100644 --- a/pkg/blob/controllerserver.go +++ b/pkg/blob/controllerserver.go @@ -192,7 +192,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) } if pointer.BoolDeref(enableBlobVersioning, false) { - if protocol == NFS || pointer.BoolDeref(isHnsEnabled, false) { + if isNFSProtocol(protocol) || pointer.BoolDeref(isHnsEnabled, false) { return nil, status.Errorf(codes.InvalidArgument, "enableBlobVersioning is not supported for NFS protocol or HNS enabled account") } } @@ -202,7 +202,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) } if subsID != "" && subsID != d.cloud.SubscriptionID { - if protocol == NFS { + if isNFSProtocol(protocol) { return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("NFS protocol is not supported in cross subscription(%s)", subsID)) } if !storeAccountKey { @@ -249,7 +249,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) vnetResourceIDs []string enableNfsV3 *bool ) - if protocol == NFS { + if isNFSProtocol(protocol) { isHnsEnabled = pointer.Bool(true) enableNfsV3 = pointer.Bool(true) // NFS protocol does not need account key @@ -359,7 +359,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) } } - if createPrivateEndpoint && protocol == NFS { + if createPrivateEndpoint && isNFSProtocol(protocol) { // As for blobfuse/blobfuse2, serverName, i.e.,AZURE_STORAGE_BLOB_ENDPOINT env variable can't include // "privatelink", issue: https://github.com/Azure/azure-storage-fuse/issues/1014 // diff --git a/pkg/blob/nodeserver.go b/pkg/blob/nodeserver.go index ca49e18ce..c638d5498 100644 --- a/pkg/blob/nodeserver.go +++ b/pkg/blob/nodeserver.go @@ -311,7 +311,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe serverAddress = fmt.Sprintf("%s.blob.%s", accountName, storageEndpointSuffix) } - if protocol == NFS { + if isNFSProtocol(protocol) { klog.V(2).Infof("target %v\nprotocol %v\n\nvolumeId %v\ncontext %v\nmountflags %v\nserverAddress %v", targetPath, protocol, volumeID, attrib, mountFlags, serverAddress)