python: Passing `follow=True` to `read_namespaced_pod_log` makes it never return

I’m trying to stream logs out of a running pod.

For a pod named ‘test’ running in the default namespace,

api = client.CoreV1Api()
api.read_namespaced_pod_log("test", "default")

returns the logs so far. But,

api = client.CoreV1Api()
api.read_namespaced_pod_log("test", "default", follow=True)

just never returns. I can’t use it with watch.Watch either since that seems to be for a very different purpose.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 6
  • Comments: 22 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Ah so what I did initially was close but the temporary fix that worked for me was -

for line in client.CoreV1Api.read_namespaced_pod_log('<pod_name>', 'default', follow=True, _preload_content=False).stream():
    print(line)
for line in client.CoreV1Api.read_namespaced_pod_log('<pod_name>', 'default', follow=True, _preload_content=False).stream():

I had to decode the output:

for line in v1.read_namespaced_pod_log(<pod-ame>,<namespace>,follow = True, _preload_content=False).stream():
   print(line.decode('utf-8'))

/edit the proper way to do it:

from kubernetes import watch
 w = watch.Watch()
 for line in w.stream(v1.read_namespaced_pod_log, name=<pod-name>, namespace='<namespace>'):
    log.info(line)

Having trouble using this, am i missing something?

v1 = client.CoreV1Api() w = watch.Watch() for e in w.stream(v1.read_namespaced_pod_log, name=pod, namespace=namespace, follow=True, tail_lines=1, limit_bytes=560, _preload_content=False): print(e)

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.7/site-packages/kubernetes/watch/watch.py", line 132, in stream resp = func(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/core_v1_api.py", line 18538, in read_namespaced_pod_log (data) = self.read_namespaced_pod_log_with_http_info(name, namespace, **kwargs) File "/usr/local/lib/python3.7/site-packages/kubernetes/client/apis/core_v1_api.py", line 18576, in read_namespaced_pod_log_with_http_info " to method read_namespaced_pod_log" % key TypeError: Got an unexpected keyword argument 'watch' to method read_namespaced_pod_log

Posted on stackoverflow if anyone wanted to answer!

I am looking through the tests and I may be able to help. Let me work through the watch routines and I’ll let you know. @mitar