Rename variable
This commit is contained in:
parent
7e74fb6f08
commit
3639b43260
|
@ -163,35 +163,35 @@ func (pw *PodWatcher) removePod(podName string) {
|
||||||
delete(pw.status, podName)
|
delete(pw.status, podName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyPodLogs(ctx context.Context, wg *sync.WaitGroup, clientset KubernetesClient, p *corev1.Pod, container string, dst io.Writer) *streamError {
|
func copyPodLogs(ctx context.Context, wg *sync.WaitGroup, clientset KubernetesClient, pod *corev1.Pod, container string, dst io.Writer) *streamError {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
podLogOpts := corev1.PodLogOptions{
|
podLogOpts := corev1.PodLogOptions{
|
||||||
Follow: true,
|
Follow: true,
|
||||||
Container: container,
|
Container: container,
|
||||||
}
|
}
|
||||||
req := clientset.CoreV1().Pods(p.Namespace).GetLogs(p.Name, &podLogOpts)
|
req := clientset.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts)
|
||||||
logs, err := req.Stream(ctx)
|
logs, err := req.Stream(ctx)
|
||||||
|
|
||||||
// If one container is still being created, do not treat this as a fatal error.
|
// If one container is still being created, do not treat this as a fatal error.
|
||||||
// We try to verify the error type as strictly as possible.
|
// We try to verify the error type as strictly as possible.
|
||||||
var statusErr *apierrors.StatusError
|
var statusErr *apierrors.StatusError
|
||||||
if errors.As(err, &statusErr) && statusErr.Status().Reason == metav1.StatusReasonBadRequest && strings.Contains(statusErr.Error(), "ContainerCreating") {
|
if errors.As(err, &statusErr) && statusErr.Status().Reason == metav1.StatusReasonBadRequest && strings.Contains(statusErr.Error(), "ContainerCreating") {
|
||||||
return newRecoverableError(err, p.Name)
|
return newRecoverableError(err, pod.Name)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return newStreamError(err, p.Name)
|
return newStreamError(err, pod.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() { _ = logs.Close() }()
|
defer func() { _ = logs.Close() }()
|
||||||
|
|
||||||
scanner := bufio.NewScanner(logs)
|
scanner := bufio.NewScanner(logs)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
if _, err = dst.Write([]byte("[" + p.Name + "] " + scanner.Text() + nl)); err != nil {
|
if _, err = dst.Write([]byte("[" + pod.Name + "] " + scanner.Text() + nl)); err != nil {
|
||||||
return newStreamError(fmt.Errorf("error writing logs: %v", err), p.Name)
|
return newStreamError(fmt.Errorf("error writing logs: %v", err), pod.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
return newStreamError(fmt.Errorf("error scanning logs: %v", err), p.Name)
|
return newStreamError(fmt.Errorf("error scanning logs: %v", err), pod.Name)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue