Pools Reconciliation

The pathset implements the pools reconciliation to
ensure that pools in OpenStack is matching that of
Kubernetes.

Implements: blueprint reconcile-openstack-resources-with-k8s
Change-Id: I433359ec29eadf866a160ab7431184b5b65148d8
This commit is contained in:
Sunday Mgbogu 2022-01-31 20:13:44 +01:00 committed by Maysa Macedo
parent 274c08b71f
commit 7e85dc0f5d
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")
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',

View File

@ -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)