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, )
| 40 | |
| 41 | // streamOperatorLogsToZip streams the operator pod logs to a new section in the ZIP |
| 42 | func 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 |
no test coverage detected