diff --git a/cmd/hepto/hooks.go b/cmd/hepto/hooks.go index 0d2f8f43255c9306fd114c58a93409997d7e6211..36b2dee01c8dff2e40bd3533219a337e9f96a912 100644 --- a/cmd/hepto/hooks.go +++ b/cmd/hepto/hooks.go @@ -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 {