client-go
client-go copied to clipboard
GetLogs function hangs after 4 hours
the below is a code to tail logs for specific pod/container. when tailing pod, after 4 hours exactly, it hangs and break loop of Scan() and continue while pod still running. In addition, kubectl logs -f POD -n NS also stopped after 4 hours. Any idea, someone?
rs, err := api.clientset.CoreV1().Pods(api.ns).GetLogs(api.podName, &v1.PodLogOptions{
Container: api.options.containerName,
Follow: true,
}).Stream(context.TODO())
if err != nil {
return err
}
defer rs.Close()
sc := bufio.NewScanner(rs)
f := bufio.NewWriter(os.Stdout)
defer f.Flush()
for sc.Scan() {
f.Write([]byte(sc.Text() + "\n"))
f.Flush()
}