Browse Source

Merge "Skip FIP creation if no external subnet config is set"

changes/21/749921/1
Zuul 11 months ago
committed by Gerrit Code Review
parent
commit
a6f70a4761
  1. 16
      kuryr_kubernetes/controller/drivers/lb_public_ip.py
  2. 3
      kuryr_kubernetes/controller/handlers/loadbalancer.py
  3. 14
      kuryr_kubernetes/tests/unit/controller/drivers/test_lb_public_ip.py

16
kuryr_kubernetes/controller/drivers/lb_public_ip.py

@ -15,7 +15,6 @@
from kuryr_kubernetes import config
from kuryr_kubernetes.controller.drivers import base
from kuryr_kubernetes.controller.drivers import public_ip
from oslo_config import cfg
from oslo_log import log as logging
LOG = logging.getLogger(__name__)
@ -44,6 +43,15 @@ class FloatingIpServicePubIPDriver(base.ServicePubIpDriver):
if spec_type != 'LoadBalancer':
return None
# get public network/subnet ids from kuryr.conf
public_network_id = config.CONF.neutron_defaults.external_svc_net
public_subnet_id = config.CONF.neutron_defaults.external_svc_subnet
if not public_network_id:
LOG.warning('Skipping Floating IP allocation on port: %s. '
'Missing value for external_svc_net config.',
port_id_to_be_associated)
return None
if spec_lb_ip:
user_specified_ip = spec_lb_ip.format()
res_id = self._drv_pub_ip.is_ip_available(user_specified_ip,
@ -63,12 +71,6 @@ class FloatingIpServicePubIPDriver(base.ServicePubIpDriver):
else:
LOG.debug("Trying to allocate public ip from pool")
# get public network/subnet ids from kuryr.conf
public_network_id = config.CONF.neutron_defaults.external_svc_net
public_subnet_id = config.CONF.neutron_defaults.external_svc_subnet
if not public_network_id:
raise cfg.RequiredOptError('external_svc_net',
cfg.OptGroup('neutron_defaults'))
try:
res_id, alloc_ip_addr = (self._drv_pub_ip.allocate_ip(
public_network_id, project_id, pub_subnet_id=public_subnet_id,

3
kuryr_kubernetes/controller/handlers/loadbalancer.py

@ -30,8 +30,6 @@ from kuryr_kubernetes import utils
LOG = logging.getLogger(__name__)
SUPPORTED_SERVICE_TYPES = ('ClusterIP', 'LoadBalancer')
class KuryrLoadBalancerHandler(k8s_base.ResourceEventHandler):
"""LoadBalancerStatusHandler handles K8s Endpoints events.
@ -83,7 +81,6 @@ class KuryrLoadBalancerHandler(k8s_base.ResourceEventHandler):
if self._sync_lbaas_members(loadbalancer_crd):
# Note(yboaron) For LoadBalancer services, we should allocate FIP,
# associate it to LB VIP and update K8S service status
# if loadbalancer_crd['status'].get('service_pub_ip_info') is None:
lb_ip = loadbalancer_crd['spec'].get('lb_ip')
pub_info = loadbalancer_crd['status'].get(
'service_pub_ip_info')

14
kuryr_kubernetes/tests/unit/controller/drivers/test_lb_public_ip.py

@ -16,13 +16,16 @@ import munch
from openstack import exceptions as os_exc
from unittest import mock
from oslo_config import cfg
from kuryr_kubernetes.controller.drivers import lb_public_ip\
as d_lb_public_ip
from kuryr_kubernetes.controller.drivers import public_ip
from kuryr_kubernetes.objects import lbaas as obj_lbaas
from kuryr_kubernetes.tests import base as test_base
from kuryr_kubernetes.tests.unit import kuryr_fixtures as k_fix
from oslo_config import cfg
CONF = cfg.CONF
class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
@ -52,6 +55,9 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
project_id = mock.sentinel.project_id
spec_type = 'LoadBalancer'
spec_lb_ip = '1.2.3.4'
CONF.set_override('external_svc_net',
'9767e1bd-40a7-4294-8e59-29dd77edb0e3',
group='neutron_defaults')
expected_resp = {
'ip_id': fip.id,
@ -111,9 +117,9 @@ class TestFloatingIpServicePubIPDriverDriver(test_base.TestCase):
spec_type = 'LoadBalancer'
spec_lb_ip = None
self.assertRaises(cfg.RequiredOptError,
driver.acquire_service_pub_ip_info,
spec_type, spec_lb_ip, project_id)
result = driver.acquire_service_pub_ip_info(
spec_type, spec_lb_ip, project_id)
self.assertIsNone(result)
@mock.patch('kuryr_kubernetes.config.CONF')
def test_acquire_service_pub_ip_info_pool_subnet_is_none(self, m_cfg):

Loading…
Cancel
Save