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

Function streamOperatorLogsToZip

internal/cmd/plugin/report/logs.go:42–74  ·  view source on GitHub ↗

streamOperatorLogsToZip streams the operator pod logs to a new section in the ZIP

(
	ctx context.Context,
	pods []corev1.Pod,
	dirName string,
	name string,
	logTimeStamp bool,
	zipper *zip.Writer,
)

Source from the content-addressed store, hash-verified

40
41// streamOperatorLogsToZip streams the operator pod logs to a new section in the ZIP
42func streamOperatorLogsToZip(
43 ctx context.Context,
44 pods []corev1.Pod,
45 dirName string,
46 name string,
47 logTimeStamp bool,
48 zipper *zip.Writer,
49) error {
50 logsDir := filepath.Join(dirName, name)
51 if _, err := zipper.Create(logsDir + "/"); err != nil {
52 return fmt.Errorf("could not add '%s' to zip: %w", logsDir, err)
53 }
54
55 for i := range pods {
56 pod := pods[i]
57 path := filepath.Join(logsDir, fmt.Sprintf("%s-logs.jsonl", pod.Name))
58 writer, zipperErr := zipper.Create(path)
59 if zipperErr != nil {
60 return fmt.Errorf("could not add '%s' to zip: %w", path, zipperErr)
61 }
62
63 streamPodLogs := podlogs.NewPodLogsWriter(pod, kubernetes.NewForConfigOrDie(ctrl.GetConfigOrDie()))
64 opts := &corev1.PodLogOptions{
65 Timestamps: logTimeStamp,
66 Previous: true,
67 }
68 if err := streamPodLogs.Single(ctx, writer, opts); err != nil {
69 return err
70 }
71 }
72
73 return nil
74}
75
76// streamClusterLogsToZip streams the logs from the pods in the cluster, one by
77// one, each in a new file, within a folder

Callers 1

assembleSectionsFunction · 0.85

Calls 4

NewPodLogsWriterFunction · 0.92
JoinMethod · 0.80
SingleMethod · 0.80
CreateMethod · 0.65

Tested by

no test coverage detected