Skip to content

Commit d840b39

Browse files
authored
Merge pull request #1595 from k8s-infra-cherrypick-robot/cherry-pick-1592-to-release-1.28
[release-1.28] feat: append default nfs mount options
2 parents edf616e + fc3c174 commit d840b39

File tree

4 files changed

+101
-5
lines changed

4 files changed

+101
-5
lines changed

pkg/azurefile/azurefile.go

+48-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const (
6363
fileMode = "file_mode"
6464
dirMode = "dir_mode"
6565
actimeo = "actimeo"
66+
noResvPort = "noresvport"
6667
mfsymlinks = "mfsymlinks"
6768
defaultFileMode = "0777"
6869
defaultDirMode = "0777"
@@ -212,6 +213,8 @@ type DriverOptions struct {
212213
EnableWindowsHostProcess bool
213214
AppendClosetimeoOption bool
214215
AppendNoShareSockOption bool
216+
AppendNoResvPortOption bool
217+
AppendActimeoOption bool
215218
SkipMatchingTagCacheExpireInMinutes int
216219
VolStatsCacheExpireInMinutes int
217220
PrintVolumeStatsCallLogs bool
@@ -239,6 +242,8 @@ type Driver struct {
239242
enableWindowsHostProcess bool
240243
appendClosetimeoOption bool
241244
appendNoShareSockOption bool
245+
appendNoResvPortOption bool
246+
appendActimeoOption bool
242247
printVolumeStatsCallLogs bool
243248
fileClient *azureFileClient
244249
mounter *mount.SafeFormatAndMount
@@ -295,6 +300,8 @@ func NewDriver(options *DriverOptions) *Driver {
295300
driver.enableWindowsHostProcess = options.EnableWindowsHostProcess
296301
driver.appendClosetimeoOption = options.AppendClosetimeoOption
297302
driver.appendNoShareSockOption = options.AppendNoShareSockOption
303+
driver.appendNoResvPortOption = options.AppendNoResvPortOption
304+
driver.appendActimeoOption = options.AppendActimeoOption
298305
driver.printVolumeStatsCallLogs = options.PrintVolumeStatsCallLogs
299306
driver.sasTokenExpirationMinutes = options.SasTokenExpirationMinutes
300307
driver.volLockMap = newLockMap()
@@ -470,7 +477,7 @@ func GetFileShareInfo(id string) (string, string, string, string, string, string
470477
}
471478

472479
// check whether mountOptions contains file_mode, dir_mode, vers, if not, append default mode
473-
func appendDefaultMountOptions(mountOptions []string, appendNoShareSockOption, appendClosetimeoOption bool) []string {
480+
func appendDefaultCifsMountOptions(mountOptions []string, appendNoShareSockOption, appendClosetimeoOption bool) []string {
474481
var defaultMountOptions = map[string]string{
475482
fileMode: defaultFileMode,
476483
dirMode: defaultDirMode,
@@ -515,6 +522,46 @@ func appendDefaultMountOptions(mountOptions []string, appendNoShareSockOption, a
515522
return allMountOptions
516523
}
517524

525+
// check whether mountOptions contains actimeo, if not, append default mode
526+
func appendDefaultNfsMountOptions(mountOptions []string, appendNoResvPortOption, appendActimeoOption bool) []string {
527+
var defaultMountOptions = map[string]string{}
528+
if appendNoResvPortOption {
529+
defaultMountOptions[noResvPort] = ""
530+
}
531+
if appendActimeoOption {
532+
defaultMountOptions[actimeo] = defaultActimeo
533+
}
534+
535+
if len(defaultMountOptions) == 0 {
536+
return mountOptions
537+
}
538+
539+
// stores the mount options already included in mountOptions
540+
included := make(map[string]bool)
541+
542+
for _, mountOption := range mountOptions {
543+
for k := range defaultMountOptions {
544+
if strings.HasPrefix(mountOption, k) {
545+
included[k] = true
546+
}
547+
}
548+
}
549+
550+
allMountOptions := mountOptions
551+
552+
for k, v := range defaultMountOptions {
553+
if _, isIncluded := included[k]; !isIncluded {
554+
if v != "" {
555+
allMountOptions = append(allMountOptions, fmt.Sprintf("%s=%s", k, v))
556+
} else {
557+
allMountOptions = append(allMountOptions, k)
558+
}
559+
}
560+
}
561+
562+
return allMountOptions
563+
}
564+
518565
// get storage account from secrets map
519566
func getStorageAccount(secrets map[string]string) (string, string, error) {
520567
if secrets == nil {

pkg/azurefile/azurefile_test.go

+47-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestNewFakeDriver(t *testing.T) {
101101
assert.NotNil(t, d)
102102
}
103103

104-
func TestAppendDefaultMountOptions(t *testing.T) {
104+
func TestAppendDefaultCifsMountOptions(t *testing.T) {
105105
tests := []struct {
106106
options []string
107107
appendClosetimeoOption bool
@@ -231,12 +231,56 @@ func TestAppendDefaultMountOptions(t *testing.T) {
231231
}
232232

233233
for _, test := range tests {
234-
result := appendDefaultMountOptions(test.options, test.appendNoShareSockOption, test.appendClosetimeoOption)
234+
result := appendDefaultCifsMountOptions(test.options, test.appendNoShareSockOption, test.appendClosetimeoOption)
235235
sort.Strings(result)
236236
sort.Strings(test.expected)
237237

238238
if !reflect.DeepEqual(result, test.expected) {
239-
t.Errorf("input: %q, appendDefaultMountOptions result: %q, expected: %q", test.options, result, test.expected)
239+
t.Errorf("input: %q, appendDefaultCifsMountOptions result: %q, expected: %q", test.options, result, test.expected)
240+
}
241+
}
242+
}
243+
244+
func TestAppendDefaultNfsMountOptions(t *testing.T) {
245+
tests := []struct {
246+
options []string
247+
appendNoResvPortOption bool
248+
appendActimeoOption bool
249+
expected []string
250+
}{
251+
{
252+
options: []string{""},
253+
appendNoResvPortOption: false,
254+
appendActimeoOption: false,
255+
expected: []string{""},
256+
},
257+
{
258+
options: []string{},
259+
appendNoResvPortOption: true,
260+
appendActimeoOption: true,
261+
expected: []string{fmt.Sprintf("%s=%s", actimeo, defaultActimeo), noResvPort},
262+
},
263+
{
264+
options: []string{noResvPort},
265+
appendNoResvPortOption: true,
266+
appendActimeoOption: true,
267+
expected: []string{fmt.Sprintf("%s=%s", actimeo, defaultActimeo), noResvPort},
268+
},
269+
{
270+
options: []string{fmt.Sprintf("%s=%s", actimeo, "60")},
271+
appendNoResvPortOption: true,
272+
appendActimeoOption: true,
273+
expected: []string{fmt.Sprintf("%s=%s", actimeo, "60"), noResvPort},
274+
},
275+
}
276+
277+
for _, test := range tests {
278+
result := appendDefaultNfsMountOptions(test.options, test.appendNoResvPortOption, test.appendActimeoOption)
279+
sort.Strings(result)
280+
sort.Strings(test.expected)
281+
282+
if !reflect.DeepEqual(result, test.expected) {
283+
t.Errorf("input: %q, appendDefaultNfsMountOptions result: %q, expected: %q", test.options, result, test.expected)
240284
}
241285
}
242286
}

pkg/azurefile/nodeserver.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
286286
var mountOptions, sensitiveMountOptions []string
287287
if protocol == nfs {
288288
mountOptions = util.JoinMountOptions(mountFlags, []string{"vers=4,minorversion=1,sec=sys"})
289+
mountOptions = appendDefaultNfsMountOptions(mountOptions, d.appendNoResvPortOption, d.appendActimeoOption)
289290
} else {
290291
if accountName == "" || accountKey == "" {
291292
return nil, status.Errorf(codes.Internal, "accountName(%s) or accountKey is empty", accountName)
@@ -302,7 +303,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
302303
if ephemeralVol {
303304
cifsMountFlags = util.JoinMountOptions(cifsMountFlags, strings.Split(ephemeralVolMountOptions, ","))
304305
}
305-
mountOptions = appendDefaultMountOptions(cifsMountFlags, d.appendNoShareSockOption, d.appendClosetimeoOption)
306+
mountOptions = appendDefaultCifsMountOptions(cifsMountFlags, d.appendNoShareSockOption, d.appendClosetimeoOption)
306307
}
307308
}
308309

pkg/azurefileplugin/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ var (
5959
enableWindowsHostProcess = flag.Bool("enable-windows-host-process", false, "enable windows host process")
6060
appendClosetimeoOption = flag.Bool("append-closetimeo-option", false, "Whether appending closetimeo=0 option to smb mount command")
6161
appendNoShareSockOption = flag.Bool("append-nosharesock-option", true, "Whether appending nosharesock option to smb mount command")
62+
appendNoResvPortOption = flag.Bool("append-noresvport-option", true, "Whether appending noresvport option to nfs mount command")
63+
appendActimeoOption = flag.Bool("append-actimeo-option", true, "Whether appending actimeo=0 option to nfs mount command")
6264
skipMatchingTagCacheExpireInMinutes = flag.Int("skip-matching-tag-cache-expire-in-minutes", 30, "The cache expire time in minutes for skipMatchingTagCache")
6365
volStatsCacheExpireInMinutes = flag.Int("vol-stats-cache-expire-in-minutes", 10, "The cache expire time in minutes for volume stats cache")
6466
printVolumeStatsCallLogs = flag.Bool("print-volume-stats-call-logs", false, "Whether to print volume statfs call logs with log level 2")
@@ -107,6 +109,8 @@ func handle() {
107109
EnableWindowsHostProcess: *enableWindowsHostProcess,
108110
AppendClosetimeoOption: *appendClosetimeoOption,
109111
AppendNoShareSockOption: *appendNoShareSockOption,
112+
AppendNoResvPortOption: *appendNoResvPortOption,
113+
AppendActimeoOption: *appendActimeoOption,
110114
SkipMatchingTagCacheExpireInMinutes: *skipMatchingTagCacheExpireInMinutes,
111115
VolStatsCacheExpireInMinutes: *volStatsCacheExpireInMinutes,
112116
PrintVolumeStatsCallLogs: *printVolumeStatsCallLogs,

0 commit comments

Comments
 (0)