Skip to content

Commit

Permalink
improve destroy rosa hcp cluster (#11005)
Browse files Browse the repository at this point in the history
* add func to destroy rosa cluster

Signed-off-by: Daniel Osypenko <[email protected]>
  • Loading branch information
DanielOsypenko authored Dec 13, 2024
1 parent d29c56c commit 09ac71c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ocs_ci/deployment/rosa.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
get_associated_oidc_config_id,
delete_account_roles,
wait_console_url,
destroy_rosa_cluster,
)
from ocs_ci.utility.utils import (
ceph_health_check,
Expand Down Expand Up @@ -154,7 +155,10 @@ def destroy(self, log_level="DEBUG"):
log_step(f"Destroying ROSA cluster. Hosted CP: {rosa_hcp}")
delete_status = rosa.destroy_appliance_mode_cluster(self.cluster_name)
if not delete_status:
ocm.destroy_cluster(self.cluster_name)
if rosa_hcp:
destroy_rosa_cluster(self.cluster_name)
else:
ocm.destroy_cluster(self.cluster_name)
log_step("Waiting for ROSA cluster to be uninstalled")
sample = TimeoutSampler(
timeout=14400,
Expand Down
18 changes: 18 additions & 0 deletions ocs_ci/utility/rosa.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
generate_onboarding_token,
get_storage_provider_endpoint,
)
from ocs_ci.utility.openshift_dedicated import get_cluster_details
from ocs_ci.utility.retry import catch_exceptions
from ocs_ci.utility.utils import exec_cmd, TimeoutSampler

Expand Down Expand Up @@ -894,6 +895,23 @@ def destroy_appliance_mode_cluster(cluster):
return True


def destroy_rosa_cluster(cluster, best_effort=True):
"""
Delete rosa cluster
Parameters:
cluster (str): name of the cluster
best_effort (bool): If True (true), ignore errors and continue with the deletion of the cluster
"""
external_id = get_cluster_details(cluster)["id"]
cmd = f"ocm delete cluster {external_id} -p best_effort={str(best_effort).lower()}"
proc = exec_cmd(cmd, timeout=1200)
if proc.returncode != 0:
raise CommandFailed(f"Failed to delete cluster: {proc.stderr.decode().strip()}")
logger.info(f"{proc.stdout.decode().strip()}")
return True


def delete_oidc_provider(cluster_name):
"""
Delete oidc provider of the given cluster
Expand Down

0 comments on commit 09ac71c

Please sign in to comment.