Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
b4936d02
M
minikube
项目概览
Chu Peng 楚鹏
/
minikube
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
minikube
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b4936d02
编写于
4月 20, 2017
作者:
A
Aaron Prindle
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed mount command to bind on specific VM ip address instead of all interfaces
上级
83f77bb4
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
57 addition
and
77 deletion
+57
-77
cmd/minikube/cmd/mount.go
cmd/minikube/cmd/mount.go
+13
-1
pkg/minikube/cluster/cluster.go
pkg/minikube/cluster/cluster.go
+43
-1
pkg/minikube/cluster/cluster_darwin.go
pkg/minikube/cluster/cluster_darwin.go
+0
-15
pkg/minikube/cluster/cluster_linux.go
pkg/minikube/cluster/cluster_linux.go
+0
-14
pkg/minikube/cluster/cluster_windows.go
pkg/minikube/cluster/cluster_windows.go
+0
-45
pkg/minikube/constants/constants.go
pkg/minikube/constants/constants.go
+1
-1
未找到文件。
cmd/minikube/cmd/mount.go
浏览文件 @
b4936d02
...
...
@@ -18,6 +18,7 @@ package cmd
import
(
"fmt"
"net"
"os"
"sync"
...
...
@@ -26,6 +27,7 @@ import (
"github.com/golang/glog"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/third_party/go9p/ufs"
...
...
@@ -79,13 +81,23 @@ var mountCmd = &cobra.Command{
os
.
Exit
(
1
)
}
defer
api
.
Close
()
host
,
err
:=
api
.
Load
(
config
.
GetMachineName
())
if
err
!=
nil
{
glog
.
Errorln
(
"Error loading api: "
,
err
)
os
.
Exit
(
1
)
}
ip
,
err
:=
cluster
.
GetVMHostIP
(
host
)
if
err
!=
nil
{
glog
.
Errorln
(
"Error getting the host IP address to use from within the VM: "
,
err
)
os
.
Exit
(
1
)
}
fmt
.
Printf
(
"Mounting %s into %s on the minikubeVM
\n
"
,
hostPath
,
vmPath
)
fmt
.
Println
(
"This daemon process needs to stay alive for the mount to still be accessible..."
)
var
wg
sync
.
WaitGroup
wg
.
Add
(
1
)
go
func
()
{
ufs
.
StartServer
(
constants
.
DefaultUfsAddress
,
debugVal
,
hostPath
)
ufs
.
StartServer
(
net
.
JoinHostPort
(
ip
.
String
(),
constants
.
DefaultUfsPort
)
,
debugVal
,
hostPath
)
wg
.
Done
()
}()
err
=
cluster
.
MountHost
(
api
,
vmPath
)
...
...
pkg/minikube/cluster/cluster.go
浏览文件 @
b4936d02
...
...
@@ -23,6 +23,7 @@ import (
"net"
"os"
"path/filepath"
"regexp"
"strings"
"time"
...
...
@@ -405,7 +406,7 @@ func MountHost(api libmachine.API, path string) error {
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"Error checking that api exists and loading it"
)
}
ip
,
err
:=
g
etVMHostIP
(
host
)
ip
,
err
:=
G
etVMHostIP
(
host
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"Error getting the host IP address to use from within the VM"
)
}
...
...
@@ -421,6 +422,47 @@ func MountHost(api libmachine.API, path string) error {
return
nil
}
// GetVMHostIP gets the ip address to be used for mapping host -> VM and VM -> host
func
GetVMHostIP
(
host
*
host
.
Host
)
(
net
.
IP
,
error
)
{
switch
host
.
DriverName
{
case
"kvm"
:
return
net
.
ParseIP
(
"192.168.42.1"
),
nil
case
"hyperv"
:
re
:=
regexp
.
MustCompile
(
"
\"
VSwitch
\"
:
\"
(.*?)
\"
,"
)
// TODO(aprindle) Change this to deserialize the driver instead
hypervVirtualSwitch
:=
re
.
FindStringSubmatch
(
string
(
host
.
RawDriver
))[
1
]
ip
,
err
:=
getIPForInterface
(
fmt
.
Sprintf
(
"vEthernet (%s)"
,
hypervVirtualSwitch
))
if
err
!=
nil
{
return
[]
byte
{},
errors
.
Wrap
(
err
,
"Error getting VM/Host IP address"
)
}
return
ip
,
nil
case
"virtualbox"
:
ip
,
err
:=
getIPForInterface
(
"vboxnet0"
)
if
err
!=
nil
{
return
[]
byte
{},
errors
.
Wrap
(
err
,
"Error getting VM/Host IP address"
)
}
return
ip
,
nil
case
"xhyve"
:
return
net
.
ParseIP
(
"192.168.64.1"
),
nil
default
:
return
[]
byte
{},
errors
.
New
(
"Error, attempted to get host ip address for unsupported driver"
)
}
}
// Based on code from http://stackoverflow.com/questions/23529663/how-to-get-all-addresses-and-masks-from-local-interfaces-in-go
func
getIPForInterface
(
name
string
)
(
net
.
IP
,
error
)
{
i
,
_
:=
net
.
InterfaceByName
(
name
)
addrs
,
_
:=
i
.
Addrs
()
for
_
,
a
:=
range
addrs
{
if
ipnet
,
ok
:=
a
.
(
*
net
.
IPNet
);
ok
{
if
ip
:=
ipnet
.
IP
.
To4
();
ip
!=
nil
{
return
ip
,
nil
}
}
}
return
nil
,
errors
.
Errorf
(
"Error finding IPV4 address for %s"
,
name
)
}
func
CheckIfApiExistsAndLoad
(
api
libmachine
.
API
)
(
*
host
.
Host
,
error
)
{
exists
,
err
:=
api
.
Exists
(
cfg
.
GetMachineName
())
if
err
!=
nil
{
...
...
pkg/minikube/cluster/cluster_darwin.go
浏览文件 @
b4936d02
...
...
@@ -17,12 +17,8 @@ limitations under the License.
package
cluster
import
(
"errors"
"net"
"github.com/docker/machine/drivers/vmwarefusion"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/host"
cfg
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
)
...
...
@@ -72,14 +68,3 @@ func createXhyveHost(config MachineConfig) *xhyveDriver {
Virtio9pFolder
:
"/Users"
,
}
}
func
getVMHostIP
(
host
*
host
.
Host
)
(
net
.
IP
,
error
)
{
switch
host
.
DriverName
{
case
"virtualbox"
:
return
net
.
ParseIP
(
"10.0.2.2"
),
nil
case
"xhyve"
:
return
net
.
ParseIP
(
"192.168.64.1"
),
nil
default
:
return
[]
byte
{},
errors
.
New
(
"Error, attempted to get host ip address for unsupported driver"
)
}
}
pkg/minikube/cluster/cluster_linux.go
浏览文件 @
b4936d02
...
...
@@ -17,13 +17,10 @@ limitations under the License.
package
cluster
import
(
"errors"
"fmt"
"net"
"path/filepath"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/host"
cfg
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
)
...
...
@@ -61,14 +58,3 @@ func createKVMHost(config MachineConfig) *kvmDriver {
IOMode
:
"threads"
,
}
}
func
getVMHostIP
(
host
*
host
.
Host
)
(
net
.
IP
,
error
)
{
switch
host
.
DriverName
{
case
"virtualbox"
:
return
net
.
ParseIP
(
"10.0.2.2"
),
nil
case
"kvm"
:
return
net
.
ParseIP
(
"192.168.42.1"
),
nil
default
:
return
[]
byte
{},
errors
.
New
(
"Error, attempted to get host ip address for unsupported driver"
)
}
}
pkg/minikube/cluster/cluster_windows.go
浏览文件 @
b4936d02
...
...
@@ -17,15 +17,8 @@ limitations under the License.
package
cluster
import
(
"fmt"
"net"
"regexp"
"strings"
"github.com/docker/machine/drivers/hyperv"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/host"
"github.com/pkg/errors"
cfg
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
)
...
...
@@ -40,41 +33,3 @@ func createHypervHost(config MachineConfig) drivers.Driver {
d
.
SSHUser
=
"docker"
return
d
}
func
getVMHostIP
(
host
*
host
.
Host
)
(
net
.
IP
,
error
)
{
switch
host
.
DriverName
{
case
"virtualbox"
:
return
net
.
ParseIP
(
"10.0.2.2"
),
nil
case
"hyperv"
:
re
:=
regexp
.
MustCompile
(
"
\"
VSwitch
\"
:
\"
(.*?)
\"
,"
)
hypervVirtualSwitch
:=
re
.
FindStringSubmatch
(
string
(
host
.
RawDriver
))[
1
]
ip
,
err
:=
getWindowsHostIpFromHyperV
(
hypervVirtualSwitch
)
if
err
!=
nil
{
return
[]
byte
{},
errors
.
Wrap
(
err
,
"Error getting 9p mount command"
)
}
return
ip
,
nil
default
:
return
[]
byte
{},
errors
.
New
(
"Error, attempted to get host ip address for unsupported driver"
)
}
}
func
getWindowsHostIpFromHyperV
(
hypervVirtualSwitch
string
)
(
net
.
IP
,
error
)
{
virtualSwitchTemplate
:=
"vEthernet (%s)"
i
,
_
:=
net
.
InterfaceByName
(
fmt
.
Sprintf
(
virtualSwitchTemplate
,
hypervVirtualSwitch
))
addrs
,
_
:=
i
.
Addrs
()
for
_
,
a
:=
range
addrs
{
switch
a
.
(
type
)
{
case
*
net
.
IPNet
:
ip
:=
a
.
String
()
if
strings
.
Contains
(
ip
,
"."
)
{
vmIP
:=
net
.
ParseIP
(
strings
.
Split
(
ip
,
"/"
)[
0
])
if
vmIP
.
String
()
==
""
{
return
nil
,
errors
.
Errorf
(
"Error finding IPV4 address for virtual switch %s"
,
hypervVirtualSwitch
)
}
return
vmIP
,
nil
}
}
}
return
nil
,
errors
.
Errorf
(
"Error finding IPV4 address for virtual switch %s"
,
hypervVirtualSwitch
)
}
pkg/minikube/constants/constants.go
浏览文件 @
b4936d02
...
...
@@ -125,6 +125,6 @@ const (
)
const
(
DefaultUfs
Address
=
":
5640"
DefaultUfs
Port
=
"
5640"
DefaultUfsDebugLvl
=
0
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录