Merge "Pools Reconciliation"

This commit is contained in:
Zuul 2022-03-21 19:50:59 +00:00 committed by Gerrit Code Review
commit c8af19ad96
2 changed files with 41 additions and 10 deletions

View File

@ -181,8 +181,9 @@ class KuryrLoadBalancerHandler(k8s_base.ResourceEventHandler):
LOG.debug("Reconciling the KuryrLoadBalancer CRDs") LOG.debug("Reconciling the KuryrLoadBalancer CRDs")
lbaas = clients.get_loadbalancer_client() lbaas = clients.get_loadbalancer_client()
resources_fn = {'loadbalancer': lbaas.load_balancers, resources_fn = {'loadbalancer': lbaas.load_balancers,
'listener': lbaas.listeners} 'listener': lbaas.listeners,
resources = {'loadbalancer': [], 'listener': []} 'pool': lbaas.pools}
resources = {'loadbalancer': [], 'listener': [], 'pool': []}
for klb in loadbalancer_crds: for klb in loadbalancer_crds:
if klb['metadata'].get('deletionTimestamp'): if klb['metadata'].get('deletionTimestamp'):
@ -200,10 +201,15 @@ class KuryrLoadBalancerHandler(k8s_base.ResourceEventHandler):
resources['listener'].append({'id': lbl['id'], resources['listener'].append({'id': lbl['id'],
'selflink': selflink, 'selflink': selflink,
'lklb': klb}) 'lklb': klb})
for pl in klb.get('status', {}).get('pools', []):
resources['pool'].append({'id': pl['id'],
'selflink': selflink,
'pklb': klb})
resources_already_triggered = [] resources_already_triggered = []
# let's reconcile load balancers first, and than listeners # let's reconcile load balancers first, listeners and then pools
for resource_type in ('loadbalancer', 'listener'): resource_types = ('loadbalancer', 'listener', 'pool')
for resource_type in resource_types:
filters = {} filters = {}
self._drv_lbaas.add_tags(resource_type, filters) self._drv_lbaas.add_tags(resource_type, filters)
os_list = resources_fn[resource_type] os_list = resources_fn[resource_type]
@ -223,13 +229,15 @@ class KuryrLoadBalancerHandler(k8s_base.ResourceEventHandler):
try: try:
if data.get('klb'): if data.get('klb'):
self._add_event(data['klb'], 'LoadBalancerRecreating', 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') 'exist anymore. Recreating it.', 'Warning')
if data.get('lklb'): if data.get('lklb'):
self._add_event(data['lklb'], 'LoadBalancerRecreating', self._add_event(data['lklb'], 'Load Balancer listener does not'
'Listener of load balancer for the Service ' ' exist anymore. Recreating it.', 'Warning')
'seems to not exist anymore. Recreating it.', if data.get('pklb'):
'Warning') self._add_event(data['pklb'], 'Load Balancer pool does not '
'exist anymore. Recreating it.', 'Warning')
kubernetes.patch_crd('status', data['selflink'], {}) kubernetes.patch_crd('status', data['selflink'], {})
except k_exc.K8sResourceNotFound: except k_exc.K8sResourceNotFound:
LOG.debug('Unable to reconcile the KuryLoadBalancer CRD %s', LOG.debug('Unable to reconcile the KuryLoadBalancer CRD %s',

View File

@ -177,6 +177,16 @@ def get_lb_crds():
], ],
"subnet_id": "123456789120" "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" "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 = self.useFixture(k_fix.MockLBaaSClient()).client
lbaas.load_balancers.return_value = [] lbaas.load_balancers.return_value = []
lbaas.listeners.return_value = [] lbaas.listeners.return_value = []
lbaas.pools.return_value = []
selflink = ('/apis/openstack.org/v1/namespaces/default/' selflink = ('/apis/openstack.org/v1/namespaces/default/'
'kuryrloadbalancers/test') 'kuryrloadbalancers/test')
m_get_res_link.return_value = selflink m_get_res_link.return_value = selflink
@ -640,9 +662,10 @@ class TestKuryrLoadBalancerHandler(test_base.TestCase):
loadbalancers_id = [{'id': '01234567890'}, {'id': '01234567891'}] loadbalancers_id = [{'id': '01234567890'}, {'id': '01234567891'}]
listeners_id = [{'id': '012345678912'}, {'id': '012345678913'}] listeners_id = [{'id': '012345678912'}, {'id': '012345678913'}]
pools_id = [{'id': '1234567890'}, {'id': '1234567891'}]
lbaas.load_balancers.return_value = loadbalancers_id lbaas.load_balancers.return_value = loadbalancers_id
lbaas.listeners.return_value = listeners_id lbaas.listeners.return_value = listeners_id
lbaas.pools.return_value = pools_id
h_lb.KuryrLoadBalancerHandler._trigger_reconciliation( h_lb.KuryrLoadBalancerHandler._trigger_reconciliation(
m_handler, loadbalancer_crds) m_handler, loadbalancer_crds)