Merge "Skip pool pre population if no Status is present on CRD"

This commit is contained in:
Zuul 2021-02-25 10:06:35 +00:00 committed by Gerrit Code Review
commit d344c54fb7
2 changed files with 9 additions and 6 deletions

View File

@ -41,13 +41,16 @@ class KuryrNetworkPopulationHandler(k8s_base.ResourceEventHandler):
self._drv_vif_pool.set_vif_driver() self._drv_vif_pool.set_vif_driver()
self._drv_nodes_subnets = drivers.NodesSubnetsDriver.get_instance() self._drv_nodes_subnets = drivers.NodesSubnetsDriver.get_instance()
def on_added(self, kuryrnet_crd): def on_present(self, kuryrnet_crd):
subnet_id = kuryrnet_crd['status'].get('subnetId') subnet_id = kuryrnet_crd.get('status', {}).get('subnetId')
if not subnet_id: if not subnet_id:
LOG.debug("No Subnet present for KuryrNetwork %s",
kuryrnet_crd['metadata']['name'])
return return
if kuryrnet_crd['status'].get('populated'): if kuryrnet_crd['status'].get('populated'):
LOG.debug("Subnet %s already populated", subnet_id) LOG.debug("Subnet %s already populated for Namespace %s",
subnet_id, kuryrnet_crd['metadata']['name'])
return return
namespace = kuryrnet_crd['spec'].get('nsName') namespace = kuryrnet_crd['spec'].get('nsName')

View File

@ -81,12 +81,12 @@ class TestKuryrNetworkPopulationHandler(test_base.TestCase):
@mock.patch.object(driver_utils, 'get_annotations') @mock.patch.object(driver_utils, 'get_annotations')
@mock.patch.object(driver_utils, 'get_namespace') @mock.patch.object(driver_utils, 'get_namespace')
@mock.patch.object(utils, 'get_nodes_ips') @mock.patch.object(utils, 'get_nodes_ips')
def test_on_added(self, m_get_nodes_ips, m_get_ns, m_get_ann): def test_on_present(self, m_get_nodes_ips, m_get_ns, m_get_ann):
m_get_nodes_ips.return_value = ['node-ip'] m_get_nodes_ips.return_value = ['node-ip']
m_get_ns.return_value = mock.sentinel.ns m_get_ns.return_value = mock.sentinel.ns
m_get_ann.return_value = self._kuryrnet_crd['metadata']['name'] m_get_ann.return_value = self._kuryrnet_crd['metadata']['name']
kuryrnetwork_population.KuryrNetworkPopulationHandler.on_added( kuryrnetwork_population.KuryrNetworkPopulationHandler.on_present(
self._handler, self._kuryrnet_crd) self._handler, self._kuryrnet_crd)
self._get_namespace_subnet.assert_called_once_with( self._get_namespace_subnet.assert_called_once_with(
@ -99,7 +99,7 @@ class TestKuryrNetworkPopulationHandler(test_base.TestCase):
def test_on_added_no_subnet(self): def test_on_added_no_subnet(self):
kns = self._kuryrnet_crd.copy() kns = self._kuryrnet_crd.copy()
kns['status'] = {} del kns['status']
kuryrnetwork_population.KuryrNetworkPopulationHandler.on_added( kuryrnetwork_population.KuryrNetworkPopulationHandler.on_added(
self._handler, kns) self._handler, kns)
self._get_namespace_subnet.assert_not_called() self._get_namespace_subnet.assert_not_called()