Skip to content

Commit 4879f4d

Browse files
committed
Make get cluster more robust
1 parent 47fe401 commit 4879f4d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

hpc_provisioner/src/hpc_provisioner/handlers.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
ClusterAlreadyRegistered,
2828
delete_cluster,
2929
dynamodb_resource,
30+
get_cluster_by_name,
3031
get_unclaimed_clusters,
3132
register_cluster,
3233
)
@@ -220,11 +221,24 @@ def pcluster_describe_handler(event, _context=None):
220221
else:
221222
logger.debug(f"describe pcluster {cluster}")
222223
try:
223-
pc_output = pcluster_describe(cluster)
224-
pc_output.update(
225-
get_secrets_for_cluster(sm_client=sm_client, cluster_name=cluster.name)
224+
dynamo_output = get_cluster_by_name(
225+
dynamodb_resource=dynamodb_resource(), cluster_name=cluster.name
226226
)
227-
logger.debug(f"described pcluster {cluster}")
227+
if dynamo_output and dynamo_output.get("provisioning_launched", 0) == 0:
228+
cluster_from_dynamo = Cluster.from_dynamo_dict(dynamo_output)
229+
pc_output = cluster_from_dynamo.as_dict()
230+
cluster_secrets = get_secrets_for_cluster(
231+
sm_client=sm_client, cluster_name=cluster_from_dynamo.name
232+
)
233+
pc_output.update(cluster_secrets)
234+
235+
else:
236+
pc_output = pcluster_describe(cluster)
237+
pc_output.update(
238+
get_secrets_for_cluster(sm_client=sm_client, cluster_name=cluster.name)
239+
)
240+
logger.debug(f"described pcluster {cluster}")
241+
228242
except NotFoundException as e:
229243
return {"statusCode": 404, "body": e.content.message}
230244
except Exception as e:

0 commit comments

Comments
 (0)