Fixing k8s Service update

* use merged version of old and new objects definitions to
prevent allocation of new NodePort after update.
* objects merge is supported by pykube
* ut updated

Change-Id: Iad88b7ad77a2ec0669d00c62e0439e77de4a6e83
This commit is contained in:
Andrey Pavlov 2016-09-21 20:04:51 +03:00
parent cfa3ead967
commit e601c50d1a
2 changed files with 12 additions and 1 deletions

View File

@ -72,6 +72,11 @@ def export_object(object_dict):
object_dict, default_flow_style=False))
def _reload_obj(obj, updated_dict):
obj.reload()
obj.obj = updated_dict
def process_object(object_dict, namespace=None, client=None):
LOG.debug("Deploying %s: \"%s\"",
object_dict["kind"], object_dict["metadata"]["name"])
@ -97,6 +102,9 @@ def process_object(object_dict, namespace=None, client=None):
LOG.debug('%s "%s" already exists', object_dict['kind'],
object_dict['metadata']['name'])
if object_dict['kind'] in UPDATABLE_OBJECTS:
if object_dict['kind'] == 'Service':
# Reload object and merge new and old fields
_reload_obj(obj, object_dict)
obj.update()
LOG.debug('%s "%s" has been updated', object_dict['kind'],
object_dict['metadata']['name'])

View File

@ -62,8 +62,9 @@ class TestKubernetesObjects(testscenarios.WithScenarios, base.TestCase):
('DaemonSet', {'kind': 'DaemonSet', 'update': False}),
('Job', {'kind': 'Job', 'update': False}),
('Namespace', {'kind': 'Namespace', 'update': False}),
('Service', {'kind': 'Service', 'update': True})
('Service', {'kind': 'Service', 'update': True, 'reload': True})
)
reload = False
def setUp(self):
super(TestKubernetesObjects, self).setUp()
@ -90,5 +91,7 @@ class TestKubernetesObjects(testscenarios.WithScenarios, base.TestCase):
m_class.mock.assert_called_once_with(mock.ANY, obj_dict)
m_obj.exists.assert_called_once_with()
m_obj.create.assert_not_called()
if self.reload:
m_obj.reload.assert_called_once_with()
if self.update:
m_obj.update.assert_called_once_with()