Skip to content

Commit 03efedf

Browse files
authored
Follow logs when using runDaemonSet and runPod collectors (#1783)
Follow logs when using runDaemonSet collector Signed-off-by: divolgin <[email protected]>
1 parent 9bca9c5 commit 03efedf

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pkg/collect/run_daemonset.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ func getLabelSelector(ds *appsv1.DaemonSet) string {
224224
func getPodLog(ctx context.Context, client v1.CoreV1Interface, pod corev1.Pod) ([]byte, error) {
225225
podLogOpts := corev1.PodLogOptions{
226226
Container: pod.Spec.Containers[0].Name,
227+
Follow: true,
227228
}
228229
req := client.Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts)
229230
logs, err := req.Stream(ctx)
@@ -232,7 +233,12 @@ func getPodLog(ctx context.Context, client v1.CoreV1Interface, pod corev1.Pod) (
232233
}
233234
defer logs.Close()
234235

235-
return io.ReadAll(logs)
236+
logsBytes, err := io.ReadAll(logs)
237+
if err != nil {
238+
return nil, errors.Wrap(err, "failed to read log stream")
239+
}
240+
241+
return logsBytes, nil
236242
}
237243

238244
// getPodNodeAtCompletion waits for the Pod to complete and returns the node name

pkg/collect/run_pod.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ func RunPodLogs(ctx context.Context, client v1.CoreV1Interface, podSpec *corev1.
390390
// 3. Logs
391391
podLogOpts := corev1.PodLogOptions{
392392
Container: pod.Spec.Containers[0].Name,
393+
Follow: true,
393394
}
394395
req := client.Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts)
395396
logs, err := req.Stream(ctx)

0 commit comments

Comments
 (0)