From f390d1ef0b4325e8d5b5053a0d24e121d3ac27f8 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Fri, 12 Feb 2021 18:12:46 -0700 Subject: [PATCH] Output last start logs during minikube logs --- cmd/minikube/main.go | 3 +-- pkg/minikube/localpath/localpath.go | 5 +++++ pkg/minikube/logs/logs.go | 22 +++++++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cmd/minikube/main.go b/cmd/minikube/main.go index 080c736f2c..c600a31a03 100644 --- a/cmd/minikube/main.go +++ b/cmd/minikube/main.go @@ -22,7 +22,6 @@ import ( "fmt" "log" "os" - "path/filepath" "regexp" "strconv" @@ -145,7 +144,7 @@ func setFlags() { } } if os.Args[1] == "start" { - fp := filepath.Join(localpath.MiniPath(), "logs", "lastStart.txt") + fp := localpath.LastStartLog() if err := os.Remove(fp); err != nil { klog.Warningf("Unable to delete file %s: %v", err) } diff --git a/pkg/minikube/localpath/localpath.go b/pkg/minikube/localpath/localpath.go index 2699d51591..3558ef9a30 100644 --- a/pkg/minikube/localpath/localpath.go +++ b/pkg/minikube/localpath/localpath.go @@ -74,6 +74,11 @@ func AuditLog() string { return filepath.Join(MiniPath(), "logs", "audit.json") } +// LastStartLog returns the path to the last start log. +func LastStartLog() string { + return filepath.Join(MiniPath(), "logs", "lastStart.txt") +} + // ClientCert returns client certificate path, used by kubeconfig func ClientCert(name string) string { new := filepath.Join(Profile(name), "client.crt") diff --git a/pkg/minikube/logs/logs.go b/pkg/minikube/logs/logs.go index 8f20856249..8e7f42915e 100644 --- a/pkg/minikube/logs/logs.go +++ b/pkg/minikube/logs/logs.go @@ -21,6 +21,7 @@ import ( "bufio" "bytes" "fmt" + "io/ioutil" "os" "os/exec" "regexp" @@ -34,6 +35,7 @@ import ( "k8s.io/minikube/pkg/minikube/command" "k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/cruntime" + "k8s.io/minikube/pkg/minikube/localpath" "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/style" ) @@ -190,10 +192,15 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.Cluster } if err := outputAudit(lines); err != nil { - klog.Error(err) + klog.Errorf("failed to output audit logs: %v", err) failed = append(failed, "audit") } + if err := outputLastStart(); err != nil { + klog.Errorf("failed to output last start logs: %v", err) + failed = append(failed, "last start") + } + if len(failed) > 0 { return fmt.Errorf("unable to fetch logs for: %s", strings.Join(failed, ", ")) } @@ -212,6 +219,19 @@ func outputAudit(lines int) error { return nil } +// outputLastStart outputs the last start logs. +func outputLastStart() error { + out.Step(style.Empty, "") + out.Step(style.Empty, "==> Last Start <==") + fp := localpath.LastStartLog() + l, err := ioutil.ReadFile(fp) + if err != nil { + return fmt.Errorf("failed to read file %s: %v", fp, err) + } + out.Step(style.Empty, string(l)) + return nil +} + // 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})