Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
3276ed43
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,发现更多精彩内容 >>
未验证
提交
3276ed43
编写于
4月 17, 2020
作者:
M
Medya Ghazizadeh
提交者:
GitHub
4月 17, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7753 from tstromberg/dns-permissions
tunnel: Fix resolver file permissions, add DNS forwarding test
上级
825ba532
e7f08ee7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
70 addition
and
25 deletion
+70
-25
pkg/minikube/tunnel/route_darwin.go
pkg/minikube/tunnel/route_darwin.go
+39
-15
test/integration/fn_tunnel_cmd.go
test/integration/fn_tunnel_cmd.go
+31
-10
未找到文件。
pkg/minikube/tunnel/route_darwin.go
浏览文件 @
3276ed43
...
...
@@ -22,10 +22,12 @@ import (
"net"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"github.com/golang/glog"
"github.com/pkg/errors"
)
func
(
router
*
osRouter
)
EnsureRouteIsAdded
(
route
*
Route
)
error
{
...
...
@@ -37,7 +39,7 @@ func (router *osRouter) EnsureRouteIsAdded(route *Route) error {
return
nil
}
if
err
:=
writeResolverFile
(
route
);
err
!=
nil
{
return
fmt
.
Errorf
(
"could not write /etc/resolver/{cluster_domain} file: %s
"
,
err
)
glog
.
Errorf
(
"DNS forwarding unavailable: %v
"
,
err
)
}
serviceCIDR
:=
route
.
DestCIDR
.
String
()
...
...
@@ -178,26 +180,48 @@ func (router *osRouter) Cleanup(route *Route) error {
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-"
)
glog
.
Infof
(
"preparing DNS forwarding config in %q:
\n
%s"
,
resolverFile
,
content
)
// write resolver content into tf, then copy it to /etc/resolver/clusterDomain
tf
,
err
:=
ioutil
.
TempFile
(
""
,
"minikube-tunnel-resolver-"
)
if
err
!=
nil
{
return
err
return
err
ors
.
Wrap
(
err
,
"tempfile"
)
}
defer
os
.
Remove
(
tmpFile
.
Name
())
if
_
,
err
=
tmpFile
.
WriteString
(
content
);
err
!=
nil
{
return
err
defer
os
.
Remove
(
tf
.
Name
())
if
_
,
err
=
tf
.
WriteString
(
content
);
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"write"
)
}
if
err
=
tmpFile
.
Close
();
err
!=
nil
{
return
err
if
err
=
tf
.
Close
();
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"close"
)
}
cmd
:=
exec
.
Command
(
"sudo"
,
"mkdir"
,
"-p"
,
"/etc/resolver"
)
if
err
:=
cmd
.
Run
(
);
err
!=
nil
{
return
err
if
err
=
os
.
Chmod
(
tf
.
Name
(),
0644
);
err
!=
nil
{
return
err
ors
.
Wrap
(
err
,
"chmod"
)
}
cmd
=
exec
.
Command
(
"sudo"
,
"cp"
,
"-f"
,
tmpFile
.
Name
(),
resolverFile
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
return
err
cmd
:=
exec
.
Command
(
"sudo"
,
"mkdir"
,
"-p"
,
filepath
.
Dir
(
resolverFile
))
_
,
err
=
cmd
.
Output
()
if
err
!=
nil
{
if
exitErr
,
ok
:=
err
.
(
*
exec
.
ExitError
);
ok
{
return
fmt
.
Errorf
(
"%q failed: %v: %q"
,
strings
.
Join
(
cmd
.
Args
,
" "
),
exitErr
,
exitErr
.
Stderr
)
}
return
errors
.
Wrap
(
err
,
"mkdir"
)
}
cmd
=
exec
.
Command
(
"sudo"
,
"cp"
,
"-fp"
,
tf
.
Name
(),
resolverFile
)
_
,
err
=
cmd
.
Output
()
if
err
!=
nil
{
if
exitErr
,
ok
:=
err
.
(
*
exec
.
ExitError
);
ok
{
return
fmt
.
Errorf
(
"%q failed: %v: %q"
,
strings
.
Join
(
cmd
.
Args
,
" "
),
exitErr
,
exitErr
.
Stderr
)
}
return
errors
.
Wrap
(
err
,
"copy"
)
}
glog
.
Infof
(
"DNS forwarding now configured in %q"
,
resolverFile
)
return
nil
}
test/integration/fn_tunnel_cmd.go
浏览文件 @
3276ed43
...
...
@@ -41,9 +41,8 @@ func validateTunnelCmd(ctx context.Context, t *testing.T, profile string) {
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
Minutes
(
20
))
defer
cancel
()
if
runtime
.
GOOS
!=
"windows"
{
// Otherwise minikube fails waiting for a password.
if
err
:=
exec
.
Command
(
"sudo"
,
"-n"
,
"route"
)
.
Run
();
err
!=
nil
{
if
!
KicDriver
()
&&
runtime
.
GOOS
!=
"windows"
{
if
err
:=
exec
.
Command
(
"sudo"
,
"-n"
,
"ifconfig"
)
.
Run
();
err
!=
nil
{
t
.
Skipf
(
"password required to execute 'route', skipping testTunnel: %v"
,
err
)
}
}
...
...
@@ -59,7 +58,7 @@ func validateTunnelCmd(ctx context.Context, t *testing.T, profile string) {
}
// Start the tunnel
args
:=
[]
string
{
"-p"
,
profile
,
"tunnel"
,
"--alsologtostderr"
,
"-v=1"
}
args
:=
[]
string
{
"-p"
,
profile
,
"tunnel"
,
"--alsologtostderr"
}
ss
,
err
:=
Start
(
t
,
exec
.
CommandContext
(
ctx
,
Target
(),
args
...
))
if
err
!=
nil
{
t
.
Errorf
(
"failed to start a tunnel: args %q: %v"
,
args
,
err
)
...
...
@@ -80,14 +79,14 @@ func validateTunnelCmd(ctx context.Context, t *testing.T, profile string) {
}
// Wait until the nginx-svc has a loadbalancer ingress IP
nginxIP
:=
""
err
=
wait
.
PollImmediate
(
1
*
time
.
Second
,
Minutes
(
3
),
func
()
(
bool
,
error
)
{
hostname
:=
""
err
=
wait
.
PollImmediate
(
5
*
time
.
Second
,
Minutes
(
3
),
func
()
(
bool
,
error
)
{
rr
,
err
:=
Run
(
t
,
exec
.
CommandContext
(
ctx
,
"kubectl"
,
"--context"
,
profile
,
"get"
,
"svc"
,
"nginx-svc"
,
"-o"
,
"jsonpath={.status.loadBalancer.ingress[0].ip}"
))
if
err
!=
nil
{
return
false
,
err
}
if
len
(
rr
.
Stdout
.
String
())
>
0
{
nginxIP
=
rr
.
Stdout
.
String
()
hostname
=
rr
.
Stdout
.
String
()
return
true
,
nil
}
return
false
,
nil
...
...
@@ -103,9 +102,11 @@ func validateTunnelCmd(ctx context.Context, t *testing.T, profile string) {
}
got
:=
[]
byte
{}
url
:=
fmt
.
Sprintf
(
"http://%s"
,
hostname
)
fetch
:=
func
()
error
{
h
:=
&
http
.
Client
{
Timeout
:
time
.
Second
*
10
}
resp
,
err
:=
h
.
Get
(
fmt
.
Sprintf
(
"http://%s"
,
nginxIP
)
)
resp
,
err
:=
h
.
Get
(
url
)
if
err
!=
nil
{
return
&
retry
.
RetriableError
{
Err
:
err
}
}
...
...
@@ -119,12 +120,32 @@ func validateTunnelCmd(ctx context.Context, t *testing.T, profile string) {
}
return
nil
}
if
err
=
retry
.
Expo
(
fetch
,
time
.
Millisecond
*
500
,
Minutes
(
2
),
13
);
err
!=
nil
{
t
.
Errorf
(
"failed to hit nginx at %q: %v"
,
nginxIP
,
err
)
if
err
=
retry
.
Expo
(
fetch
,
3
*
time
.
Second
,
Minutes
(
2
),
13
);
err
!=
nil
{
t
.
Errorf
(
"failed to hit nginx at %q: %v"
,
url
,
err
)
}
want
:=
"Welcome to nginx!"
if
!
strings
.
Contains
(
string
(
got
),
want
)
{
t
.
Errorf
(
"expected body to contain %q, but got *%q*"
,
want
,
got
)
}
else
{
t
.
Logf
(
"tunnel at %s is working!"
,
url
)
}
// Not all platforms support DNS forwarding
if
runtime
.
GOOS
!=
"darwin"
{
return
}
url
=
"http://nginx-svc.default.svc.cluster.local"
if
err
=
retry
.
Expo
(
fetch
,
3
*
time
.
Second
,
Seconds
(
30
),
10
);
err
!=
nil
{
t
.
Errorf
(
"failed to hit nginx with DNS forwarded %q: %v"
,
url
,
err
)
}
want
=
"Welcome to nginx!"
if
!
strings
.
Contains
(
string
(
got
),
want
)
{
t
.
Errorf
(
"expected body to contain %q, but got *%q*"
,
want
,
got
)
}
else
{
t
.
Logf
(
"tunnel at %s is working!"
,
url
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录