Skip to content
Snippets Groups Projects
Commit 1c1abefa authored by kaiyou's avatar kaiyou
Browse files

Extend mount() behavior to support subpath

Subpath mounts in kubelet require more mount options to be
taken into account, which is still manageable without importing
a full mount command
parent 9d304ea4
No related branches found
No related tags found
No related merge requests found
Pipeline #28742 passed
......@@ -2,6 +2,8 @@ package hepto
import (
"context"
"flag"
"fmt"
"os"
"strings"
......@@ -21,11 +23,24 @@ import (
)
func Mount() error {
// Hook the mount command for mounting configmaps
// Hook the mount command for mounting configmaps and subpaths
// This is fairly naive mount implementation, kubelet only evers calls
// mount with very simple very formatted arguments in that order:
// mount with very simple very formatted arguments in the following forms:
// mount -t tmpfs -o size=1234 /src /dst
return unix.Mount(os.Args[5], os.Args[6], os.Args[2], 0, os.Args[4])
// mount --no-canonicalize -o bind /src /dst
fs := flag.NewFlagSet("mount", flag.ExitOnError)
fstype := fs.String("t", "bind", "type")
data := fs.String("o", "", "options")
fs.Bool("no-canonicalize", false, "")
fs.Parse(os.Args[1:])
var flags uintptr
if fs.NArg() < 2 {
return fmt.Errorf("must specify src and dst")
}
if *fstype == "bind" || *data == "bind" {
flags |= unix.MS_BIND
}
return unix.Mount(fs.Arg(0), fs.Arg(1), *fstype, flags, *data)
}
func Umount() error {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment