logger adjust
This commit is contained in:
@@ -178,37 +178,43 @@ func (cm *ContainerMonitor) watchJob(clientset *kubernetes.Clientset, execID str
|
||||
}
|
||||
|
||||
if podName == "" {
|
||||
l.Error().Msg("No pod found for job after 60s")
|
||||
cm.failExec(execID, l, "No pod found for job after 60s")
|
||||
return
|
||||
}
|
||||
|
||||
l.Info().Str("pod", podName).Msg("Pod found for job")
|
||||
|
||||
// Wait for the pod to be Running or terminal (up to 120s)
|
||||
podReady := false
|
||||
for i := 0; i < 120; i++ {
|
||||
pod, err := clientset.CoreV1().Pods(ns).Get(context.Background(), podName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
l.Error().Err(err).Str("pod", podName).Msg("Failed to get pod status")
|
||||
cm.failExec(execID, l, "Failed to get pod status: "+err.Error())
|
||||
return
|
||||
}
|
||||
phase := pod.Status.Phase
|
||||
if phase == corev1.PodRunning || phase == corev1.PodSucceeded || phase == corev1.PodFailed {
|
||||
l.Info().Str("pod", podName).Str("phase", string(phase)).Msg("Pod phase")
|
||||
podReady = true
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
if !podReady {
|
||||
cm.failExec(execID, l, "Pod never reached a running/terminal phase after 120s")
|
||||
return
|
||||
}
|
||||
|
||||
// Stream pod logs
|
||||
req := clientset.CoreV1().Pods(ns).GetLogs(podName, &corev1.PodLogOptions{Follow: true})
|
||||
stream, err := req.Stream(context.Background())
|
||||
if err != nil {
|
||||
l.Error().Err(err).Str("pod", podName).Msg("Failed to stream pod logs")
|
||||
} else {
|
||||
defer stream.Close()
|
||||
l.Info().Str("pod", podName).Msg("Streaming pod logs")
|
||||
logExecution(stream, l)
|
||||
cm.failExec(execID, l, "Failed to stream pod logs: "+err.Error())
|
||||
return
|
||||
}
|
||||
defer stream.Close()
|
||||
l.Info().Str("pod", podName).Msg("Streaming pod logs")
|
||||
logExecution(stream, l)
|
||||
|
||||
// Log final job status
|
||||
job, err := clientset.BatchV1().Jobs(ns).Get(context.Background(), jobName, metav1.GetOptions{})
|
||||
|
||||
Reference in New Issue
Block a user