Skip to content

Commit 4357c74

Browse files
andyzhangxk8s-infra-cherrypick-robot
authored andcommitted
feat: support encryptInTransit mountOption in nfs volume
fix
1 parent a65319b commit 4357c74

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

pkg/azurefile/nodeserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
410410
mountFsType := cifs
411411
if protocol == nfs {
412412
mountFsType = nfs
413+
if newOptions, exists := removeOptionIfExists(mountOptions, encryptInTransitField); exists {
414+
klog.V(2).Infof("encryptInTransit is set in mountOptions(%v), enabling encryptInTransit", mountOptions)
415+
encryptInTransit = true
416+
mountOptions = newOptions
417+
}
413418
if encryptInTransit {
414419
mountFsType = aznfs
415420
}

pkg/azurefile/utils.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,14 @@ func getFileServiceURL(accountName, storageEndpointSuffix string) string {
361361
func isValidSubscriptionID(subsID string) bool {
362362
return regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`).MatchString(subsID)
363363
}
364+
365+
// RemoveOptionIfExists removes the given option from the list of options
366+
// return the new list and a boolean indicating whether the option was found.
367+
func removeOptionIfExists(options []string, removeOption string) ([]string, bool) {
368+
for i, option := range options {
369+
if strings.EqualFold(option, removeOption) {
370+
return append(options[:i], options[i+1:]...), true
371+
}
372+
}
373+
return options, false
374+
}

pkg/azurefile/utils_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,3 +1028,71 @@ func TestIsValidSubscriptionID(t *testing.T) {
10281028
}
10291029
}
10301030
}
1031+
1032+
func TestRemoveOptionIfExists(t *testing.T) {
1033+
tests := []struct {
1034+
desc string
1035+
options []string
1036+
removeOption string
1037+
expectedOptions []string
1038+
expected bool
1039+
}{
1040+
{
1041+
desc: "nil options",
1042+
removeOption: "option",
1043+
expected: false,
1044+
},
1045+
{
1046+
desc: "empty options",
1047+
options: []string{},
1048+
removeOption: "option",
1049+
expectedOptions: []string{},
1050+
expected: false,
1051+
},
1052+
{
1053+
desc: "option not found",
1054+
options: []string{"option1", "option2"},
1055+
removeOption: "option",
1056+
expectedOptions: []string{"option1", "option2"},
1057+
expected: false,
1058+
},
1059+
{
1060+
desc: "option found in the last element",
1061+
options: []string{"option1", "option2", "option"},
1062+
removeOption: "option",
1063+
expectedOptions: []string{"option1", "option2"},
1064+
expected: true,
1065+
},
1066+
{
1067+
desc: "option found in the first element",
1068+
options: []string{"option", "option1", "option2"},
1069+
removeOption: "option",
1070+
expectedOptions: []string{"option1", "option2"},
1071+
expected: true,
1072+
},
1073+
{
1074+
desc: "option found in the middle element",
1075+
options: []string{"option1", "option", "option2"},
1076+
removeOption: "option",
1077+
expectedOptions: []string{"option1", "option2"},
1078+
expected: true,
1079+
},
1080+
{
1081+
desc: "option found with case insensitive match",
1082+
options: []string{"option1", "encryptInTransit", "option2"},
1083+
removeOption: "encryptintransit",
1084+
expectedOptions: []string{"option1", "option2"},
1085+
expected: true,
1086+
},
1087+
}
1088+
1089+
for _, test := range tests {
1090+
result, exists := removeOptionIfExists(test.options, test.removeOption)
1091+
if !reflect.DeepEqual(result, test.expectedOptions) {
1092+
t.Errorf("test[%s]: unexpected output: %v, expected result: %v", test.desc, result, test.expectedOptions)
1093+
}
1094+
if exists != test.expected {
1095+
t.Errorf("test[%s]: unexpected output: %v, expected result: %v", test.desc, exists, test.expected)
1096+
}
1097+
}
1098+
}

test/e2e/dynamic_provisioning_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,48 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
15291529
test.Run(ctx, cs, ns)
15301530
})
15311531

1532+
ginkgo.It("should create a NFS volume on demand on a storage account with encryptInTransit enabled within mountOptions [file.csi.azure.com] [nfs]", func(ctx ginkgo.SpecContext) {
1533+
skipIfUsingInTreeVolumePlugin()
1534+
skipIfTestingInWindowsCluster()
1535+
if !supportEncryptInTransitwithNFS {
1536+
ginkgo.Skip("encryptInTransit on nfs file share is not supported on current region")
1537+
}
1538+
1539+
pods := []testsuites.PodDetails{
1540+
{
1541+
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
1542+
Volumes: []testsuites.VolumeDetails{
1543+
{
1544+
ClaimSize: "100Gi",
1545+
MountOptions: []string{
1546+
"nconnect=4",
1547+
"rsize=1048576",
1548+
"wsize=1048576",
1549+
"noresvport",
1550+
"actimeo=30",
1551+
"encryptInTransit",
1552+
},
1553+
VolumeMount: testsuites.VolumeMountDetails{
1554+
NameGenerate: "test-volume-",
1555+
MountPathGenerate: "/mnt/test-",
1556+
},
1557+
},
1558+
},
1559+
IsWindows: isWindowsCluster,
1560+
WinServerVer: winServerVer,
1561+
},
1562+
}
1563+
scParameters := map[string]string{
1564+
"protocol": "nfs",
1565+
}
1566+
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
1567+
CSIDriver: testDriver,
1568+
Pods: pods,
1569+
StorageClassParameters: scParameters,
1570+
}
1571+
test.Run(ctx, cs, ns)
1572+
})
1573+
15321574
ginkgo.It("should create a pod with multiple NFS volumes [file.csi.azure.com]", func(ctx ginkgo.SpecContext) {
15331575
skipIfTestingInWindowsCluster()
15341576
skipIfUsingInTreeVolumePlugin()

0 commit comments

Comments
 (0)