Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
12e41aea
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,发现更多精彩内容 >>
提交
12e41aea
编写于
3月 21, 2017
作者:
M
Matt Rickard
提交者:
GitHub
3月 21, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1273 from r2d4/logs
Add -f --folow option to minikube logs
上级
4edbe4c0
c9a5152e
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
88 addition
and
10 deletion
+88
-10
cmd/minikube/cmd/logs.go
cmd/minikube/cmd/logs.go
+6
-1
docs/bash-completion
docs/bash-completion
+3
-0
docs/minikube_logs.md
docs/minikube_logs.md
+6
-0
pkg/minikube/cluster/cluster.go
pkg/minikube/cluster/cluster.go
+17
-1
pkg/minikube/cluster/cluster_test.go
pkg/minikube/cluster/cluster_test.go
+26
-4
pkg/minikube/cluster/commands.go
pkg/minikube/cluster/commands.go
+30
-4
未找到文件。
cmd/minikube/cmd/logs.go
浏览文件 @
12e41aea
...
...
@@ -27,6 +27,10 @@ import (
"k8s.io/minikube/pkg/minikube/machine"
)
var
(
follow
bool
)
// logsCmd represents the logs command
var
logsCmd
=
&
cobra
.
Command
{
Use
:
"logs"
,
...
...
@@ -39,7 +43,7 @@ var logsCmd = &cobra.Command{
os
.
Exit
(
1
)
}
defer
api
.
Close
()
s
,
err
:=
cluster
.
GetHostLogs
(
api
)
s
,
err
:=
cluster
.
GetHostLogs
(
api
,
follow
)
if
err
!=
nil
{
log
.
Println
(
"Error getting machine logs:"
,
err
)
cmdUtil
.
MaybeReportErrorAndExit
(
err
)
...
...
@@ -49,5 +53,6 @@ var logsCmd = &cobra.Command{
}
func
init
()
{
logsCmd
.
Flags
()
.
BoolVarP
(
&
follow
,
"follow"
,
"f"
,
false
,
"Show only the most recent journal entries, and continuously print new entries as they are appended to the journal."
)
RootCmd
.
AddCommand
(
logsCmd
)
}
docs/bash-completion
浏览文件 @
12e41aea
...
...
@@ -706,6 +706,9 @@ _minikube_logs()
flags_with_completion=()
flags_completion=()
flags+=("--follow")
flags+=("-f")
local_nonpersistent_flags+=("--follow")
flags+=("--alsologtostderr")
flags+=("--log_backtrace_at=")
flags+=("--log_dir=")
...
...
docs/minikube_logs.md
浏览文件 @
12e41aea
...
...
@@ -11,6 +11,12 @@ Gets the logs of the running localkube instance, used for debugging minikube, no
minikube logs
```
### Options
```
-f, --follow Show only the most recent journal entries, and continuously print new entries as they are appended to the journal.
```
### Options inherited from parent commands
```
...
...
pkg/minikube/cluster/cluster.go
浏览文件 @
12e41aea
...
...
@@ -370,11 +370,27 @@ func GetHostDockerEnv(api libmachine.API) (map[string]string, error) {
}
// GetHostLogs gets the localkube logs of the host VM.
func
GetHostLogs
(
api
libmachine
.
API
)
(
string
,
error
)
{
// If follow is specified, it will tail the logs
func
GetHostLogs
(
api
libmachine
.
API
,
follow
bool
)
(
string
,
error
)
{
h
,
err
:=
CheckIfApiExistsAndLoad
(
api
)
if
err
!=
nil
{
return
""
,
errors
.
Wrap
(
err
,
"Error checking that api exists and loading it"
)
}
logsCommand
,
err
:=
GetLogsCommand
(
follow
)
if
err
!=
nil
{
return
""
,
errors
.
Wrap
(
err
,
"Error getting logs command"
)
}
if
follow
{
c
,
err
:=
h
.
CreateSSHClient
()
if
err
!=
nil
{
return
""
,
errors
.
Wrap
(
err
,
"Error creating ssh client"
)
}
err
=
c
.
Shell
(
logsCommand
)
if
err
!=
nil
{
return
""
,
errors
.
Wrap
(
err
,
"error ssh shell"
)
}
return
""
,
err
}
s
,
err
:=
h
.
RunSSHCommand
(
logsCommand
)
if
err
!=
nil
{
return
""
,
err
...
...
pkg/minikube/cluster/cluster_test.go
浏览文件 @
12e41aea
...
...
@@ -495,12 +495,34 @@ func TestHostGetLogs(t *testing.T) {
}
api
.
Hosts
[
constants
.
MachineName
]
=
&
host
.
Host
{
Driver
:
d
}
if
_
,
err
:=
GetHostLogs
(
api
);
err
!=
nil
{
t
.
Fatalf
(
"Error getting host logs: %s"
,
err
)
tests
:=
[]
struct
{
description
string
follow
bool
}{
{
description
:
"logs"
,
follow
:
false
,
},
{
description
:
"logs -f"
,
follow
:
true
,
},
}
if
_
,
ok
:=
s
.
Commands
[
logsCommand
];
!
ok
{
t
.
Fatalf
(
"Expected command not run: %s"
,
logsCommand
)
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
description
,
func
(
t
*
testing
.
T
)
{
t
.
Parallel
()
cmd
,
err
:=
GetLogsCommand
(
test
.
follow
)
if
err
!=
nil
{
t
.
Errorf
(
"Error getting the logs command: %s"
,
err
)
}
if
_
,
err
=
GetHostLogs
(
api
,
test
.
follow
);
err
!=
nil
{
t
.
Errorf
(
"Error getting host logs: %s"
,
err
)
}
if
_
,
ok
:=
s
.
Commands
[
cmd
];
!
ok
{
t
.
Errorf
(
"Expected command to run but did not: %s"
,
cmd
)
}
})
}
}
...
...
pkg/minikube/cluster/commands.go
浏览文件 @
12e41aea
...
...
@@ -180,13 +180,39 @@ func GenLocalkubeStartCmd(kubernetesConfig KubernetesConfig) (string, error) {
return
buf
.
String
(),
nil
}
var
logsCommand
=
fmt
.
Sprintf
(
`
const
logsTemplate
=
`
if which systemctl 2>&1 1>/dev/null; then
sudo journalctl -u localkube
sudo journalctl
{{.Flags}}
-u localkube
else
tail -n +1
%s
%s
tail -n +1
{{.Flags}} {{.RemoteLocalkubeErrPath}} {{.RemoteLocalkubeOutPath}}
%s
fi
`
,
constants
.
RemoteLocalKubeErrPath
,
constants
.
RemoteLocalKubeOutPath
)
`
func
GetLogsCommand
(
follow
bool
)
(
string
,
error
)
{
t
,
err
:=
template
.
New
(
"logsTemplate"
)
.
Parse
(
logsTemplate
)
if
err
!=
nil
{
return
""
,
err
}
var
flags
[]
string
if
follow
{
flags
=
append
(
flags
,
"-f"
)
}
buf
:=
bytes
.
Buffer
{}
data
:=
struct
{
RemoteLocalkubeErrPath
string
RemoteLocalkubeOutPath
string
Flags
string
}{
RemoteLocalkubeErrPath
:
constants
.
RemoteLocalKubeErrPath
,
RemoteLocalkubeOutPath
:
constants
.
RemoteLocalKubeOutPath
,
Flags
:
strings
.
Join
(
flags
,
" "
),
}
if
err
:=
t
.
Execute
(
&
buf
,
data
);
err
!=
nil
{
return
""
,
err
}
return
buf
.
String
(),
nil
}
var
localkubeStatusCommand
=
fmt
.
Sprintf
(
`
if which systemctl 2>&1 1>/dev/null; then
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录