Skip to content

Conversation

@nmarukovich
Copy link
Contributor

@nmarukovich nmarukovich commented Oct 31, 2025

PR provides the automatic deletion aks resources based on tags.
To use this script for your aks cluster please add tags during cluster creation:
--tags team=cloud delete-cluster-after-hours=1 creation-time=$(date -u +%s)

@nmarukovich nmarukovich marked this pull request as ready for review November 2, 2025 20:12
…rcona-Lab/jenkins-pipelines into K8SPXC-1650_delete_resources_in_azure
@nmarukovich nmarukovich requested a review from gkech November 5, 2025 11:22
@@ -0,0 +1,7 @@
# To redeploy function run in cmd folder:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add to README where this script will be executed, where to check its logs, how to run it.
From DM: this is the only way to redeploy the functions.
It would be to have here smth like:

  1. The code is deployed and executed at (link)
  2. Logs of execution are (link/how to check if not obvious from the 1st)
  3. The script can not be redeployed/changed through interface. To redeploy download the script (how?) and run below (where?)

@@ -0,0 +1,169 @@
# Remove expired AKS clusters (Azure, cluster-only)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to have for future:

  1. There is a case where the cloud tag is present but the TTL is not correct (creatio time is missing/incorrect format). It would be good to receive a notification about such clusters to recheck why this happens and maybe update scripts corrspondingly.

@nmarukovich nmarukovich requested a review from eleo007 November 27, 2025 08:05
@@ -0,0 +1,14 @@
1. In the Azure portal, search for **Function App** (make sure the subscription is set to **eng-cloud-dev**).
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some intro, like: The cleanup scrips runs in Azure, to check it: do and then the steps

resource_groups_client = ResourceManagementClient(credential, subscription_id)
aks_client = ContainerServiceClient(credential, subscription_id)

logging.info("Searching for AKS clusters to remove.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to ensure consistency, we are using 3 terms for the same thing (remove, delete, terminate) can we stick to just one and apply in the whole file?

logging.info("[DRY-RUN] Would delete cluster %s/%s", rg_name, cluster_name)
return

aks_client.managed_clusters.begin_delete(rg_name, cluster_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems that this method returns https://learn.microsoft.com/en-us/python/api/azure-core/azure.core.polling.lropoller?view=azure-python
Any specific reason to have wait_for_cluster_delete and not use this?
aks_client.managed_clusters.begin_delete(rg_name, cluster_name).result(timeout=300) or
aks_client.managed_clusters.begin_delete(rg_name, cluster_name).wait(timeout=300)

@jvpasinatto jvpasinatto changed the title (K8SPXC-1650 delete resources in azure K8SPXC-1650 delete resources in azure Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants