Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/connectedk8s/azext_connectedk8s/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ def validate_connect_rp_location(cmd: CLICommand, location: str) -> None:
"Failed to fetch resource provider details",
)

for resourceTypes in providerDetails.resource_types: # type: ignore[attr-defined]
for resourceTypes in providerDetails.resource_types or []:
if resourceTypes.resource_type == "connectedClusters":
rp_locations = [
location.replace(" ", "").lower()
for location in resourceTypes.locations
for location in (resourceTypes.locations or [])
]
if location.lower() not in rp_locations:
telemetry.set_exception(
Expand Down
41 changes: 29 additions & 12 deletions src/connectedk8s/azext_connectedk8s/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1886,9 +1886,23 @@ def delete_connectedk8s(
logger.warning("This operation might take a while ...\n")

# Check if the cluster is of supported type for deletion
cluster_resource = client.get(resource_group_name, cluster_name)
if (cluster_resource.kind is not None) and (
cluster_resource.kind.lower() == consts.Provisioned_Cluster_Kind
cluster_resource = None
try:
cluster_resource = client.get(resource_group_name, cluster_name)
except HttpResponseError as ex:
# If the resource group or cluster resource is not found, proceed with local cleanup
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to check if the resource group and resource name tallies with the one being deleted. I dont see the check , can you please add or point me to it ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error check is only for handling ARM call failing, the delete flow still remains the same.

The existing resource check:
https://github.com/AzureArcForKubernetes/connectedk8s/blob/main/src/connectedk8s/azext_connectedk8s/custom.py#L1984

if ex.error and ex.error.code in ("ResourceGroupNotFound", "ResourceNotFound"):
logger.warning(
"Could not find the Azure resource (resource group or cluster may have been deleted). "
"Proceeding with local cleanup."
)
else:
raise

if (
cluster_resource is not None
and (cluster_resource.kind is not None)
and (cluster_resource.kind.lower() == consts.Provisioned_Cluster_Kind)
):
err_msg = (
"Deleting a Provisioned Cluster is not supported from the Connected Cluster CLI. Please use the "
Expand Down Expand Up @@ -1929,9 +1943,10 @@ def delete_connectedk8s(
print(f"Step: {utils.get_utctimestring()}: Performing Force Delete")
kubectl_client_location = install_kubectl_client()

delete_cc_resource(
client, resource_group_name, cluster_name, no_wait, force=force_delete
).result()
if cluster_resource is not None:
delete_cc_resource(
client, resource_group_name, cluster_name, no_wait, force=force_delete
).result()

# Explicit CRD Deletion
crd_cleanup_force_delete(
Expand All @@ -1951,9 +1966,10 @@ def delete_connectedk8s(
return

if not release_namespace:
delete_cc_resource(
client, resource_group_name, cluster_name, no_wait, force=force_delete
).result()
if cluster_resource is not None:
delete_cc_resource(
client, resource_group_name, cluster_name, no_wait, force=force_delete
).result()
return

# Loading config map
Expand Down Expand Up @@ -2004,9 +2020,10 @@ def delete_connectedk8s(
recommendation=reco_str,
)

delete_cc_resource(
client, resource_group_name, cluster_name, no_wait, force=force_delete
).result()
if cluster_resource is not None:
delete_cc_resource(
client, resource_group_name, cluster_name, no_wait, force=force_delete
).result()
else:
telemetry.set_exception(
exception="Unable to delete connected cluster",
Expand Down
Loading