This repository was archived by the owner on Mar 13, 2022. It is now read-only.
File tree 2 files changed +18
-1
lines changed
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):
96
96
def unmarshal_event (self , data , return_type ):
97
97
js = json .loads (data )
98
98
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' :
100
104
obj = SimpleNamespace (data = json .dumps (js ['raw_object' ]))
101
105
js ['object' ] = self ._api_client .deserialize (obj , return_type )
102
106
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):
255
255
self .assertEqual ("1" , event ['object' ]['metadata' ]['resourceVersion' ])
256
256
self .assertEqual ("1" , w .resource_version )
257
257
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
+
258
271
def test_watch_with_exception (self ):
259
272
fake_resp = Mock ()
260
273
fake_resp .close = Mock ()
You can’t perform that action at this time.
0 commit comments