diff --git a/pkg/addons/addons.go b/pkg/addons/addons.go index 29dc6d2a40..b1ce70bd31 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 b1693db245..8a535be9a9 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") +func displayGitHubIssueMessage() { + logPath, err := latestLogFilePath() + if err != nil { + klog.Warningf("failed to diplay GitHub issue message: %v", err) } - 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 + 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 a79f27731e..7b750ddfca 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 1082c83bd8..68aaaffcd7 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) } } }