Browse Source

Ensure kuryr-controller recover from lb in ERROR status

This patch ensures kuryr controller can recover from the situation
when the created lb goes into ERROR status (instead of ACTIVE). Now,
when the kuryr-controller finds the created lb, it checks its
provisioning_status and if in ERROR status it will delete it and
ensure a ResourceNotReady exception is triggered so that a new
creation action is triggered after the deletion of the lb in ERROR
status.

Closes-Bug: 1815880
Change-Id: I3f5de710a5ff37dee05f5f8826cb37c343141a08
Luis Tomas Bolivar 2 months ago
parent
commit
33594b8702

+ 6
- 0
kuryr_kubernetes/controller/drivers/lbaasv2.py View File

@@ -74,6 +74,8 @@ class LBaaSv2Driver(base.LBaaSDriver):
74 74
         if not response:
75 75
             # NOTE(ivc): load balancer was present before 'create', but got
76 76
             # deleted externally between 'create' and 'find'
77
+            # NOTE(ltomasbo): or it is in ERROR status, so we deleted and
78
+            # trigger the retry
77 79
             raise k_exc.ResourceNotReady(request)
78 80
 
79 81
         return response
@@ -521,6 +523,10 @@ class LBaaSv2Driver(base.LBaaSDriver):
521 523
             loadbalancer.id = response['loadbalancers'][0]['id']
522 524
             loadbalancer.port_id = self._get_vip_port(loadbalancer).get("id")
523 525
             loadbalancer.provider = response['loadbalancers'][0]['provider']
526
+            if (response['loadbalancers'][0]['provisioning_status'] ==
527
+                    'ERROR'):
528
+                self.release_loadbalancer(loadbalancer)
529
+                return None
524 530
         except (KeyError, IndexError):
525 531
             return None
526 532
 

+ 27
- 1
kuryr_kubernetes/tests/unit/controller/drivers/test_lbaasv2.py View File

@@ -343,7 +343,8 @@ class TestLBaaSv2Driver(test_base.TestCase):
343 343
             provider='haproxy', security_groups=[])
344 344
         loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
345 345
         resp = {'loadbalancers': [{'id': loadbalancer_id,
346
-                                   'provider': 'haproxy'}]}
346
+                                   'provider': 'haproxy',
347
+                                   'provisioning_status': 'ACTIVE'}]}
347 348
         lbaas.list_loadbalancers.return_value = resp
348 349
         m_driver._get_vip_port.return_value = {'id': mock.sentinel.port_id}
349 350
 
@@ -357,6 +358,7 @@ class TestLBaaSv2Driver(test_base.TestCase):
357 358
             self.assertEqual(getattr(loadbalancer, attr),
358 359
                              getattr(ret, attr))
359 360
         self.assertEqual(loadbalancer_id, ret.id)
361
+        m_driver.release_loadbalancer.assert_not_called()
360 362
 
361 363
     def test_find_loadbalancer_not_found(self):
362 364
         lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
@@ -375,6 +377,30 @@ class TestLBaaSv2Driver(test_base.TestCase):
375 377
             vip_address=str(loadbalancer.ip),
376 378
             vip_subnet_id=loadbalancer.subnet_id)
377 379
         self.assertIsNone(ret)
380
+        m_driver.release_loadbalancer.assert_not_called()
381
+
382
+    def test_find_loadbalancer_error(self):
383
+        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
384
+        cls = d_lbaasv2.LBaaSv2Driver
385
+        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
386
+        loadbalancer = obj_lbaas.LBaaSLoadBalancer(
387
+            name='TEST_NAME', project_id='TEST_PROJECT', ip='1.2.3.4',
388
+            subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1')
389
+        loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
390
+        resp = {'loadbalancers': [{'id': loadbalancer_id,
391
+                                   'provider': 'haproxy',
392
+                                   'provisioning_status': 'ERROR'}]}
393
+        lbaas.list_loadbalancers.return_value = resp
394
+        m_driver._get_vip_port.return_value = {'id': mock.sentinel.port_id}
395
+
396
+        ret = cls._find_loadbalancer(m_driver, loadbalancer)
397
+        lbaas.list_loadbalancers.assert_called_once_with(
398
+            name=loadbalancer.name,
399
+            project_id=loadbalancer.project_id,
400
+            vip_address=str(loadbalancer.ip),
401
+            vip_subnet_id=loadbalancer.subnet_id)
402
+        self.assertIsNone(ret)
403
+        m_driver.release_loadbalancer.assert_called_once()
378 404
 
379 405
     def test_create_listener(self):
380 406
         lbaas = self.useFixture(k_fix.MockLBaaSClient()).client

Loading…
Cancel
Save