Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last start logs to minikube logs output #10465

Merged
merged 11 commits into from
Feb 24, 2021
Prev Previous commit
Next Next commit
Output last start logs during minikube logs
  • Loading branch information
spowelljr committed Feb 19, 2021
commit f390d1ef0b4325e8d5b5053a0d24e121d3ac27f8
3 changes: 1 addition & 2 deletions cmd/minikube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"strconv"

Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/minikube/localpath/localpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
22 changes: 21 additions & 1 deletion pkg/minikube/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"regexp"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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, ", "))
}
Expand All @@ -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})
Expand Down