@@ -160,6 +160,15 @@ def has_method(self, method_action):
160160 return False
161161 return method is not None
162162
163+ def fix_serialization (self , obj ):
164+ if obj and obj .kind == "Service" :
165+ for port in obj .spec .ports :
166+ try :
167+ port .target_port = int (port .target_port )
168+ except ValueError :
169+ pass
170+ return obj
171+
163172 def get_object (self , name = None , namespace = None ):
164173 k8s_obj = None
165174 method_name = 'list' if self .kind .endswith ('list' ) else 'read'
@@ -198,7 +207,7 @@ def patch_object(self, name, namespace, k8s_obj):
198207 self .__remove_creation_timestamps (k8s_obj )
199208 w , stream = self ._create_stream (namespace )
200209 return_obj = None
201- self .logger .debug ("Patching object: {}" .format (json . dumps ( k8s_obj .to_dict () )))
210+ self .logger .debug ("Patching object: {}" .format (k8s_obj .to_str ( )))
202211 try :
203212 patch_method = self .lookup_method ('patch' , namespace )
204213 if namespace :
@@ -215,7 +224,7 @@ def patch_object(self, name, namespace, k8s_obj):
215224 if not return_obj or self .kind in ('project' , 'namespace' ):
216225 return_obj = self ._wait_for_response (name , namespace , 'patch' )
217226
218- return return_obj
227+ return self . fix_serialization ( return_obj )
219228
220229 def create_object (self , namespace = None , k8s_obj = None , body = None ):
221230 """
@@ -257,7 +266,7 @@ def create_object(self, namespace=None, k8s_obj=None, body=None):
257266 if not return_obj or self .kind in ('project' , 'namespace' ):
258267 return_obj = self ._wait_for_response (name , namespace , 'create' )
259268
260- return return_obj
269+ return self . fix_serialization ( return_obj )
261270
262271 def delete_object (self , name , namespace ):
263272 self .logger .debug ('Starting delete object {0} {1} {2}' .format (self .kind , name , namespace ))
@@ -342,7 +351,7 @@ def replace_object(self, name, namespace, k8s_obj=None, body=None):
342351 if not return_obj or self .kind in ('project' , 'namespace' ):
343352 return_obj = self ._wait_for_response (name , namespace , 'replace' )
344353
345- return return_obj
354+ return self . fix_serialization ( return_obj )
346355
347356 @staticmethod
348357 def objects_match (obj_a , obj_b ):
@@ -557,7 +566,7 @@ def _read_stream(self, watcher, stream, name):
557566 for event in stream :
558567 obj = None
559568 if event .get ('object' ):
560- obj_json = json . dumps ( event ['object' ].to_dict () )
569+ obj_json = event ['object' ].to_str ( )
561570 self .logger .debug (
562571 "EVENT type: {0} object: {1}" .format (event ['type' ], obj_json )
563572 )
@@ -609,4 +618,4 @@ def _read_stream(self, watcher, stream, name):
609618 self .logger .debug ('STREAM FAILED: {}' .format (exc ))
610619 pass
611620
612- return return_obj
621+ return self . fix_serialization ( return_obj )
0 commit comments