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

Move errors getting logs into log output itself #18007

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/minikube/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/minikube/pkg/minikube/mustload"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/reason"
"k8s.io/minikube/pkg/minikube/style"
)

const (
Expand Down Expand Up @@ -120,10 +121,9 @@ var logsCmd = &cobra.Command{
logs.OutputProblems(problems, numberOfProblems, logOutput)
return
}
err = logs.Output(cr, bs, *co.Config, co.CP.Runner, numberOfLines, logOutput)
if err != nil {
out.Ln("")
out.WarningT("{{.error}}", out.V{"error": err})
logs.Output(cr, bs, *co.Config, co.CP.Runner, numberOfLines, logOutput)
if fileOutput != "" {
out.Styled(style.Success, "Logs file created ({{.logPath}}), remember to include it when reporting issues!", out.V{"logPath": fileOutput})
}
},
}
Expand Down
14 changes: 3 additions & 11 deletions pkg/minikube/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func OutputProblems(problems map[string][]string, maxLines int, logOutput *os.Fi
}

// Output displays logs from multiple sources in tail(1) format
func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.ClusterConfig, runner command.Runner, lines int, logOutput *os.File) error {
func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.ClusterConfig, runner command.Runner, lines int, logOutput *os.File) {
cmds := logCommands(r, bs, cfg, lines, false)
cmds["kernel"] = "uptime && uname -a && grep PRETTY /etc/os-release"

Expand All @@ -181,7 +181,6 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.Cluster
defer out.SetErrFile(os.Stderr)

sort.Strings(names)
failed := []string{}
for i, name := range names {
if i > 0 {
out.Styled(style.None, "")
Expand All @@ -192,8 +191,7 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.Cluster
c.Stdout = &b
c.Stderr = &b
if rr, err := runner.RunCmd(c); err != nil {
klog.Errorf("command %s failed with error: %v output: %q", rr.Command(), err, rr.Output())
failed = append(failed, name)
out.Styled(style.None, fmt.Sprintf("command %s failed with error: %v", rr.Command(), err))
continue
}
l := ""
Expand All @@ -202,16 +200,10 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.Cluster
l += scanner.Text() + "\n"
}
if err := scanner.Err(); err != nil {
klog.Errorf("failed to read output: %v", err)
failed = append(failed, name)
l += fmt.Sprintf("failed to read output: %v", err)
}
out.Styled(style.None, l)
}

if len(failed) > 0 {
return fmt.Errorf("unable to fetch logs for: %s", strings.Join(failed, ", "))
}
return nil
}

// outputAudit displays the audit logs.
Expand Down
3 changes: 0 additions & 3 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,9 +1247,6 @@ func validateLogsFileCmd(ctx context.Context, t *testing.T, profile string) {
if err != nil {
t.Errorf("%s failed: %v", rr.Command(), err)
}
if rr.Stdout.String() != "" {
t.Errorf("expected empty minikube logs output, but got: \n***%s***\n", rr.Output())
}

logs, err := os.ReadFile(logFileName)
if err != nil {
Expand Down
Loading