提交 eb8f7e65 编写于 作者: S Steven Powell

Show last start and audit logs on `minikube logs` if minikube not running

上级 f95d43a2
......@@ -23,6 +23,7 @@ import (
"github.com/spf13/viper"
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/logs"
......@@ -52,6 +53,11 @@ var logsCmd = &cobra.Command{
Short: "Returns logs to debug a local Kubernetes cluster",
Long: `Gets the logs of the running instance, used for debugging minikube, not user code.`,
Run: func(cmd *cobra.Command, args []string) {
if !isClusterRunning() {
logs.OutputMinikubeLogs(numberOfLines)
return
}
co := mustload.Running(ClusterFlagValue())
bs, err := cluster.Bootstrapper(co.API, viper.GetString(cmdcfg.Bootstrapper), *co.Config, co.CP.Runner)
......@@ -85,6 +91,16 @@ var logsCmd = &cobra.Command{
},
}
func isClusterRunning() bool {
if _, err := config.Load(ClusterFlagValue()); err != nil {
if config.IsNotExist(err) {
return false
}
exit.Error(reason.HostConfigLoad, "Error getting cluster config", err)
}
return true
}
func init() {
logsCmd.Flags().BoolVarP(&followLogs, "follow", "f", false, "Show only the most recent journal entries, and continuously print new entries as they are appended to the journal.")
logsCmd.Flags().BoolVar(&showProblems, "problems", false, "Show only log entries which point to known problems")
......
......@@ -243,6 +243,16 @@ func outputLastStart() error {
return nil
}
// OutputMinikubeLogs outputs the audit and last start logs only
func OutputMinikubeLogs(lines int) {
if err := outputAudit(lines); err != nil {
klog.Errorf("failed to output audit logs: %v", err)
}
if err := outputLastStart(); err != nil {
klog.Errorf("failed to output last start logs: %v", err)
}
}
// logCommands returns a list of commands that would be run to receive the anticipated logs
func logCommands(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.ClusterConfig, length int, follow bool) map[string]string {
cmds := bs.LogCommands(cfg, bootstrapper.LogOptions{Lines: length, Follow: follow})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册