diff --git a/kuryr_kubernetes/controller/handlers/loadbalancer.py b/kuryr_kubernetes/controller/handlers/loadbalancer.py index 848c0bf9e..3b0954ac3 100755 --- a/kuryr_kubernetes/controller/handlers/loadbalancer.py +++ b/kuryr_kubernetes/controller/handlers/loadbalancer.py @@ -181,8 +181,9 @@ class KuryrLoadBalancerHandler(k8s_base.ResourceEventHandler): LOG.debug("Reconciling the KuryrLoadBalancer CRDs") lbaas = clients.get_loadbalancer_client() resources_fn = {'loadbalancer': lbaas.load_balancers, - 'listener': lbaas.listeners} - resources = {'loadbalancer': [], 'listener': []} + 'listener': lbaas.listeners, + 'pool': lbaas.pools} + resources = {'loadbalancer': [], 'listener': [], 'pool': []} for klb in loadbalancer_crds: if klb['metadata'].get('deletionTimestamp'): @@ -200,10 +201,15 @@ class KuryrLoadBalancerHandler(k8s_base.ResourceEventHandler): resources['listener'].append({'id': lbl['id'], 'selflink': selflink, 'lklb': klb}) + for pl in klb.get('status', {}).get('pools', []): + resources['pool'].append({'id': pl['id'], + 'selflink': selflink, + 'pklb': klb}) resources_already_triggered = [] - # let's reconcile load balancers first, and than listeners - for resource_type in ('loadbalancer', 'listener'): + # let's reconcile load balancers first, listeners and then pools + resource_types = ('loadbalancer', 'listener', 'pool') + for resource_type in resource_types: filters = {} self._drv_lbaas.add_tags(resource_type, filters) os_list = resources_fn[resource_type] @@ -223,13 +229,15 @@ class KuryrLoadBalancerHandler(k8s_base.ResourceEventHandler): try: if data.get('klb'): self._add_event(data['klb'], 'LoadBalancerRecreating', - 'Load balancer for the Service seems to not ' + 'Load balancer for the Service does not ' 'exist anymore. Recreating it.', 'Warning') if data.get('lklb'): - self._add_event(data['lklb'], 'LoadBalancerRecreating', - 'Listener of load balancer for the Service ' - 'seems to not exist anymore. Recreating it.', - 'Warning') + self._add_event(data['lklb'], 'Load Balancer listener does not' + ' exist anymore. Recreating it.', 'Warning') + if data.get('pklb'): + self._add_event(data['pklb'], 'Load Balancer pool does not ' + 'exist anymore. Recreating it.', 'Warning') + kubernetes.patch_crd('status', data['selflink'], {}) except k_exc.K8sResourceNotFound: LOG.debug('Unable to reconcile the KuryLoadBalancer CRD %s', diff --git a/kuryr_kubernetes/tests/unit/controller/handlers/test_loadbalancer.py b/kuryr_kubernetes/tests/unit/controller/handlers/test_loadbalancer.py index 3828a2767..e8275ee42 100755 --- a/kuryr_kubernetes/tests/unit/controller/handlers/test_loadbalancer.py +++ b/kuryr_kubernetes/tests/unit/controller/handlers/test_loadbalancer.py @@ -177,6 +177,16 @@ def get_lb_crds(): ], "subnet_id": "123456789120" }, + "pools": [ + { + "id": "1234567890", + "listener_id": "012345678912", + "loadbalancer_id": "01234567890", + "name": "default/test:TCP:80", + "project_id": "12345678912", + "protocol": "TCP" + } + ], } }, { @@ -217,6 +227,17 @@ def get_lb_crds(): ], "subnet_id": "123456789120" }, + "pools": [ + { + "id": "1234567891", + "listener_id": "012345678913", + "loadbalancer_id": "01234567891", + "name": "default/test:TCP:80", + "project_id": "12345678912", + "protocol": "TCP" + } + ], + } } ] @@ -617,6 +638,7 @@ class TestKuryrLoadBalancerHandler(test_base.TestCase): lbaas = self.useFixture(k_fix.MockLBaaSClient()).client lbaas.load_balancers.return_value = [] lbaas.listeners.return_value = [] + lbaas.pools.return_value = [] selflink = ('/apis/openstack.org/v1/namespaces/default/' 'kuryrloadbalancers/test') m_get_res_link.return_value = selflink @@ -640,9 +662,10 @@ class TestKuryrLoadBalancerHandler(test_base.TestCase): loadbalancers_id = [{'id': '01234567890'}, {'id': '01234567891'}] listeners_id = [{'id': '012345678912'}, {'id': '012345678913'}] - + pools_id = [{'id': '1234567890'}, {'id': '1234567891'}] lbaas.load_balancers.return_value = loadbalancers_id lbaas.listeners.return_value = listeners_id + lbaas.pools.return_value = pools_id h_lb.KuryrLoadBalancerHandler._trigger_reconciliation( m_handler, loadbalancer_crds)