Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
d4cf3b0f
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,发现更多精彩内容 >>
提交
d4cf3b0f
编写于
5月 16, 2019
作者:
M
Medya Gh
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'upstream/master' into no_proxy_for_self
上级
0d58773a
146499e0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
93 addition
and
16 deletion
+93
-16
pkg/minikube/tunnel/cluster_inspector.go
pkg/minikube/tunnel/cluster_inspector.go
+9
-3
pkg/minikube/tunnel/cluster_inspector_test.go
pkg/minikube/tunnel/cluster_inspector_test.go
+9
-2
pkg/minikube/tunnel/route_darwin.go
pkg/minikube/tunnel/route_darwin.go
+37
-0
pkg/minikube/tunnel/route_darwin_test.go
pkg/minikube/tunnel/route_darwin_test.go
+28
-7
pkg/minikube/tunnel/route_test.go
pkg/minikube/tunnel/route_test.go
+6
-2
pkg/minikube/tunnel/types.go
pkg/minikube/tunnel/types.go
+4
-2
未找到文件。
pkg/minikube/tunnel/cluster_inspector.go
浏览文件 @
d4cf3b0f
...
...
@@ -26,6 +26,7 @@ import (
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/util"
)
type
clusterInspector
struct
{
...
...
@@ -93,9 +94,14 @@ func getRoute(host *host.Host, clusterConfig config.Config) (*Route, error) {
if
ip
==
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid IP for host %s"
,
hostDriverIP
)
}
dnsIP
,
err
:=
util
.
GetDNSIP
(
ipNet
.
String
())
if
err
!=
nil
{
return
nil
,
err
}
return
&
Route
{
Gateway
:
ip
,
DestCIDR
:
ipNet
,
Gateway
:
ip
,
DestCIDR
:
ipNet
,
ClusterDomain
:
clusterConfig
.
KubernetesConfig
.
DNSDomain
,
ClusterDNSIP
:
dnsIP
,
},
nil
}
pkg/minikube/tunnel/cluster_inspector_test.go
浏览文件 @
d4cf3b0f
...
...
@@ -19,6 +19,8 @@ package tunnel
import
(
"testing"
"k8s.io/minikube/pkg/util"
"net"
"reflect"
"strings"
...
...
@@ -78,10 +80,15 @@ func TestMinikubeCheckReturnsHostInformation(t *testing.T) {
ip
:=
net
.
ParseIP
(
"1.2.3.4"
)
_
,
ipNet
,
_
:=
net
.
ParseCIDR
(
"96.0.0.0/12"
)
dnsIP
,
err
:=
util
.
GetDNSIP
(
ipNet
.
String
())
if
err
!=
nil
{
t
.
Errorf
(
"getdnsIP: %v"
,
err
)
}
expectedRoute
:=
&
Route
{
Gateway
:
ip
,
DestCIDR
:
ipNet
,
Gateway
:
ip
,
DestCIDR
:
ipNet
,
ClusterDNSIP
:
dnsIP
,
}
if
s
!=
Running
{
...
...
pkg/minikube/tunnel/route_darwin.go
浏览文件 @
d4cf3b0f
...
...
@@ -18,7 +18,9 @@ package tunnel
import
(
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
"regexp"
"strings"
...
...
@@ -34,6 +36,9 @@ func (router *osRouter) EnsureRouteIsAdded(route *Route) error {
if
exists
{
return
nil
}
if
err
:=
writeResolverFile
(
route
);
err
!=
nil
{
return
fmt
.
Errorf
(
"could not write /etc/resolver/{cluster_domain} file: %s"
,
err
)
}
serviceCIDR
:=
route
.
DestCIDR
.
String
()
gatewayIP
:=
route
.
Gateway
.
String
()
...
...
@@ -162,5 +167,37 @@ func (router *osRouter) Cleanup(route *Route) error {
if
!
re
.
MatchString
(
message
)
{
return
fmt
.
Errorf
(
"error deleting route: %s, %d"
,
message
,
len
(
strings
.
Split
(
message
,
"
\n
"
)))
}
// idempotent removal of cluster domain dns
resolverFile
:=
fmt
.
Sprintf
(
"/etc/resolver/%s"
,
route
.
ClusterDomain
)
command
=
exec
.
Command
(
"sudo"
,
"rm"
,
"-f"
,
resolverFile
)
if
err
:=
command
.
Run
();
err
!=
nil
{
return
fmt
.
Errorf
(
"could not remove %s: %s"
,
resolverFile
,
err
)
}
return
nil
}
func
writeResolverFile
(
route
*
Route
)
error
{
resolverFile
:=
"/etc/resolver/"
+
route
.
ClusterDomain
content
:=
fmt
.
Sprintf
(
"nameserver %s
\n
search_order 1
\n
"
,
route
.
ClusterDNSIP
)
// write resolver content into tmpFile, then copy it to /etc/resolver/clusterDomain
tmpFile
,
err
:=
ioutil
.
TempFile
(
""
,
"minikube-tunnel-resolver-"
)
if
err
!=
nil
{
return
err
}
defer
os
.
Remove
(
tmpFile
.
Name
())
if
_
,
err
=
tmpFile
.
WriteString
(
content
);
err
!=
nil
{
return
err
}
if
err
=
tmpFile
.
Close
();
err
!=
nil
{
return
err
}
command
:=
exec
.
Command
(
"sudo"
,
"mkdir"
,
"-p"
,
"/etc/resolver"
)
if
err
:=
command
.
Run
();
err
!=
nil
{
return
err
}
command
=
exec
.
Command
(
"sudo"
,
"cp"
,
"-f"
,
tmpFile
.
Name
(),
resolverFile
)
if
err
:=
command
.
Run
();
err
!=
nil
{
return
err
}
return
nil
}
pkg/minikube/tunnel/route_darwin_test.go
浏览文件 @
d4cf3b0f
...
...
@@ -35,9 +35,14 @@ func TestDarwinRouteFailsOnConflictIntegrationTest(t *testing.T) {
IP
:
net
.
IPv4
(
10
,
96
,
0
,
0
),
Mask
:
net
.
IPv4Mask
(
255
,
240
,
0
,
0
),
},
ClusterDomain
:
"cluster.local"
,
ClusterDNSIP
:
net
.
IPv4
(
10
,
96
,
0
,
10
),
}
conflictingCfg
:=
*
cfg
conflictingCfg
.
Gateway
=
net
.
IPv4
(
127
,
0
,
0
,
2
)
addRoute
(
t
,
"10.96.0.0/12"
,
"127.0.0.2"
)
addRoute
(
t
,
&
conflictingCfg
)
defer
cleanRoute
(
t
,
&
conflictingCfg
)
err
:=
(
&
osRouter
{})
.
EnsureRouteIsAdded
(
cfg
)
if
err
==
nil
{
t
.
Errorf
(
"add should have error, but it is nil"
)
...
...
@@ -51,9 +56,11 @@ func TestDarwinRouteIdempotentIntegrationTest(t *testing.T) {
IP
:
net
.
IPv4
(
10
,
96
,
0
,
0
),
Mask
:
net
.
IPv4Mask
(
255
,
240
,
0
,
0
),
},
ClusterDomain
:
"cluster.local"
,
ClusterDNSIP
:
net
.
IPv4
(
10
,
96
,
0
,
10
),
}
cleanRoute
(
t
,
"10.96.0.0/12"
)
cleanRoute
(
t
,
cfg
)
err
:=
(
&
osRouter
{})
.
EnsureRouteIsAdded
(
cfg
)
if
err
!=
nil
{
t
.
Errorf
(
"add error: %s"
,
err
)
...
...
@@ -64,7 +71,7 @@ func TestDarwinRouteIdempotentIntegrationTest(t *testing.T) {
t
.
Errorf
(
"add error: %s"
,
err
)
}
cleanRoute
(
t
,
"10.96.0.0/12"
)
cleanRoute
(
t
,
cfg
)
}
func
TestDarwinRouteCleanupIdempontentIntegrationTest
(
t
*
testing
.
T
)
{
...
...
@@ -75,10 +82,12 @@ func TestDarwinRouteCleanupIdempontentIntegrationTest(t *testing.T) {
IP
:
net
.
IPv4
(
10
,
96
,
0
,
0
),
Mask
:
net
.
IPv4Mask
(
255
,
240
,
0
,
0
),
},
ClusterDomain
:
"cluster.local"
,
ClusterDNSIP
:
net
.
IPv4
(
10
,
96
,
0
,
10
),
}
cleanRoute
(
t
,
"10.96.0.0/12"
)
addRoute
(
t
,
"10.96.0.0/12"
,
"192.168.1.1"
)
cleanRoute
(
t
,
cfg
)
addRoute
(
t
,
cfg
)
err
:=
(
&
osRouter
{})
.
Cleanup
(
cfg
)
if
err
!=
nil
{
t
.
Errorf
(
"cleanup failed with %s"
,
err
)
...
...
@@ -89,20 +98,32 @@ func TestDarwinRouteCleanupIdempontentIntegrationTest(t *testing.T) {
}
}
func
addRoute
(
t
*
testing
.
T
,
cidr
string
,
gw
string
)
{
func
addRoute
(
t
*
testing
.
T
,
r
*
Route
)
{
cidr
:=
r
.
DestCIDR
.
String
()
gw
:=
r
.
Gateway
.
String
()
command
:=
exec
.
Command
(
"sudo"
,
"route"
,
"-n"
,
"add"
,
cidr
,
gw
)
_
,
err
:=
command
.
CombinedOutput
()
if
err
!=
nil
{
t
.
Logf
(
"add route error (should be ok): %s"
,
err
)
}
err
=
writeResolverFile
(
r
)
if
err
!=
nil
{
t
.
Logf
(
"add route DNS resolver error (should be ok): %s"
,
err
)
}
}
func
cleanRoute
(
t
*
testing
.
T
,
cidr
string
)
{
func
cleanRoute
(
t
*
testing
.
T
,
r
*
Route
)
{
cidr
:=
r
.
DestCIDR
.
String
()
command
:=
exec
.
Command
(
"sudo"
,
"route"
,
"-n"
,
"delete"
,
cidr
)
_
,
err
:=
command
.
CombinedOutput
()
if
err
!=
nil
{
t
.
Logf
(
"cleanup error (should be ok): %s"
,
err
)
}
command
=
exec
.
Command
(
"sudo"
,
"rm"
,
"-f"
,
fmt
.
Sprintf
(
"/etc/resolver/%s"
,
r
.
ClusterDomain
))
_
,
err
=
command
.
CombinedOutput
()
if
err
!=
nil
{
t
.
Logf
(
"cleanup DNS resolver error (should be ok): %s"
,
err
)
}
}
func
TestCIDRPadding
(
t
*
testing
.
T
)
{
...
...
pkg/minikube/tunnel/route_test.go
浏览文件 @
d4cf3b0f
...
...
@@ -20,6 +20,8 @@ import (
"net"
"reflect"
"testing"
"k8s.io/minikube/pkg/util"
)
func
TestRoutingTable
(
t
*
testing
.
T
)
{
...
...
@@ -130,10 +132,12 @@ got
func
unsafeParseRoute
(
gatewayIP
string
,
destCIDR
string
)
*
Route
{
ip
:=
net
.
ParseIP
(
gatewayIP
)
_
,
ipNet
,
_
:=
net
.
ParseCIDR
(
destCIDR
)
dnsIP
,
_
:=
util
.
GetDNSIP
(
ipNet
.
String
())
expectedRoute
:=
&
Route
{
Gateway
:
ip
,
DestCIDR
:
ipNet
,
Gateway
:
ip
,
DestCIDR
:
ipNet
,
ClusterDNSIP
:
dnsIP
,
}
return
expectedRoute
}
pkg/minikube/tunnel/types.go
浏览文件 @
d4cf3b0f
...
...
@@ -61,8 +61,10 @@ func (t *Status) String() string {
// Route represents a route
type
Route
struct
{
Gateway
net
.
IP
DestCIDR
*
net
.
IPNet
Gateway
net
.
IP
DestCIDR
*
net
.
IPNet
ClusterDomain
string
ClusterDNSIP
net
.
IP
}
func
(
r
*
Route
)
String
()
string
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录