Browse Source

Fix unused members deletion

Unused members are not being deleted from the pools. This commit
fixes the issue by associating the current target ports with the pool,
and removing the members not presented in these current targets.

Change-Id: I60ce63d2d50daf9a1cea9897dae4926137fc2352
Closes-Bug: #1812370
Maysa Macedo 2 months ago
parent
commit
66faa8a38b
1 changed files with 22 additions and 4 deletions
  1. 22
    4
      kuryr_kubernetes/controller/handlers/lbaas.py

+ 22
- 4
kuryr_kubernetes/controller/handlers/lbaas.py View File

@@ -436,20 +436,38 @@ class LoadBalancerHandler(k8s_base.ResourceEventHandler):
436 436
                 for subnet in network.subnets.objects
437 437
                 if ip in subnet.cidr][0]
438 438
 
439
+    def _get_port_in_pool(self, pool, lbaas_state, lbaas_spec):
440
+        for l in lbaas_state.listeners:
441
+            if l.id != pool.listener_id:
442
+                continue
443
+            for port in lbaas_spec.ports:
444
+                if l.port == port.port and l.protocol == port.protocol:
445
+                    return port
446
+        return None
447
+
439 448
     def _remove_unused_members(self, endpoints, lbaas_state, lbaas_spec):
440
-        spec_port_names = {p.name for p in lbaas_spec.ports}
441
-        current_targets = {(a['ip'], p['port'])
449
+        spec_ports = {}
450
+        for pool in lbaas_state.pools:
451
+            port = self._get_port_in_pool(pool, lbaas_state, lbaas_spec)
452
+            if port:
453
+                spec_ports[port.name] = pool.id
454
+
455
+        current_targets = {(a['ip'], p['port'],
456
+                            spec_ports.get(p.get('name')))
442 457
                            for s in endpoints['subsets']
443 458
                            for a in s['addresses']
444 459
                            for p in s['ports']
445
-                           if p.get('name') in spec_port_names}
460
+                           if p.get('name') in spec_ports}
461
+
446 462
         removed_ids = set()
447 463
         for member in lbaas_state.members:
448
-            if (str(member.ip), member.port) in current_targets:
464
+            if ((str(member.ip), member.port, member.pool_id) in
465
+                    current_targets):
449 466
                 continue
450 467
             self._drv_lbaas.release_member(lbaas_state.loadbalancer,
451 468
                                            member)
452 469
             removed_ids.add(member.id)
470
+
453 471
         if removed_ids:
454 472
             lbaas_state.members = [m for m in lbaas_state.members
455 473
                                    if m.id not in removed_ids]

Loading…
Cancel
Save