From 97d3b4c3bf4973a4fc72041ea09e41646be0d45e Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 20 Apr 2021 09:45:45 -0700 Subject: [PATCH 01/12] add log file message when suggesting user file issue --- pkg/minikube/out/out.go | 20 ++++++++++++++++++++ pkg/minikube/out/out_test.go | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/pkg/minikube/out/out.go b/pkg/minikube/out/out.go index bd3f16e5aa15..f90467baafba 100644 --- a/pkg/minikube/out/out.go +++ b/pkg/minikube/out/out.go @@ -24,6 +24,7 @@ import ( "html/template" "io" "os" + "os/exec" "strconv" "strings" "time" @@ -359,6 +360,25 @@ 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) { + args := "cd $TMPDIR && echo $TMPDIR$(ls -t *minikube_*_*_*log | head -1)" + 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 diff --git a/pkg/minikube/out/out_test.go b/pkg/minikube/out/out_test.go index 9094be289c72..60c71ea0c4fa 100644 --- a/pkg/minikube/out/out_test.go +++ b/pkg/minikube/out/out_test.go @@ -114,3 +114,20 @@ func TestErr(t *testing.T) { t.Errorf("Err() = %q, want %q", got, want) } } + +func TestGetLatestLogFile(t *testing.T) { + td := os.Getenv("TMPDIR") + 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) + } +} From 0e52a659fbc0c8a7cde644b221ae3d4902076f1e Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 20 Apr 2021 09:58:39 -0700 Subject: [PATCH 02/12] make work if TMPDIR env not set --- pkg/minikube/out/out.go | 6 +++++- pkg/minikube/out/out_test.go | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/minikube/out/out.go b/pkg/minikube/out/out.go index f90467baafba..3f7cfa2a4356 100644 --- a/pkg/minikube/out/out.go +++ b/pkg/minikube/out/out.go @@ -369,7 +369,11 @@ func DisplayError(msg string, err error) { } func getLatestLogFileName() (string, error) { - args := "cd $TMPDIR && echo $TMPDIR$(ls -t *minikube_*_*_*log | head -1)" + dir := os.Getenv("TMPDIR") + if dir == "" { + dir = "/tmp" + } + args := fmt.Sprintf("cd %s && echo %s$(ls -t *minikube_*_*_*log | head -1)", dir, dir) c := exec.Command("/bin/bash", "-c", args) o, err := c.Output() if err != nil { diff --git a/pkg/minikube/out/out_test.go b/pkg/minikube/out/out_test.go index 60c71ea0c4fa..cfea94b52ce3 100644 --- a/pkg/minikube/out/out_test.go +++ b/pkg/minikube/out/out_test.go @@ -117,6 +117,9 @@ func TestErr(t *testing.T) { 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 { From 3aaf0ff4eac0bcc38463e823759645b7c068d6cc Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 20 Apr 2021 10:00:18 -0700 Subject: [PATCH 03/12] added missing trailing slash --- pkg/minikube/out/out.go | 2 +- pkg/minikube/out/out_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/minikube/out/out.go b/pkg/minikube/out/out.go index 3f7cfa2a4356..dc5167c8875a 100644 --- a/pkg/minikube/out/out.go +++ b/pkg/minikube/out/out.go @@ -371,7 +371,7 @@ func DisplayError(msg string, err error) { func getLatestLogFileName() (string, error) { dir := os.Getenv("TMPDIR") if dir == "" { - dir = "/tmp" + dir = "/tmp/" } args := fmt.Sprintf("cd %s && echo %s$(ls -t *minikube_*_*_*log | head -1)", dir, dir) c := exec.Command("/bin/bash", "-c", args) diff --git a/pkg/minikube/out/out_test.go b/pkg/minikube/out/out_test.go index cfea94b52ce3..ad13ebd644bf 100644 --- a/pkg/minikube/out/out_test.go +++ b/pkg/minikube/out/out_test.go @@ -118,7 +118,7 @@ func TestErr(t *testing.T) { func TestGetLatestLogFile(t *testing.T) { td := os.Getenv("TMPDIR") if td == "" { - td = "/tmp" + td = "/tmp/" } want := fmt.Sprintf("%sminikube_test_test_test.log", td) f, err := os.Create(want) From 4e66128fbd4b783352c5807fb0fa669dd91476ec Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 20 Apr 2021 10:23:10 -0700 Subject: [PATCH 04/12] added output to other func that outputs GitHub issue line --- pkg/minikube/out/out.go | 6 +++--- pkg/minikube/out/out_reason.go | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/minikube/out/out.go b/pkg/minikube/out/out.go index dc5167c8875a..fb1edb7eb4e7 100644 --- a/pkg/minikube/out/out.go +++ b/pkg/minikube/out/out.go @@ -334,7 +334,7 @@ func wantsColor(w fdWriter) bool { // LogEntries outputs an error along with any important log entries. func LogEntries(msg string, err error, entries map[string][]string) { - DisplayError(msg, err) + displayError(msg, err) for name, lines := range entries { Step(style.Failure, "Problems detected in {{.entry}}:", V{"entry": name}) @@ -347,8 +347,8 @@ func LogEntries(msg string, err error, entries map[string][]string) { } } -// DisplayError prints the error and displays the standard minikube error messaging -func DisplayError(msg string, err error) { +// displayError prints the error and displays the standard minikube error messaging +func displayError(msg string, err error) { klog.Warningf(fmt.Sprintf("%s: %v", msg, err)) if JSON { FatalT("{{.msg}}: {{.err}}", V{"msg": translate.T(msg), "err": err}) diff --git a/pkg/minikube/out/out_reason.go b/pkg/minikube/out/out_reason.go index 3907e2107e20..2eefb32cd9f6 100644 --- a/pkg/minikube/out/out_reason.go +++ b/pkg/minikube/out/out_reason.go @@ -36,6 +36,7 @@ package out import ( "strings" + "k8s.io/klog/v2" "k8s.io/minikube/pkg/minikube/out/register" "k8s.io/minikube/pkg/minikube/reason" "k8s.io/minikube/pkg/minikube/style" @@ -117,4 +118,10 @@ func displayText(k reason.Kind, format string, a ...V) { ErrT(style.URL, "https://github.com/kubernetes/minikube/issues/new/choose") } Ln("") + 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}) } From c651e9614d9896e3d1a80b9e968516f911b291bb Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 20 Apr 2021 13:49:07 -0700 Subject: [PATCH 05/12] add path to lastStart.txt if user runs start command --- pkg/minikube/out/out.go | 28 ++++++++++++++++++++------ pkg/minikube/out/out_reason.go | 9 +++------ pkg/minikube/out/out_test.go | 36 ++++++++++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/pkg/minikube/out/out.go b/pkg/minikube/out/out.go index fb1edb7eb4e7..b29a5f7075f4 100644 --- a/pkg/minikube/out/out.go +++ b/pkg/minikube/out/out.go @@ -34,6 +34,7 @@ import ( isatty "github.com/mattn/go-isatty" "k8s.io/klog/v2" + "k8s.io/minikube/pkg/minikube/localpath" "k8s.io/minikube/pkg/minikube/out/register" "k8s.io/minikube/pkg/minikube/style" "k8s.io/minikube/pkg/minikube/translate" @@ -360,15 +361,12 @@ 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 + if err := displayLogLocationMessage(); err != nil { + klog.Warningf("failed to display log location message: %v", err) } - 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) { +func getLatestLogFilePath() (string, error) { dir := os.Getenv("TMPDIR") if dir == "" { dir = "/tmp/" @@ -385,6 +383,24 @@ func getLatestLogFileName() (string, error) { return name, nil } +func displayLogLocationMessage() error { + if len(os.Args) < 2 { + return fmt.Errorf("unable to detect command") + } + logPath := localpath.LastStartLog() + cmd := os.Args[1] + if cmd != "start" { + var err error + logPath, err = getLatestLogFilePath() + if err != nil { + return err + } + } + 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: {{.logPath}}", V{"logPath": logPath}) + + return nil +} + // applyTmpl applies formatting func applyTmpl(format string, a ...V) string { if len(a) == 0 { diff --git a/pkg/minikube/out/out_reason.go b/pkg/minikube/out/out_reason.go index 2eefb32cd9f6..a79f27731edf 100644 --- a/pkg/minikube/out/out_reason.go +++ b/pkg/minikube/out/out_reason.go @@ -116,12 +116,9 @@ func displayText(k reason.Kind, format string, a ...V) { ErrT(style.Empty, "") ErrT(style.Sad, "If the above advice does not help, please let us know: ") ErrT(style.URL, "https://github.com/kubernetes/minikube/issues/new/choose") + if err := displayLogLocationMessage(); err != nil { + klog.Warningf("failed to display log location message: %v", err) + } } Ln("") - 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}) } diff --git a/pkg/minikube/out/out_test.go b/pkg/minikube/out/out_test.go index ad13ebd644bf..a8d16b04fdf3 100644 --- a/pkg/minikube/out/out_test.go +++ b/pkg/minikube/out/out_test.go @@ -20,6 +20,7 @@ import ( "fmt" "os" "strconv" + "strings" "testing" "k8s.io/minikube/pkg/minikube/style" @@ -115,7 +116,7 @@ func TestErr(t *testing.T) { } } -func TestGetLatestLogFile(t *testing.T) { +func TestGetLatestLogPath(t *testing.T) { td := os.Getenv("TMPDIR") if td == "" { td = "/tmp/" @@ -126,7 +127,7 @@ func TestGetLatestLogFile(t *testing.T) { t.Fatalf("failed to create file: %v", err) } defer os.Remove(f.Name()) - got, err := getLatestLogFileName() + got, err := getLatestLogFilePath() if err != nil { t.Fatalf("failed to get latest log file name: %v", err) } @@ -134,3 +135,34 @@ func TestGetLatestLogFile(t *testing.T) { t.Errorf("getLatestLogFile() = %q; want %q", got, want) } } + +func TestDisplayLogLocationMessage(t *testing.T) { + testCases := []struct { + args []string + want string + }{ + { + []string{"minikube", "start"}, + "lastStart.txt", + }, + { + []string{"minikube", "status"}, + "minikube", + }, + } + + for _, tt := range testCases { + oldArgs := os.Args + defer func() { os.Args = oldArgs }() + os.Args = tt.args + f := tests.NewFakeFile() + SetErrFile(f) + if err := displayLogLocationMessage(); err != nil { + t.Fatalf("failed to displayLogLocationMessage: %v", err) + } + got := f.String() + if !strings.Contains(got, tt.want) { + t.Errorf("displayLogLocationMessage() = %q; wanted to contain %q", got, tt.want) + } + } +} From e108b0a1b3172873e7699fc3325d6b5f785c9df0 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 20 Apr 2021 14:16:45 -0700 Subject: [PATCH 06/12] create tmp log file for testing --- pkg/minikube/out/out_test.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/pkg/minikube/out/out_test.go b/pkg/minikube/out/out_test.go index a8d16b04fdf3..d97e928269d0 100644 --- a/pkg/minikube/out/out_test.go +++ b/pkg/minikube/out/out_test.go @@ -116,27 +116,42 @@ func TestErr(t *testing.T) { } } -func TestGetLatestLogPath(t *testing.T) { +func createLogFile() (string, error) { td := os.Getenv("TMPDIR") if td == "" { td = "/tmp/" } - want := fmt.Sprintf("%sminikube_test_test_test.log", td) - f, err := os.Create(want) + name := fmt.Sprintf("%sminikube_test_test_test.log", td) + f, err := os.Create(name) + if err != nil { + return "", fmt.Errorf("failed to create log file: %v", err) + } + + return f.Name(), nil +} + +func TestGetLatestLogPath(t *testing.T) { + want, err := createLogFile() if err != nil { - t.Fatalf("failed to create file: %v", err) + t.Fatal(err) } - defer os.Remove(f.Name()) + defer os.Remove(want) got, err := getLatestLogFilePath() 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) + t.Errorf("getLatestLogPath() = %q; want %q", got, want) } } func TestDisplayLogLocationMessage(t *testing.T) { + filename, err := createLogFile() + if err != nil { + t.Fatal(err) + } + defer os.Remove(filename) + testCases := []struct { args []string want string @@ -147,7 +162,7 @@ func TestDisplayLogLocationMessage(t *testing.T) { }, { []string{"minikube", "status"}, - "minikube", + filename, }, } From 411f934bae3a7dc20b318124cb10c4c950a3a2e4 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 20 Apr 2021 16:02:41 -0700 Subject: [PATCH 07/12] found Windows compatible way to get latest log file --- pkg/minikube/out/out.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/pkg/minikube/out/out.go b/pkg/minikube/out/out.go index b29a5f7075f4..7eec9f8bf141 100644 --- a/pkg/minikube/out/out.go +++ b/pkg/minikube/out/out.go @@ -23,8 +23,8 @@ import ( "html" "html/template" "io" + "io/ioutil" "os" - "os/exec" "strconv" "strings" "time" @@ -367,20 +367,25 @@ func displayError(msg string, err error) { } func getLatestLogFilePath() (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) - c := exec.Command("/bin/bash", "-c", args) - o, err := c.Output() + tmpdir := os.TempDir() + files, err := ioutil.ReadDir(tmpdir) if err != nil { - return "", fmt.Errorf("failed to get latest log file name: %v", err) + return "", fmt.Errorf("failed to get list of files in tempdir: %v", err) + } + var lastModName string + var lastModTime time.Time + for _, file := range files { + if !strings.Contains(file.Name(), "minikube_") { + continue + } + if !lastModTime.IsZero() && lastModTime.After(file.ModTime()) { + continue + } + lastModName = file.Name() + lastModTime = file.ModTime() } - // trim newline - name := string(o)[:len(o)-1] - return name, nil + return tmpdir + lastModName, nil } func displayLogLocationMessage() error { From c8422c0b6ee874bc92d4c2f8f489dbfa91abe1eb Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 20 Apr 2021 16:10:02 -0700 Subject: [PATCH 08/12] properly join dir and file --- pkg/minikube/out/out.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/minikube/out/out.go b/pkg/minikube/out/out.go index 7eec9f8bf141..b1693db2457f 100644 --- a/pkg/minikube/out/out.go +++ b/pkg/minikube/out/out.go @@ -25,6 +25,7 @@ import ( "io" "io/ioutil" "os" + "path/filepath" "strconv" "strings" "time" @@ -384,8 +385,9 @@ func getLatestLogFilePath() (string, error) { lastModName = file.Name() lastModTime = file.ModTime() } + fullPath := filepath.Join(tmpdir, lastModName) - return tmpdir + lastModName, nil + return fullPath, nil } func displayLogLocationMessage() error { From d17e47ca7fe63c0127971f52d9d84ed473be8680 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 20 Apr 2021 16:21:36 -0700 Subject: [PATCH 09/12] made test file generation Windows compatible as well --- pkg/minikube/out/out_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/minikube/out/out_test.go b/pkg/minikube/out/out_test.go index d97e928269d0..1082c83bd8a6 100644 --- a/pkg/minikube/out/out_test.go +++ b/pkg/minikube/out/out_test.go @@ -19,6 +19,7 @@ package out import ( "fmt" "os" + "path/filepath" "strconv" "strings" "testing" @@ -117,11 +118,8 @@ func TestErr(t *testing.T) { } func createLogFile() (string, error) { - td := os.Getenv("TMPDIR") - if td == "" { - td = "/tmp/" - } - name := fmt.Sprintf("%sminikube_test_test_test.log", td) + td := os.TempDir() + name := filepath.Join(td, "minikube_test_test_test.log") f, err := os.Create(name) if err != nil { return "", fmt.Errorf("failed to create log file: %v", err) From cd93ee9eb4877e82db0992c8e688f9905e8ed57f Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 21 Apr 2021 16:43:06 -0700 Subject: [PATCH 10/12] added message to box --- pkg/addons/addons.go | 2 +- pkg/minikube/out/out.go | 51 +++++++++++++++++----------------- pkg/minikube/out/out_reason.go | 7 +---- pkg/minikube/out/out_test.go | 33 ++++++---------------- 4 files changed, 35 insertions(+), 58 deletions(-) diff --git a/pkg/addons/addons.go b/pkg/addons/addons.go index 29dc6d2a4068..b1ce70bd3199 100644 --- a/pkg/addons/addons.go +++ b/pkg/addons/addons.go @@ -199,7 +199,7 @@ https://github.com/kubernetes/minikube/issues/7332`, out.V{"driver_name": cc.Dri return errors.Wrap(err, "registry port") } if enable { - out.Boxed(style.Tip, `Registry addon with {{.driver}} driver uses port {{.port}} please use that instead of default port 5000`, out.V{"driver": cc.Driver, "port": port}) + out.Boxed(`Registry addon with {{.driver}} driver uses port {{.port}} please use that instead of default port 5000`, out.V{"driver": cc.Driver, "port": port}) } out.Styled(style.Documentation, `For more information see: https://minikube.sigs.k8s.io/docs/drivers/{{.driver}}`, out.V{"driver": cc.Driver}) } diff --git a/pkg/minikube/out/out.go b/pkg/minikube/out/out.go index b1693db2457f..8a535be9a9c9 100644 --- a/pkg/minikube/out/out.go +++ b/pkg/minikube/out/out.go @@ -114,17 +114,14 @@ func Styled(st style.Enum, format string, a ...V) { } // Boxed writes a stylized and templated message in a box to stdout -func Boxed(st style.Enum, format string, a ...V) { +func Boxed(format string, a ...V) { str := Sprintf(style.None, format, a...) str = strings.TrimSpace(str) - box := box.New(box.Config{Type: "Round"}) + box := box.New(box.Config{Py: 1, Px: 4, Type: "Round"}) if useColor { box.Config.Color = "Red" } - txt := strings.Split(box.String("", str), "\n") - Styled(style.Indent, txt[0]) - Styled(st, txt[1]) - Styled(style.Indent, txt[2]) + box.Println("", str) } // Sprintf is used for returning the string (doesn't write anything) @@ -360,14 +357,18 @@ func displayError(msg string, err error) { ErrT(style.Empty, "") FatalT("{{.msg}}: {{.err}}", V{"msg": translate.T(msg), "err": err}) 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") - if err := displayLogLocationMessage(); err != nil { - klog.Warningf("failed to display log location message: %v", err) - } + displayGitHubIssueMessage() } -func getLatestLogFilePath() (string, error) { +func latestLogFilePath() (string, error) { + if len(os.Args) < 2 { + return "", fmt.Errorf("unable to detect command") + } + cmd := os.Args[1] + if cmd == "start" { + return localpath.LastStartLog(), nil + } + tmpdir := os.TempDir() files, err := ioutil.ReadDir(tmpdir) if err != nil { @@ -390,22 +391,20 @@ func getLatestLogFilePath() (string, error) { return fullPath, nil } -func displayLogLocationMessage() error { - if len(os.Args) < 2 { - return fmt.Errorf("unable to detect command") - } - logPath := localpath.LastStartLog() - cmd := os.Args[1] - if cmd != "start" { - var err error - logPath, err = getLatestLogFilePath() - if err != nil { - return err - } +func displayGitHubIssueMessage() { + logPath, err := latestLogFilePath() + if err != nil { + klog.Warningf("failed to diplay GitHub issue message: %v", err) } - 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: {{.logPath}}", V{"logPath": logPath}) - return nil + msg := `If the above advice does not help, please let us know: +https://github.com/kubernetes/minikube/issues/new/choose + +Please attach the following file to the GitHub issue: +- ` + msg += logPath + + Boxed(msg) } // applyTmpl applies formatting diff --git a/pkg/minikube/out/out_reason.go b/pkg/minikube/out/out_reason.go index a79f27731edf..7b750ddfca17 100644 --- a/pkg/minikube/out/out_reason.go +++ b/pkg/minikube/out/out_reason.go @@ -36,7 +36,6 @@ package out import ( "strings" - "k8s.io/klog/v2" "k8s.io/minikube/pkg/minikube/out/register" "k8s.io/minikube/pkg/minikube/reason" "k8s.io/minikube/pkg/minikube/style" @@ -114,11 +113,7 @@ func displayText(k reason.Kind, format string, a ...V) { if k.NewIssueLink { ErrT(style.Empty, "") - ErrT(style.Sad, "If the above advice does not help, please let us know: ") - ErrT(style.URL, "https://github.com/kubernetes/minikube/issues/new/choose") - if err := displayLogLocationMessage(); err != nil { - klog.Warningf("failed to display log location message: %v", err) - } + displayGitHubIssueMessage() } Ln("") } diff --git a/pkg/minikube/out/out_test.go b/pkg/minikube/out/out_test.go index 1082c83bd8a6..68aaaffcd753 100644 --- a/pkg/minikube/out/out_test.go +++ b/pkg/minikube/out/out_test.go @@ -21,9 +21,9 @@ import ( "os" "path/filepath" "strconv" - "strings" "testing" + "k8s.io/minikube/pkg/minikube/localpath" "k8s.io/minikube/pkg/minikube/style" "k8s.io/minikube/pkg/minikube/tests" "k8s.io/minikube/pkg/minikube/translate" @@ -128,22 +128,7 @@ func createLogFile() (string, error) { return f.Name(), nil } -func TestGetLatestLogPath(t *testing.T) { - want, err := createLogFile() - if err != nil { - t.Fatal(err) - } - defer os.Remove(want) - got, err := getLatestLogFilePath() - if err != nil { - t.Fatalf("failed to get latest log file name: %v", err) - } - if got != want { - t.Errorf("getLatestLogPath() = %q; want %q", got, want) - } -} - -func TestDisplayLogLocationMessage(t *testing.T) { +func TestLatestLogPath(t *testing.T) { filename, err := createLogFile() if err != nil { t.Fatal(err) @@ -156,7 +141,7 @@ func TestDisplayLogLocationMessage(t *testing.T) { }{ { []string{"minikube", "start"}, - "lastStart.txt", + localpath.LastStartLog(), }, { []string{"minikube", "status"}, @@ -168,14 +153,12 @@ func TestDisplayLogLocationMessage(t *testing.T) { oldArgs := os.Args defer func() { os.Args = oldArgs }() os.Args = tt.args - f := tests.NewFakeFile() - SetErrFile(f) - if err := displayLogLocationMessage(); err != nil { - t.Fatalf("failed to displayLogLocationMessage: %v", err) + got, err := latestLogFilePath() + if err != nil { + t.Fatalf("failed latestLogFilePath(): %v", err) } - got := f.String() - if !strings.Contains(got, tt.want) { - t.Errorf("displayLogLocationMessage() = %q; wanted to contain %q", got, tt.want) + if got != tt.want { + t.Errorf("oa.Args = %s; latestLogFilePath() = %q; wanted to contain %q", tt.args, got, tt.want) } } } From 68171b4dbecd9dc16a6375ea43166158c35d0917 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 21 Apr 2021 16:57:09 -0700 Subject: [PATCH 11/12] improved failure messages --- pkg/minikube/out/out_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/minikube/out/out_test.go b/pkg/minikube/out/out_test.go index 68aaaffcd753..593222350aa7 100644 --- a/pkg/minikube/out/out_test.go +++ b/pkg/minikube/out/out_test.go @@ -155,10 +155,10 @@ func TestLatestLogPath(t *testing.T) { os.Args = tt.args got, err := latestLogFilePath() if err != nil { - t.Fatalf("failed latestLogFilePath(): %v", err) + t.Fatalf("os.Args = %s; latestLogFilePath() failed with error = %v", tt.args, err) } if got != tt.want { - t.Errorf("oa.Args = %s; latestLogFilePath() = %q; wanted to contain %q", tt.args, got, tt.want) + t.Errorf("os.Args = %s; latestLogFilePath() = %q; wanted %q", tt.args, got, tt.want) } } } From a669ebb53e5798ff9c92433a7dada86a0b750404 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Fri, 23 Apr 2021 16:07:50 -0700 Subject: [PATCH 12/12] added back emojis --- pkg/minikube/out/out.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/minikube/out/out.go b/pkg/minikube/out/out.go index 8a535be9a9c9..45a6eb6f68b2 100644 --- a/pkg/minikube/out/out.go +++ b/pkg/minikube/out/out.go @@ -397,12 +397,10 @@ func displayGitHubIssueMessage() { klog.Warningf("failed to diplay GitHub issue message: %v", err) } - msg := `If the above advice does not help, please let us know: -https://github.com/kubernetes/minikube/issues/new/choose - -Please attach the following file to the GitHub issue: -- ` - msg += logPath + msg := Sprintf(style.Sad, "If the above advice does not help, please let us know:") + msg += Sprintf(style.URL, "https://github.com/kubernetes/minikube/issues/new/choose\n") + msg += Sprintf(style.Empty, "Please attach the following file to the GitHub issue:") + msg += Sprintf(style.Empty, "- {{.logPath}}", V{"logPath": logPath}) Boxed(msg) }