From d6e5fe9f8305fc813b9d9799a183fb48f5881c5e Mon Sep 17 00:00:00 2001 From: Luis Tomas Bolivar Date: Wed, 4 Sep 2019 11:02:04 +0200 Subject: [PATCH] Ensure conflicts creating subnet from subnetpools are retried If a lot of subnets are created at once, there is a chance that Neutron will get the calls concurrently and fail. Internally Neutron will retry but it may happen that the limit in the number of retries is also hit. Thus this patch ensures that scenario is catched and reacted to. Change-Id: I83d62616835f22e916bfe056e793eb31654be51f --- .../controller/drivers/namespace_subnet.py | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/kuryr_kubernetes/controller/drivers/namespace_subnet.py b/kuryr_kubernetes/controller/drivers/namespace_subnet.py index 392fc6e09..b49a9c6ed 100644 --- a/kuryr_kubernetes/controller/drivers/namespace_subnet.py +++ b/kuryr_kubernetes/controller/drivers/namespace_subnet.py @@ -144,17 +144,23 @@ class NamespacePodSubnetDriver(default_subnet.DefaultPodSubnetDriver): c_utils.tag_neutron_resources('networks', [neutron_net['id']]) # create a subnet within that network - neutron_subnet = neutron.create_subnet( - { - "subnet": { - "network_id": neutron_net['id'], - "ip_version": 4, - "name": subnet_name, - "enable_dhcp": False, - "subnetpool_id": subnet_pool_id, - "project_id": project_id - } - }).get('subnet') + try: + neutron_subnet = neutron.create_subnet( + { + "subnet": { + "network_id": neutron_net['id'], + "ip_version": 4, + "name": subnet_name, + "enable_dhcp": False, + "subnetpool_id": subnet_pool_id, + "project_id": project_id + } + }).get('subnet') + except n_exc.Conflict: + LOG.debug("Max number of retries on neutron side achieved, " + "raising ResourceNotReady to retry subnet creation " + "for %s", subnet_name) + raise exceptions.ResourceNotReady(subnet_name) c_utils.tag_neutron_resources('subnets', [neutron_subnet['id']]) # connect the subnet to the router