Merge "Get trunks more diligently"
This commit is contained in:
commit
84e467a0d1
|
@ -407,7 +407,10 @@ class BaseVIFPool(base.VIFPoolDriver, metaclass=abc.ABCMeta):
|
|||
|
||||
for port in all_active_ports:
|
||||
# Parent port
|
||||
if port.trunk_details:
|
||||
# NOTE(dulek): We do not filter by worker_nodes_subnets here
|
||||
# meaning that we might include some unrelated trunks,
|
||||
# but the consequence is only memory usage.
|
||||
if port.trunk_details and port.fixed_ips:
|
||||
parent_ports[port.trunk_details['trunk_id']] = {
|
||||
'ip': port.fixed_ips[0]['ip_address'],
|
||||
'subports': port.trunk_details['sub_ports']}
|
||||
|
|
|
@ -39,6 +39,7 @@ class KuryrNetworkPopulationHandler(k8s_base.ResourceEventHandler):
|
|||
self._drv_vif_pool = drivers.VIFPoolDriver.get_instance(
|
||||
specific_driver='multi_pool')
|
||||
self._drv_vif_pool.set_vif_driver()
|
||||
self._drv_nodes_subnets = drivers.NodesSubnetsDriver.get_instance()
|
||||
|
||||
def on_added(self, kuryrnet_crd):
|
||||
subnet_id = kuryrnet_crd['status'].get('subnetId')
|
||||
|
@ -55,7 +56,9 @@ class KuryrNetworkPopulationHandler(k8s_base.ResourceEventHandler):
|
|||
# required
|
||||
subnets = self._drv_subnets.get_namespace_subnet(namespace, subnet_id)
|
||||
|
||||
nodes = utils.get_nodes_ips()
|
||||
node_subnets = self._drv_nodes_subnets.get_nodes_subnets(
|
||||
raise_on_empty=True)
|
||||
nodes = utils.get_nodes_ips(node_subnets)
|
||||
# NOTE(ltomasbo): Patching the kuryrnet_crd here instead of after
|
||||
# populate_pool method to ensure initial repopulation is not happening
|
||||
# twice upon unexpected problems, such as neutron failing to
|
||||
|
|
|
@ -16,6 +16,7 @@ from unittest import mock
|
|||
|
||||
from kuryr_kubernetes.controller.drivers import base as drivers
|
||||
from kuryr_kubernetes.controller.drivers import namespace_subnet as subnet_drv
|
||||
from kuryr_kubernetes.controller.drivers import node_subnets
|
||||
from kuryr_kubernetes.controller.drivers import utils as driver_utils
|
||||
from kuryr_kubernetes.controller.drivers import vif_pool
|
||||
from kuryr_kubernetes.controller.handlers import kuryrnetwork_population
|
||||
|
@ -52,6 +53,8 @@ class TestKuryrNetworkPopulationHandler(test_base.TestCase):
|
|||
spec=subnet_drv.NamespacePodSubnetDriver)
|
||||
self._handler._drv_vif_pool = mock.MagicMock(
|
||||
spec=vif_pool.MultiVIFPool)
|
||||
self._handler._drv_nodes_subnets = mock.MagicMock(
|
||||
spec=node_subnets.ConfigNodesSubnets)
|
||||
|
||||
self._get_namespace_subnet = (
|
||||
self._handler._drv_subnets.get_namespace_subnet)
|
||||
|
|
|
@ -313,16 +313,22 @@ class TestUtils(test_base.TestCase):
|
|||
|
||||
def test_get_nodes_ips(self):
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
ip1 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.1'}],
|
||||
ip1 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.1',
|
||||
'subnet_id': 'foo'}],
|
||||
'trunk_details': True})
|
||||
ip2 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.2'}],
|
||||
ip2 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.2',
|
||||
'subnet_id': 'bar'}],
|
||||
'trunk_details': True})
|
||||
ip3 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.3'}],
|
||||
ip3 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.3',
|
||||
'subnet_id': 'baz'}],
|
||||
'trunk_details': None})
|
||||
ports = (p for p in [ip1, ip2, ip3])
|
||||
ip4 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.4',
|
||||
'subnet_id': 'zab'}],
|
||||
'trunk_details': True})
|
||||
ports = (p for p in [ip1, ip2, ip3, ip4])
|
||||
|
||||
os_net.ports.return_value = ports
|
||||
trunk_ips = utils.get_nodes_ips()
|
||||
trunk_ips = utils.get_nodes_ips(['foo', 'bar'])
|
||||
os_net.ports.assert_called_once_with(status='ACTIVE')
|
||||
self.assertEqual(trunk_ips, [ip1.fixed_ips[0]['ip_address'],
|
||||
ip2.fixed_ips[0]['ip_address']])
|
||||
|
@ -333,14 +339,16 @@ class TestUtils(test_base.TestCase):
|
|||
group='neutron_defaults')
|
||||
|
||||
os_net = self.useFixture(k_fix.MockNetworkClient()).client
|
||||
ip1 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.1'}],
|
||||
ip1 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.1',
|
||||
'subnet_id': 'foo'}],
|
||||
'trunk_details': True})
|
||||
ip2 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.2'}],
|
||||
ip2 = munch.Munch({'fixed_ips': [{'ip_address': '10.0.0.2',
|
||||
'subnet_id': 'bar'}],
|
||||
'trunk_details': False})
|
||||
ports = (p for p in [ip1, ip2])
|
||||
|
||||
os_net.ports.return_value = ports
|
||||
trunk_ips = utils.get_nodes_ips()
|
||||
trunk_ips = utils.get_nodes_ips(['foo'])
|
||||
os_net.ports.assert_called_once_with(status='ACTIVE', tags=['foo'])
|
||||
self.assertEqual(trunk_ips, [ip1.fixed_ips[0]['ip_address']])
|
||||
|
||||
|
|
|
@ -258,7 +258,7 @@ def get_leader_name():
|
|||
|
||||
|
||||
@MEMOIZE_NODE
|
||||
def get_nodes_ips():
|
||||
def get_nodes_ips(node_subnets):
|
||||
"""Get the IPs of the trunk ports associated to the deployment."""
|
||||
trunk_ips = []
|
||||
os_net = clients.get_network_client()
|
||||
|
@ -270,7 +270,8 @@ def get_nodes_ips():
|
|||
# part of the kuryr deployment
|
||||
ports = os_net.ports(status='ACTIVE')
|
||||
for port in ports:
|
||||
if port.trunk_details:
|
||||
if (port.trunk_details and port.fixed_ips and
|
||||
port.fixed_ips[0]['subnet_id'] in node_subnets):
|
||||
trunk_ips.append(port.fixed_ips[0]['ip_address'])
|
||||
return trunk_ips
|
||||
|
||||
|
|
Loading…
Reference in New Issue