Follow logs when using runDaemonSet and runPod collectors (#1783)

Follow logs when using runDaemonSet collector

Signed-off-by: divolgin <dmitriy@replicated.com>
This commit is contained in:
Dmitriy Ivolgin
2025-05-09 12:54:28 -07:00
committed by GitHub
parent 9bca9c5245
commit 03efedf714
2 changed files with 8 additions and 1 deletions

View File

@@ -224,6 +224,7 @@ func getLabelSelector(ds *appsv1.DaemonSet) string {
func getPodLog(ctx context.Context, client v1.CoreV1Interface, pod corev1.Pod) ([]byte, error) {
podLogOpts := corev1.PodLogOptions{
Container: pod.Spec.Containers[0].Name,
Follow: true,
}
req := client.Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts)
logs, err := req.Stream(ctx)
@@ -232,7 +233,12 @@ func getPodLog(ctx context.Context, client v1.CoreV1Interface, pod corev1.Pod) (
}
defer logs.Close()
return io.ReadAll(logs)
logsBytes, err := io.ReadAll(logs)
if err != nil {
return nil, errors.Wrap(err, "failed to read log stream")
}
return logsBytes, nil
}
// getPodNodeAtCompletion waits for the Pod to complete and returns the node name

View File

@@ -390,6 +390,7 @@ func RunPodLogs(ctx context.Context, client v1.CoreV1Interface, podSpec *corev1.
// 3. Logs
podLogOpts := corev1.PodLogOptions{
Container: pod.Spec.Containers[0].Name,
Follow: true,
}
req := client.Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts)
logs, err := req.Stream(ctx)