Ensure SG is only deleted in case it's present in the KuryrNet CRD

In case Namespace Isolation is not enforced no SG is created and
added to the KuryrNet CRD. Right now, when an exception occurred
on the KuryrNet CRD addition, we try to delete a SG that was not
created.
This commit fixes the issue by checking for the existence of the
sgID in the CRD pior to deleting it.

Change-Id: I4ad3886398138d9a4a8e483b66b3573200002a0c
Closes-Bug: 1841765
This commit is contained in:
Maysa Macedo 2019-08-28 13:37:45 +02:00
parent b6facd57e6
commit ae98963bb2
1 changed files with 2 additions and 1 deletions

View File

@ -117,7 +117,8 @@ class NamespaceHandler(k8s_base.ResourceEventHandler):
LOG.exception("Kubernetes client exception. Rolling back "
"resources created for the namespace.")
self._drv_subnets.rollback_network_resources(net_crd_spec, ns_name)
self._drv_sg.delete_sg(net_crd_sg['sgId'])
if net_crd_sg.get('sgId'):
self._drv_sg.delete_sg(net_crd_sg['sgId'])
self._del_kuryrnet_crd(net_crd_name)
def on_deleted(self, namespace, net_crd=None):