Skip to content

Commit

Permalink
fix: clean-up cluster on failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaser committed Nov 9, 2022
1 parent 7dc615f commit b2f0d9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions magnum_cluster_api/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def update_cluster_status(self, context, cluster, use_admin_ctx=False):
# TODO: watch for topology change instead
osc = clients.get_openstack_api(context)

capi_cluster = resources.Cluster(context, self.k8s_api, cluster).get_object()
capi_cluster = resources.Cluster(context, self.k8s_api, cluster).get_or_none()

if cluster.status in (
"CREATE_IN_PROGRESS",
Expand Down Expand Up @@ -105,7 +105,7 @@ def update_cluster_status(self, context, cluster, use_admin_ctx=False):
cluster.save()

if cluster.status == "DELETE_IN_PROGRESS":
if capi_cluster.exists():
if capi_cluster and capi_cluster.exists():
return

# NOTE(mnaser): We delete the application credentials at this stage
Expand Down
11 changes: 6 additions & 5 deletions magnum_cluster_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,11 @@ def labels(self) -> dict:

return {**super().labels, **labels}

def get_or_none(self) -> objects.Cluster:
return objects.Cluster.objects(self.api, namespace="magnum-system").get_or_none(
name=utils.get_or_generate_cluster_api_name(self.api, self.cluster)
)

def get_object(self) -> objects.Cluster:
return objects.Cluster(
self.api,
Expand Down Expand Up @@ -1355,11 +1360,7 @@ def get_object(self) -> objects.Cluster:
)

def delete(self):
capi_cluster = objects.Cluster.objects(
self.api, namespace="magnum-system"
).get_or_none(
name=utils.get_or_generate_cluster_api_name(self.api, self.cluster)
)
capi_cluster = self.get_or_none()
if capi_cluster:
capi_cluster.delete()

Expand Down

0 comments on commit b2f0d9e

Please sign in to comment.