Skip to content

Commit efeb836

Browse files
authored
Merge pull request #1394 from AlbeeSo/feat/save-logdir
ossfs2: set default logdir to /dev/stdout
2 parents 4ba7e7e + ba57b18 commit efeb836

File tree

4 files changed

+34
-108
lines changed

4 files changed

+34
-108
lines changed

pkg/mounter/oss/ossfs.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ func (f *fuseOssfs) getAuthOptions(o *Options, region string) (mountOptions []st
299299
}
300300

301301
func (f *fuseOssfs) AddDefaultMountOptions(options []string) []string {
302+
defaultOSSFSOptions := os.Getenv("DEFAULT_OSSFS_OPTIONS")
303+
if defaultOSSFSOptions != "" {
304+
options = append(options, strings.Split(defaultOSSFSOptions, ",")...)
305+
}
306+
302307
alreadySet := false
303308
for _, option := range options {
304309
if strings.Contains(option, "dbglevel") {
@@ -323,10 +328,6 @@ func (f *fuseOssfs) AddDefaultMountOptions(options []string) []string {
323328
options = append(options, fmt.Sprintf("mime=%s", OssfsCsiMimeTypesFilePath))
324329
}
325330

326-
defaultOSSFSOptions := os.Getenv("DEFAULT_OSSFS_OPTIONS")
327-
if defaultOSSFSOptions != "" {
328-
options = append(options, strings.Split(defaultOSSFSOptions, ",")...)
329-
}
330331
return options
331332
}
332333

pkg/mounter/oss/ossfs2.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,28 @@ func (f *fuseOssfs2) buildPodSpec(c *utils.FusePodContext, target string) (spec
186186
return
187187
}
188188

189+
const (
190+
KeyLogLevel = "log_level"
191+
KeyLogDir = "log_dir"
192+
)
193+
189194
func (f *fuseOssfs2) AddDefaultMountOptions(options []string) []string {
190-
alreadySet := false
195+
defaultOSSFSOptions := os.Getenv("DEFAULT_OSSFS2_OPTIONS")
196+
if defaultOSSFSOptions != "" {
197+
options = append(options, strings.Split(defaultOSSFSOptions, ",")...)
198+
}
199+
200+
tm := map[string]string{}
191201
for _, option := range options {
192-
if strings.Contains(option, "log_level") {
193-
alreadySet = true
194-
break
202+
if option == "" {
203+
continue
195204
}
205+
k, v, _ := strings.Cut(option, "=")
206+
tm[k] = v
196207
}
197-
if !alreadySet {
208+
209+
// set default log level
210+
if _, ok := tm[KeyLogLevel]; !ok {
198211
level, ok := ossfs2Dbglevels[f.config.Dbglevel]
199212
if ok {
200213
options = append(options, fmt.Sprintf("log_level=%s", level))
@@ -206,9 +219,9 @@ func (f *fuseOssfs2) AddDefaultMountOptions(options []string) []string {
206219
}
207220
}
208221

209-
defaultOSSFSOptions := os.Getenv("DEFAULT_OSSFS2_OPTIONS")
210-
if defaultOSSFSOptions != "" {
211-
options = append(options, strings.Split(defaultOSSFSOptions, ",")...)
222+
// set default log dir
223+
if _, ok := tm[KeyLogDir]; !ok {
224+
options = append(options, "log_dir=/dev/stdout")
212225
}
213226

214227
return options

pkg/mounter/oss/ossfs2_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,37 +207,37 @@ func TestAddDefaultMountOptions_ossfs2(t *testing.T) {
207207
{
208208
name: "empty option, empty config",
209209
options: []string{"others"},
210-
want: []string{"others", "log_level=info"},
210+
want: []string{"others", "log_level=info", "log_dir=/dev/stdout"},
211211
},
212212
{
213213
name: "set option",
214-
options: []string{"others", "log_level=debug", "others"},
215-
want: []string{"others", "log_level=debug", "others"},
214+
options: []string{"others", "log_level=debug", "log_dir=/tmp/ossfs2", "others"},
215+
want: []string{"others", "log_level=debug", "log_dir=/tmp/ossfs2", "others"},
216216
},
217217
{
218218
name: "set option, set config",
219219
cfglevel: "info",
220220
options: []string{"others", "log_level=debug", "others"},
221-
want: []string{"others", "log_level=debug", "others"},
221+
want: []string{"others", "log_level=debug", "others", "log_dir=/dev/stdout"},
222222
},
223223
{
224224
name: "empty option, set config",
225225
cfglevel: "debug",
226226
options: []string{"others"},
227-
want: []string{"others", "log_level=debug"},
227+
want: []string{"others", "log_level=debug", "log_dir=/dev/stdout"},
228228
},
229229
{
230230
name: "empty option, invalid config",
231231
cfglevel: "invalid",
232232
options: []string{"others"},
233-
want: []string{"others", "log_level=info"},
233+
want: []string{"others", "log_level=info", "log_dir=/dev/stdout"},
234234
},
235235
{
236236
name: "default options",
237237
cfglevel: "",
238238
options: nil,
239-
defaultOpts: "others",
240-
want: []string{"log_level=info", "others"},
239+
defaultOpts: "others,log_dir=/tmp/ossfs2",
240+
want: []string{"others", "log_dir=/tmp/ossfs2", "log_level=info"},
241241
},
242242
}
243243
for _, tt := range tests {

pkg/mounter/oss/ossfs_test.go

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package oss
33
import (
44
"context"
55
"fmt"
6-
"reflect"
76
"testing"
87

98
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/cloud/metadata"
@@ -61,93 +60,6 @@ func Test_buildAuthSpec_ossfs(t *testing.T) {
6160
assert.Contains(t, "rrsa-oidc-token", volumeMount.Name)
6261
}
6362

64-
func Test_AddDefaultMountOptions(t *testing.T) {
65-
tests := []struct {
66-
name string
67-
options []string
68-
dbglevel string
69-
mime string
70-
defaultOpts string
71-
want []string
72-
}{
73-
{
74-
name: "Debug level not set",
75-
options: []string{},
76-
dbglevel: "",
77-
mime: "false",
78-
want: []string{"dbglevel=err"},
79-
},
80-
{
81-
name: "Debug level set by config",
82-
options: []string{},
83-
dbglevel: "warn",
84-
mime: "false",
85-
want: []string{"dbglevel=warn"},
86-
},
87-
{
88-
name: "Debug level set by mount options",
89-
options: []string{"dbglevel=info"},
90-
dbglevel: "warn",
91-
mime: "false",
92-
want: []string{"dbglevel=info"},
93-
},
94-
{
95-
name: "Invalid debug level",
96-
options: []string{},
97-
dbglevel: "unknown",
98-
mime: "false",
99-
want: []string{"dbglevel=err"},
100-
},
101-
{
102-
name: "Mime support enabled without existing mime.types",
103-
options: []string{},
104-
dbglevel: "",
105-
mime: "true",
106-
want: []string{"dbglevel=err", "mime=" + OssfsCsiMimeTypesFilePath},
107-
},
108-
{
109-
name: "Mime support disabled with existing mime.types",
110-
options: []string{},
111-
dbglevel: "",
112-
mime: "false",
113-
want: []string{"dbglevel=err"},
114-
},
115-
{
116-
name: "Default options",
117-
options: []string{},
118-
dbglevel: "",
119-
mime: "false",
120-
defaultOpts: "allow_other,umask=000",
121-
want: []string{"dbglevel=err", "allow_other", "umask=000"},
122-
},
123-
}
124-
125-
for _, tt := range tests {
126-
t.Run(tt.name, func(t *testing.T) {
127-
f := &fuseOssfs{
128-
config: mounterutils.FuseContainerConfig{
129-
Dbglevel: tt.dbglevel,
130-
Extra: map[string]string{
131-
"mime-support": tt.mime,
132-
},
133-
},
134-
}
135-
if tt.defaultOpts != "" {
136-
t.Setenv("DEFAULT_OSSFS_OPTIONS", tt.defaultOpts)
137-
}
138-
got := f.AddDefaultMountOptions(tt.options)
139-
if len(got) != len(tt.want) {
140-
t.Errorf("AddDefaultMountOptions() got = %v, want %v", got, tt.want)
141-
return
142-
}
143-
if !reflect.DeepEqual(got, tt.want) {
144-
t.Errorf("AddDefaultMountOptions() got = %v, want %v", got, tt.want)
145-
return
146-
}
147-
})
148-
}
149-
}
150-
15163
func TestPrecheckAuthConfig_ossfs(t *testing.T) {
15264
fakeMeta := metadata.NewMetadata()
15365
fakeOssfs := NewFuseOssfs(nil, fakeMeta)

0 commit comments

Comments
 (0)