Skip to content

Commit

Permalink
fix parse mount path
Browse files Browse the repository at this point in the history
Signed-off-by: zwwhdls <[email protected]>
  • Loading branch information
zwwhdls committed Oct 12, 2023
1 parent 148743e commit 866c0ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 1 addition & 7 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,7 @@ func GetReferenceKey(target string) string {
// ParseMntPath return mntPath, volumeId (/jfs/volumeId, volumeId err)
func ParseMntPath(cmd string) (string, string, error) {
cmds := strings.Split(cmd, "\n")
if len(cmds) > 2 {
return "", "", fmt.Errorf("err cmd:%s", cmd)
}
mountCmd := cmds[0]
if len(cmds) == 2 {
mountCmd = cmds[1]
}
mountCmd := cmds[len(cmds)-1]
args := strings.Fields(mountCmd)
if len(args) < 3 || !strings.HasPrefix(args[2], config.PodMountBase) {
return "", "", fmt.Errorf("err cmd:%s", cmd)
Expand Down
11 changes: 11 additions & 0 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ func TestParseMntPath(t *testing.T) {
want1: "pvc-xxx",
wantErr: false,
},
{
name: "with create subpath",
args: args{cmd: "/usr/local/bin/juicefs format --storage=s3 --bucket=http://juicefs-bucket.minio.default.svc.cluster.local:9000 --access-key=minioadmin --secret-key=${secretkey} ${metaurl} ce-secret\n" +
"/bin/mount.juicefs ${metaurl} /mnt/jfs -o buffer-size=300,cache-size=100,enable-xattr\n" +
"if [ ! -d /mnt/jfs/pvc-fb2ec20c-474f-4804-9504-966da4af9b73 ]; then mkdir -m 777 /mnt/jfs/pvc-fb2ec20c-474f-4804-9504-966da4af9b73; fi;\n" +
"umount /mnt/jfs\n" +
"/bin/mount.juicefs redis://127.0.0.1/6379 /jfs/pvc-xxx"},
want: "/jfs/pvc-xxx",
want1: "pvc-xxx",
wantErr: false,
},
{
name: "err-pod cmd args <3",
args: args{cmd: "/usr/local/bin/juicefs format --storage=s3 --bucket=http://juicefs-bucket.minio.default.svc.cluster.local:9000 --access-key=minioadmin --secret-key=${secretkey} ${metaurl} ce-secret\n/bin/mount.juicefs redis://127.0.0.1/6379"},
Expand Down

0 comments on commit 866c0ac

Please sign in to comment.