Merge pull request #10839 from spowelljr/fixLogsOutput

Show last start and audit logs on `minikube logs` if minikube not running
pull/10648/head
Medya Ghazizadeh 2021-03-16 14:49:33 -07:00 committed by GitHub
commit e4d32a7675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -52,6 +52,8 @@ var logsCmd = &cobra.Command{
Short: "Returns logs to debug a local Kubernetes cluster", Short: "Returns logs to debug a local Kubernetes cluster",
Long: `Gets the logs of the running instance, used for debugging minikube, not user code.`, Long: `Gets the logs of the running instance, used for debugging minikube, not user code.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
logs.OutputOffline(numberOfLines)
co := mustload.Running(ClusterFlagValue()) co := mustload.Running(ClusterFlagValue())
bs, err := cluster.Bootstrapper(co.API, viper.GetString(cmdcfg.Bootstrapper), *co.Config, co.CP.Runner) bs, err := cluster.Bootstrapper(co.API, viper.GetString(cmdcfg.Bootstrapper), *co.Config, co.CP.Runner)

View File

@ -190,16 +190,6 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.Cluster
} }
} }
if err := outputAudit(lines); err != nil {
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 { if len(failed) > 0 {
return fmt.Errorf("unable to fetch logs for: %s", strings.Join(failed, ", ")) return fmt.Errorf("unable to fetch logs for: %s", strings.Join(failed, ", "))
} }
@ -243,6 +233,17 @@ func outputLastStart() error {
return nil return nil
} }
// OutputOffline outputs logs that don't need a running cluster.
func OutputOffline(lines int) {
if err := outputAudit(lines); err != nil {
klog.Errorf("failed to output audit logs: %v", err)
}
if err := outputLastStart(); err != nil {
klog.Errorf("failed to output last start logs: %v", err)
}
out.Styled(style.Empty, "")
}
// logCommands returns a list of commands that would be run to receive the anticipated logs // 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 { 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}) cmds := bs.LogCommands(cfg, bootstrapper.LogOptions{Lines: length, Follow: follow})