Skip to content

Commit

Permalink
Merge pull request #478 from openshift-cherrypick-robot/cherry-pick-4…
Browse files Browse the repository at this point in the history
…49-to-release-4.6

Bug 1938161: Get trunks more diligently
  • Loading branch information
openshift-merge-robot committed Mar 17, 2021
2 parents 97998b7 + f5834df commit 1084421
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
5 changes: 4 additions & 1 deletion kuryr_kubernetes/controller/drivers/vif_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ def _get_trunks_info(self):

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']}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from oslo_config import cfg
from oslo_log import log as logging

from kuryr_kubernetes import clients
Expand All @@ -22,6 +23,7 @@
from kuryr_kubernetes import utils

LOG = logging.getLogger(__name__)
CONF = cfg.CONF


class KuryrNetworkPopulationHandler(k8s_base.ResourceEventHandler):
Expand Down Expand Up @@ -55,7 +57,8 @@ def on_added(self, kuryrnet_crd):
# required
subnets = self._drv_subnets.get_namespace_subnet(namespace, subnet_id)

nodes = utils.get_nodes_ips()
node_subnets = [CONF.pod_vif_nested.worker_nodes_subnet]
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
Expand Down
24 changes: 16 additions & 8 deletions kuryr_kubernetes/tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,22 @@ def test_has_port_changes_no_changes(self, m_get_service_ports):

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']])
Expand All @@ -322,14 +328,16 @@ def test_get_nodes_ips_tagged(self):
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']])

Expand Down
5 changes: 3 additions & 2 deletions kuryr_kubernetes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,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()
Expand All @@ -201,7 +201,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

Expand Down

0 comments on commit 1084421

Please sign in to comment.