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

UI: Add log file to GitHub issue output #11158

Merged
merged 12 commits into from
Apr 24, 2021
24 changes: 24 additions & 0 deletions pkg/minikube/out/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"html/template"
"io"
"os"
"os/exec"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -359,6 +360,29 @@ func DisplayError(msg string, err error) {
ErrT(style.Empty, "")
ErrT(style.Sad, "minikube is exiting due to an error. If the above message is not useful, open an issue:")
ErrT(style.URL, "https://github.com/kubernetes/minikube/issues/new/choose")
logFileName, err := getLatestLogFileName()
if err != nil {
klog.Warning(err)
return
}
ErrT(style.Tip, "If you are able to drag and drop the following log-file into the issue, we'll be able to make faster progress: {{.logFileName}}", V{"logFileName": logFileName})
}

func getLatestLogFileName() (string, error) {
dir := os.Getenv("TMPDIR")
if dir == "" {
dir = "/tmp/"
}
args := fmt.Sprintf("cd %s && echo %s$(ls -t *minikube_*_*_*log | head -1)", dir, dir)
spowelljr marked this conversation as resolved.
Show resolved Hide resolved
c := exec.Command("/bin/bash", "-c", args)
o, err := c.Output()
if err != nil {
return "", fmt.Errorf("failed to get latest log file name: %v", err)
}
// trim newline
name := string(o)[:len(o)-1]

return name, nil
}

// applyTmpl applies formatting
Expand Down
20 changes: 20 additions & 0 deletions pkg/minikube/out/out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,23 @@ func TestErr(t *testing.T) {
t.Errorf("Err() = %q, want %q", got, want)
}
}

func TestGetLatestLogFile(t *testing.T) {
td := os.Getenv("TMPDIR")
if td == "" {
td = "/tmp/"
}
want := fmt.Sprintf("%sminikube_test_test_test.log", td)
f, err := os.Create(want)
if err != nil {
t.Fatalf("failed to create file: %v", err)
}
defer os.Remove(f.Name())
got, err := getLatestLogFileName()
if err != nil {
t.Fatalf("failed to get latest log file name: %v", err)
}
if got != want {
t.Errorf("getLatestLogFile() = %q; want %q", got, want)
}
}