Skip to content

Commit a23fbae

Browse files
authored
Merge pull request #1423 from AlbeeSo/feat/add-ossfs1-def-options
ossfs 1.0: add default option: listobjectsv2
2 parents de78ea7 + 0986cb2 commit a23fbae

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

pkg/mounter/oss/ossfs.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,20 +298,29 @@ func (f *fuseOssfs) getAuthOptions(o *Options, region string) (mountOptions []st
298298
return
299299
}
300300

301+
const (
302+
KeyDbgLevel = "dbglevel"
303+
KeyMime = "mime"
304+
KeyListObjectsV2 = "listobjectsv2"
305+
)
306+
301307
func (f *fuseOssfs) AddDefaultMountOptions(options []string) []string {
302308
defaultOSSFSOptions := os.Getenv("DEFAULT_OSSFS_OPTIONS")
303309
if defaultOSSFSOptions != "" {
304310
options = append(options, strings.Split(defaultOSSFSOptions, ",")...)
305311
}
306312

307-
alreadySet := false
313+
tm := map[string]string{}
308314
for _, option := range options {
309-
if strings.Contains(option, "dbglevel") {
310-
alreadySet = true
311-
break
315+
if option == "" {
316+
continue
312317
}
318+
k, v, _ := strings.Cut(option, "=")
319+
tm[k] = v
313320
}
314-
if !alreadySet {
321+
322+
// set default dbg level
323+
if _, ok := tm[KeyDbgLevel]; !ok {
315324
level, ok := ossfsDbglevels[f.config.Dbglevel]
316325
if ok {
317326
options = append(options, fmt.Sprintf("dbglevel=%s", level))
@@ -323,9 +332,21 @@ func (f *fuseOssfs) AddDefaultMountOptions(options []string) []string {
323332
}
324333
}
325334

326-
if !csiutils.IsFileExisting(filepath.Join(hostPrefix, OssfsDefMimeTypesFilePath)) && strings.ToLower(f.config.Extra["mime-support"]) == "true" {
327-
// mime.types not exists, use csi-mime.types
328-
options = append(options, fmt.Sprintf("mime=%s", OssfsCsiMimeTypesFilePath))
335+
// set mime
336+
if _, ok := tm[KeyMime]; !ok {
337+
if !csiutils.IsFileExisting(filepath.Join(hostPrefix, OssfsDefMimeTypesFilePath)) && strings.ToLower(f.config.Extra["mime-support"]) == "true" {
338+
// mime.types not exists, use csi-mime.types
339+
options = append(options, fmt.Sprintf("mime=%s", OssfsCsiMimeTypesFilePath))
340+
}
341+
}
342+
343+
// set listobjectsv2
344+
// Note: OSS officially recommends using v2 API as the preferred version,
345+
// but ossfs hasn't enabled listobjectv2 by default yet.
346+
// This is a temporary workaround added by CSI driver.
347+
// TODO: Remove this logic when ossfs enables it by default.
348+
if _, ok := tm[KeyListObjectsV2]; !ok {
349+
options = append(options, "listobjectsv2")
329350
}
330351

331352
return options

pkg/mounter/oss/ossfs_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,36 +561,41 @@ func TestAddDefaultMountOptions_ossfs(t *testing.T) {
561561
{
562562
name: "empty option, empty config",
563563
options: []string{"others"},
564-
want: []string{"others", "dbglevel=err"},
564+
want: []string{"others", "dbglevel=err", "listobjectsv2"},
565565
},
566566
{
567567
name: "set option",
568568
options: []string{"others", "dbglevel=debug", "others"},
569-
want: []string{"others", "dbglevel=debug", "others"},
569+
want: []string{"others", "dbglevel=debug", "others", "listobjectsv2"},
570570
},
571571
{
572572
name: "set option, set config",
573573
cfglevel: "info",
574574
options: []string{"others", "dbglevel=debug", "others"},
575-
want: []string{"others", "dbglevel=debug", "others"},
575+
want: []string{"others", "dbglevel=debug", "others", "listobjectsv2"},
576576
},
577577
{
578578
name: "empty option, set config",
579579
cfglevel: "debug",
580580
options: []string{"others"},
581-
want: []string{"others", "dbglevel=debug"},
581+
want: []string{"others", "dbglevel=debug", "listobjectsv2"},
582582
},
583583
{
584584
name: "empty option, invalid config",
585585
cfglevel: "invalid",
586586
options: []string{"others"},
587-
want: []string{"others", "dbglevel=err"},
587+
want: []string{"others", "dbglevel=err", "listobjectsv2"},
588588
},
589589
{
590590
name: "mime-support=true",
591591
enabledMime: true,
592592
options: []string{"others"},
593-
want: []string{"others", "dbglevel=err", "mime=" + OssfsCsiMimeTypesFilePath},
593+
want: []string{"others", "dbglevel=err", "mime=" + OssfsCsiMimeTypesFilePath, "listobjectsv2"},
594+
},
595+
{
596+
name: "listobjectsv2 has set",
597+
options: []string{"others", "listobjectsv2"},
598+
want: []string{"others", "listobjectsv2", "dbglevel=err"},
594599
},
595600
}
596601
for _, tt := range tests {

0 commit comments

Comments
 (0)