File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,11 @@ def get_watch_argument_name(self, func):
9696 def unmarshal_event (self , data , return_type ):
9797 js = json .loads (data )
9898 js ['raw_object' ] = js ['object' ]
99- if return_type and js ['type' ] != 'ERROR' :
99+ # BOOKMARK event is treated the same as ERROR for a quick fix of
100+ # decoding exception
101+ # TODO: make use of the resource_version in BOOKMARK event for more
102+ # efficient WATCH
103+ if return_type and js ['type' ] != 'ERROR' and js ['type' ] != 'BOOKMARK' :
100104 obj = SimpleNamespace (data = json .dumps (js ['raw_object' ]))
101105 js ['object' ] = self ._api_client .deserialize (obj , return_type )
102106 if hasattr (js ['object' ], 'metadata' ):
Original file line number Diff line number Diff line change @@ -255,6 +255,19 @@ def test_unmarshal_with_custom_object(self):
255255 self .assertEqual ("1" , event ['object' ]['metadata' ]['resourceVersion' ])
256256 self .assertEqual ("1" , w .resource_version )
257257
258+ def test_unmarshal_with_bookmark (self ):
259+ w = Watch ()
260+ event = w .unmarshal_event (
261+ '{"type":"BOOKMARK","object":{"kind":"Job","apiVersion":"batch/v1"'
262+ ',"metadata":{"resourceVersion":"1"},"spec":{"template":{'
263+ '"metadata":{},"spec":{"containers":null}}},"status":{}}}' ,
264+ 'V1Job' )
265+ self .assertEqual ("BOOKMARK" , event ['type' ])
266+ # Watch.resource_version is *not* updated, as BOOKMARK is treated the
267+ # same as ERROR for a quick fix of decoding exception,
268+ # resource_version in BOOKMARK is *not* used at all.
269+ self .assertEqual (None , w .resource_version )
270+
258271 def test_watch_with_exception (self ):
259272 fake_resp = Mock ()
260273 fake_resp .close = Mock ()
You can’t perform that action at this time.
0 commit comments