Fix adding pods with host networking to svc in L2 mode

If L2 mode is used for services, there is a need for stating the
subnet the pods belong to when adding them as members of the load
balancer. If these pods have host networking, then their IPs will
not be neither in the subnet CIDR range for the default pod subnet,
nor on the namespace subnet CIDR if namespace subnet driver is used.

To overcome this, we assume that in case the pod IP is not within
those ranges it means it is running on host networking mode. And
thus the worker_node_subnet CIDR range should be used instead.

Change-Id: I4ce376956b66047069b6544d36f5c3d47fa38b01
Closes-Bug: 1834605
This commit is contained in:
Luis Tomas Bolivar 2019-06-28 13:55:36 +02:00
parent bc25531108
commit 0345cd86c8
1 changed files with 10 additions and 4 deletions

View File

@ -387,10 +387,16 @@ class LoadBalancerHandler(k8s_base.ResourceEventHandler):
'namespace': target_ref['namespace']}}
project_id = self._drv_pod_project.get_project(pod)
subnets_map = self._drv_pod_subnets.get_subnets(pod, project_id)
# FIXME(ivc): potentially unsafe [0] index
return [subnet_id for subnet_id, network in subnets_map.items()
for subnet in network.subnets.objects
if ip in subnet.cidr][0]
subnet_ids = [subnet_id for subnet_id, network in subnets_map.items()
for subnet in network.subnets.objects
if ip in subnet.cidr]
if subnet_ids:
return subnet_ids[0]
else:
# NOTE(ltomasbo): We are assuming that if ip is not on the
# pod subnet is because the member is using hostnetworking. In
# this worker_nodes_subnet will be used
return config.CONF.pod_vif_nested.worker_nodes_subnet
def _get_port_in_pool(self, pool, lbaas_state, lbaas_spec):
for l in lbaas_state.listeners: