Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #185 from roycaihw/watch-unmarshal
Browse files Browse the repository at this point in the history
watch stream: don't unmarshal responses when streaming log
  • Loading branch information
k8s-ci-robot authored Mar 3, 2020
2 parents d30f1e6 + ea11e44 commit b87a5fe
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions watch/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,7 @@ def get_watch_argument_name(self, func):
return 'watch'

def unmarshal_event(self, data, return_type):
try:
js = json.loads(data)
except ValueError:
return data
if not (isinstance(js, dict) and 'object' in js):
return data
js = json.loads(data)
js['raw_object'] = js['object']
if return_type:
obj = SimpleNamespace(data=json.dumps(js['raw_object']))
Expand Down Expand Up @@ -132,7 +127,8 @@ def stream(self, func, *args, **kwargs):

self._stop = False
return_type = self.get_return_type(func)
kwargs[self.get_watch_argument_name(func)] = True
watch_arg = self.get_watch_argument_name(func)
kwargs[watch_arg] = True
kwargs['_preload_content'] = False
if 'resource_version' in kwargs:
self.resource_version = kwargs['resource_version']
Expand All @@ -142,7 +138,12 @@ def stream(self, func, *args, **kwargs):
resp = func(*args, **kwargs)
try:
for line in iter_resp_lines(resp):
yield self.unmarshal_event(line, return_type)
# unmarshal when we are receiving events from watch,
# return raw string when we are streaming log
if watch_arg == "watch":
yield self.unmarshal_event(line, return_type)
else:
yield line
if self._stop:
break
finally:
Expand Down

0 comments on commit b87a5fe

Please sign in to comment.