Skip to content

Commit ae5db20

Browse files
authored
fixing destroy ems_on_emr (awslabs#337)
1 parent 09dce90 commit ae5db20

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

plugins/emr_on_eks/emr_on_eks/__init__.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
@hooks.deploy
3434
def deploy(plugin_id: str, context: "Context", team_context: "TeamContext", parameters: Dict[str, Any]) -> None:
35-
_logger.debug("Running hello_world deploy!")
35+
_logger.debug("Running emr_on_eks deploy!")
3636
sh.run(f"echo 'Team name: {team_context.name} | Plugin ID: {plugin_id}'")
3737
cluster_name = f"orbit-{context.name}"
3838
virtual_cluster_name = f"orbit-{context.name}-{team_context.name}"
@@ -84,25 +84,23 @@ def deploy(plugin_id: str, context: "Context", team_context: "TeamContext", para
8484

8585
@hooks.destroy
8686
def destroy(plugin_id: str, context: "Context", team_context: "TeamContext", parameters: Dict[str, Any]) -> None:
87-
_logger.debug("Running hello_world destroy!")
87+
_logger.debug("Running emr_on_eks destroy!")
8888
sh.run(f"echo 'Team name: {team_context.name} | Plugin ID: {plugin_id}'")
8989

9090
virtual_cluster_name = f"orbit-{context.name}-{team_context.name}"
9191
emr = boto3.client("emr-containers")
9292
response = emr.list_virtual_clusters(
9393
containerProviderId=f"orbit-{context.name}", containerProviderType="EKS", maxResults=500
9494
)
95-
if "virtualClusters" not in response or len(response["virtualClusters"]) == 0:
96-
raise Exception("Virtual EMR Cluster not found")
97-
for c in response["virtualClusters"]:
98-
if c["name"] == virtual_cluster_name:
99-
try:
100-
delete_response = emr.delete_virtual_cluster(id=c["id"])
101-
_logger.debug("delete_virtual_cluster:", delete_response)
102-
return
103-
except Exception as e:
104-
_logger.warning(e)
105-
pass
95+
if "virtualClusters" in response:
96+
for c in response["virtualClusters"]:
97+
if c["name"] == virtual_cluster_name:
98+
try:
99+
delete_response = emr.delete_virtual_cluster(id=c["id"])
100+
_logger.debug("delete_virtual_cluster:", delete_response)
101+
except Exception as e:
102+
_logger.warning(e)
103+
pass
106104

107105
cdk_destroy(
108106
stack_name=f"orbit-{context.name}-{team_context.name}-emr-on-eks",

0 commit comments

Comments
 (0)