提交 c5becb36 编写于 作者: T Travis Cline 提交者: dlorenc

Allow control of user and group ids for mount

上级 55ea14fb
......@@ -35,6 +35,8 @@ import (
var mountIP string
var isKill bool
var uid int
var gid int
// mountCmd represents the mount command
var mountCmd = &cobra.Command{
......@@ -52,7 +54,7 @@ var mountCmd = &cobra.Command{
if len(args) != 1 {
errText := `Please specify the directory to be mounted:
\tminikube mount HOST_MOUNT_DIRECTORY:VM_MOUNT_DIRECTORY(ex:"/host-home:/vm-home")
minikube mount HOST_MOUNT_DIRECTORY:VM_MOUNT_DIRECTORY(ex:"/host-home:/vm-home")
`
fmt.Fprintln(os.Stderr, errText)
os.Exit(1)
......@@ -128,7 +130,7 @@ var mountCmd = &cobra.Command{
ufs.StartServer(net.JoinHostPort(ip.String(), port), debugVal, hostPath)
wg.Done()
}()
err = cluster.MountHost(api, vmPath, ip, port)
err = cluster.MountHost(api, vmPath, ip, port, uid, gid)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
......@@ -140,5 +142,7 @@ var mountCmd = &cobra.Command{
func init() {
mountCmd.Flags().StringVar(&mountIP, "ip", "", "Specify the ip that the mount should be setup on")
mountCmd.Flags().BoolVar(&isKill, "kill", false, "Kill the mount process spawned by minikube start")
mountCmd.Flags().IntVar(&uid, "uid", 1001, "Default user id used for the mount")
mountCmd.Flags().IntVar(&gid, "gid", 1001, "Default group id used for the mount")
RootCmd.AddCommand(mountCmd)
}
......@@ -449,7 +449,7 @@ func GetHostLogs(api libmachine.API, follow bool) (string, error) {
}
// MountHost runs the mount command from the 9p client on the VM to the 9p server on the host
func MountHost(api libmachine.API, path string, ip net.IP, port string) error {
func MountHost(api libmachine.API, path string, ip net.IP, port string, uid, gid int) error {
host, err := CheckIfApiExistsAndLoad(api)
if err != nil {
return errors.Wrap(err, "Error checking that api exists and loading it")
......@@ -461,7 +461,7 @@ func MountHost(api libmachine.API, path string, ip net.IP, port string) error {
}
}
host.RunSSHCommand(GetMountCleanupCommand(path))
mountCmd, err := GetMountCommand(ip, path, port)
mountCmd, err := GetMountCommand(ip, path, port, uid, gid)
if err != nil {
return errors.Wrap(err, "Error getting mount command")
}
......
......@@ -233,20 +233,24 @@ func GetMountCleanupCommand(path string) string {
var mountTemplate = `
sudo mkdir -p {{.Path}} || true;
sudo mount -t 9p -o trans=tcp -o port={{.Port}} -o uid=1001 -o gid=1001 {{.IP}} {{.Path}};
sudo mount -t 9p -o trans=tcp -o port={{.Port}} -o uid={{.UID}} -o gid={{.GID}} {{.IP}} {{.Path}};
sudo chmod 775 {{.Path}};`
func GetMountCommand(ip net.IP, path string, port string) (string, error) {
func GetMountCommand(ip net.IP, path, port string, uid, gid int) (string, error) {
t := template.Must(template.New("mountCommand").Parse(mountTemplate))
buf := bytes.Buffer{}
data := struct {
IP string
Path string
Port string
UID int
GID int
}{
IP: ip.String(),
Path: path,
Port: port,
UID: uid,
GID: gid,
}
if err := t.Execute(&buf, data); err != nil {
return "", err
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册