Skip to content

Commit ec43057

Browse files
authored
mkdir mountpath before createOrAddRef (#1302)
Signed-off-by: zwwhdls <[email protected]>
1 parent 5b5f4b4 commit ec43057

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

pkg/controller/pod_driver.go

+1-11
Original file line numberDiff line numberDiff line change
@@ -1050,17 +1050,7 @@ func mkrMp(ctx context.Context, pod corev1.Pod) error {
10501050
log.Error(err, "get mount point error")
10511051
return err
10521052
}
1053-
err = util.DoWithTimeout(ctx, 3*time.Second, func() error {
1054-
exist := util.Exists(mntPath)
1055-
if !exist {
1056-
return os.MkdirAll(mntPath, 0777)
1057-
}
1058-
return nil
1059-
})
1060-
if err != nil {
1061-
return err
1062-
}
1063-
return nil
1053+
return util.MkdirIfNotExist(ctx, mntPath)
10641054
}
10651055

10661056
func (p *PodDriver) getAvailableMountPod(uniqueId, upgradeUUID string) bool {

pkg/juicefs/mount/pod_mount.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package mount
1919
import (
2020
"context"
2121
"fmt"
22-
"os"
2322
"os/exec"
2423
"regexp"
2524
"strings"
@@ -361,14 +360,7 @@ func (p *PodMount) createOrAddRef(ctx context.Context, podName string, jfsSettin
361360
} else if err != nil {
362361
if k8serrors.IsNotFound(err) {
363362
// mkdir mountpath
364-
err = util.DoWithTimeout(ctx, 3*time.Second, func() error {
365-
exist, _ := k8sMount.PathExists(jfsSetting.MountPath)
366-
if !exist {
367-
return os.MkdirAll(jfsSetting.MountPath, 0777)
368-
}
369-
return nil
370-
})
371-
if err != nil {
363+
if err = util.MkdirIfNotExist(ctx, jfsSetting.MountPath); err != nil {
372364
return
373365
}
374366
// pod not exist, create
@@ -435,6 +427,11 @@ func (p *PodMount) createOrAddRef(ctx context.Context, podName string, jfsSettin
435427
log.Error(err, "Get mount path of pod error", "podName", podName)
436428
return err
437429
}
430+
431+
// mkdir mountpath
432+
if err = util.MkdirIfNotExist(ctx, jfsSetting.MountPath); err != nil {
433+
return
434+
}
438435
return p.AddRefOfMount(ctx, jfsSetting.TargetPath, podName)
439436
}
440437
}

pkg/util/util.go

+10
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,16 @@ func Exists(path string) bool {
508508
return err == nil || !os.IsNotExist(err) //skip mutate
509509
}
510510

511+
func MkdirIfNotExist(ctx context.Context, mntPath string) (err error) {
512+
return DoWithTimeout(ctx, 3*time.Second, func() error {
513+
exist := Exists(mntPath)
514+
if !exist {
515+
return os.MkdirAll(mntPath, 0777)
516+
}
517+
return nil
518+
})
519+
}
520+
511521
type ClientVersion struct {
512522
IsCe bool
513523
Dev bool

0 commit comments

Comments
 (0)