| 65 | } |
| 66 | |
| 67 | func (spl *Writer) sendLogsToWriter( |
| 68 | ctx context.Context, |
| 69 | writer io.Writer, |
| 70 | options *corev1.PodLogOptions, |
| 71 | ) error { |
| 72 | if options.Previous { |
| 73 | jsWriter := json.NewEncoder(writer) |
| 74 | if err := jsWriter.Encode("====== Beginning of Previous Log ====="); err != nil { |
| 75 | return err |
| 76 | } |
| 77 | // getting the Previous logs can fail (as with `kubectl logs -p`). Don't error out |
| 78 | previousOpts := options.DeepCopy() |
| 79 | previousRequest := spl.Client.CoreV1().Pods(spl.Pod.Namespace).GetLogs(spl.Pod.Name, previousOpts) |
| 80 | if err := executeGetLogRequest(ctx, previousRequest, writer); err != nil { |
| 81 | // we try to print the json-safe error message. We don't exit on error |
| 82 | _ = json.NewEncoder(writer).Encode("Error fetching previous logs: " + err.Error()) |
| 83 | } |
| 84 | if err := jsWriter.Encode("====== End of Previous Log ====="); err != nil { |
| 85 | return err |
| 86 | } |
| 87 | // Now fetch current logs with Previous set to false |
| 88 | options.Previous = false |
| 89 | } |
| 90 | |
| 91 | request := spl.Client.CoreV1().Pods(spl.Pod.Namespace).GetLogs(spl.Pod.Name, options) |
| 92 | return executeGetLogRequest(ctx, request, writer) |
| 93 | } |
| 94 | |
| 95 | // Multiple streams the pod logs, sending each container's stream to a separate writer |
| 96 | func (spl *Writer) Multiple( |