diff --git a/pkg/blob/nodeserver.go b/pkg/blob/nodeserver.go index b1e227b14..b5e5394de 100644 --- a/pkg/blob/nodeserver.go +++ b/pkg/blob/nodeserver.go @@ -172,6 +172,8 @@ func (d *Driver) mountBlobfuseWithProxy(args, protocol string, authEnv []string) func (d *Driver) mountBlobfuseInsideDriver(args string, protocol string, authEnv []string) (string, error) { var cmd *exec.Cmd + args = volumehelper.TrimDuplicatedSpace(args) + mountLog := "mount inside driver with" if protocol == Fuse2 { mountLog += " v2" diff --git a/pkg/blobfuse-proxy/server/server.go b/pkg/blobfuse-proxy/server/server.go index b2f492940..19c89c6f0 100644 --- a/pkg/blobfuse-proxy/server/server.go +++ b/pkg/blobfuse-proxy/server/server.go @@ -76,9 +76,11 @@ func (server *MountServer) MountAzureBlob(ctx context.Context, klog.V(2).Infof("append --ignore-open-flags=true to mount args") args = args + " " + "--ignore-open-flags=true" } + args = util.TrimDuplicatedSpace(args) klog.V(2).Infof("mount with v2, protocol: %s, args: %s", protocol, args) cmd = exec.Command("blobfuse2", strings.Split(args, " ")...) } else { + args = util.TrimDuplicatedSpace(args) klog.V(2).Infof("mount with v1, protocol: %s, args: %s", protocol, args) cmd = exec.Command("blobfuse", strings.Split(args, " ")...) } diff --git a/pkg/util/util.go b/pkg/util/util.go index 88dfc77e8..6afc44600 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -19,6 +19,7 @@ package util import ( "fmt" "os" + "regexp" "strings" "sync" @@ -183,3 +184,9 @@ func GetOSInfo(f interface{}) (*OsInfo, error) { klog.V(2).Infof("get OS info: %v", oi) return oi, nil } + +func TrimDuplicatedSpace(s string) string { + reg := regexp.MustCompile(`\s+`) + s = reg.ReplaceAllString(s, " ") + return s +} diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index e175c9a30..5d34263be 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -293,3 +293,29 @@ func TestGetOSInfo(t *testing.T) { }) } } + +func TestTrimDuplicatedSpace(t *testing.T) { + type args struct { + s string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "trim duplicated space", + args: args{ + s: " fo o bar ", + }, + want: " fo o bar ", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := TrimDuplicatedSpace(tt.args.s); got != tt.want { + t.Errorf("TrimDuplicatedSpace() = %v, want %v", got, tt.want) + } + }) + } +}