Skip to content

Commit

Permalink
Allow control of user and group ids for mount
Browse files Browse the repository at this point in the history
  • Loading branch information
tmc authored and dlorenc committed Jun 22, 2017
1 parent 55ea14f commit c5becb3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 6 additions & 2 deletions cmd/minikube/cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/minikube/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/minikube/cluster/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c5becb3

Please sign in to comment.