MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / sendLogsToWriter

Method sendLogsToWriter

pkg/podlogs/writer.go:67–93  ·  view source on GitHub ↗
(
	ctx context.Context,
	writer io.Writer,
	options *corev1.PodLogOptions,
)

Source from the content-addressed store, hash-verified

65}
66
67func (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
96func (spl *Writer) Multiple(

Callers 2

SingleMethod · 0.95
MultipleMethod · 0.95

Calls 4

executeGetLogRequestFunction · 0.85
EncodeMethod · 0.80
DeepCopyMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected