XMC Cleanup Environment
Guides the agent through tearing down an XMC environment deployed via Cluster Toolkit (gcluster) safely.
작성자를 위한 경고
- "name" should use lowercase letters, digits and single hyphens only
- "name" should match the name of the directory that holds SKILL.md
- Not listed through the skills extension: the directory must be named after the skill.
Cleanup XMC Environment Workflow
This skill guides you through destroying an XManager on Cloud (XMC) environment that was deployed using the Cluster Toolkit v2, verifying that all cloud resources are cleaned up to avoid leakages/costs.
[!IMPORTANT] All execution steps in this skill MUST strictly adhere to the policy rules defined in Skills & Automation Guidelines and Core Engineering Standards.
[!WARNING] DESTRUCTIVE WORKFLOW: This cleanup workflow is intended for developer environments. It will permanently delete all deployed cloud resources, including GKE clusters, VPC networks, and all Cloud Spanner databases and backups. Data recovery is not possible.
1. Prerequisites & Context Check
Before starting the teardown, verify you are operating on the correct environment:
- Context Check & Spanner Warning:
- Always explicitly confirm with the user before starting. Use the
ask_questiontool to ask the user to confirm: "Are you sure you want to clean up the environment '<environment_name>'? This will permanently delete the GKE cluster and the Cloud Spanner instance, including all databases and all backups."
- Always explicitly confirm with the user before starting. Use the
- Formulate & Present a Cleanup Plan:
- Check for the deployment directory in the current working directory under
./ctk-out/(e.g.,./ctk-out/my-dev).[!IMPORTANT] Strict Path Lock Policy: You must only look for the
ctk-out/folder in the immediate working directory. Refer to Skills & Automation Guidelines for directory scope restrictions. - If no
./ctk-out/directory exists in your immediate directory, note that no active cloud environment was deployed from this folder and stop execution. - Present a clear plan to the user listing exactly what will be deleted:
- Cloud Spanner: The instance
xmc-<environment>, all databases, and all active backups (backups must be deleted first to allow instance teardown). - GKE Cluster: The GKE cluster and all running applications.
- VPC Network: VPC network, subnetworks, routers, and static IPs.
- Local Config / Deployment Directory (e.g.,
ctk-out/<deployment_name>and Kubeconfig contexts)
- Cloud Spanner: The instance
- Ask for explicit user approval on this plan using the
ask_questiontool before executing any destructive commands.
- Check for the deployment directory in the current working directory under
- Verify Cluster Connection (if cloud cleanup is needed): Run
kubectl get nodesto ensure you are targeting the correct active cluster. - Identify GCP Project (if cloud cleanup is needed): Open the compiled configuration file at
ctk-out/<deployment_name>/primary/terraform.tfvarsto identify the targetproject_id. - Check Deletion Protection (if cloud cleanup is needed):
- Check if
deletion_protection = trueis configured inctk-out/<deployment_name>/primary/terraform.tfvars(or any other*.tfvarsfile in the deployment directory). - If
deletion_protectionis set totrue:- Stop execution and warn the user: "Deletion protection is enabled in this deployment's Terraform state. The standard destroy command will fail. You must either set
deletion_protection: falsein your configuration, run gcluster compile/deploy to apply the change, or manually clean up the protected resources after standard destroy fails." - Ask the user how they wish to proceed. Do not run the destroy command while
deletion_protectionistruewithout explicit user confirmation.
- Stop execution and warn the user: "Deletion protection is enabled in this deployment's Terraform state. The standard destroy command will fail. You must either set
- Check if
2. Teardown Steps
Follow these steps in sequence to perform a clean teardown.
Step 1: Delete Spanner Backups (Mandatory)
Cloud Spanner instances cannot be deleted if they contain active backups. You must delete them before running the destroy command to prevent Terraform failures.
- Identify the Spanner instance name (usually
xmc-<environment>). - List backups:
gcloud spanner backups list --instance=xmc-<environment> --project=<project_id> - Delete each backup found:
gcloud spanner backups delete <backup_id> --instance=xmc-<environment> --project=<project_id> --quiet
Step 2: Run Standard Destroy
Attempt to run the standard Toolkit destroy command:
./cluster-toolkit/gcluster destroy ctk-out/<deployment_name> --auto-approve
Wait until the command completes successfully. If it succeeds, proceed to Step 3 (Delete Cloud DNS Records). If it fails, follow the mitigations in Section 3 (Mitigations for Teardown Failures).
Step 3: Delete Cloud DNS Records (Mandatory for Automated Setup)
The automated deployment script (deploy_dev_env.py) creates Cloud DNS A records using gcloud dns CLI transactions. These are not managed by Terraform. To prevent resource leakage, you must delete them manually after destroying the cluster.
- Identify DNS Configuration:
- Identify the GCP project ID hosting the DNS zone and the Cloud DNS managed zone name.
- If they are not found in the deployment context or config, you MUST stop and ask the user to provide:
- DNS Project ID (the GCP project hosting the DNS zone).
- DNS Managed Zone Name (the name of the Cloud DNS managed zone).
- Inspect active records to find the exact ones to delete:
(Note: If no DNS records matching the environment are found in the list, skip the delete commands below and inform the user that the DNS records were not found.)gcloud dns record-sets list --zone=<dns_zone_name> --project=<dns_project_id> - Delete the records found that are related to the environment we are cleaning up:
gcloud dns record-sets delete <environment>.<domain_name>. --type=A --zone=<dns_zone_name> --project=<dns_project_id> --quiet gcloud dns record-sets delete api.<environment>.<domain_name>. --type=A --zone=<dns_zone_name> --project=<dns_project_id> --quiet gcloud dns record-sets delete grpc.<environment>.<domain_name>. --type=A --zone=<dns_zone_name> --project=<dns_project_id> --quiet
Step 4: Local Configurations & Files Cleanup
- Kubeconfig Contexts: The local kubeconfig will still have the context entry for the deleted cluster. Clean it up:
# Find the context name (which typically matches the cluster name) kubectl config get-contexts -o name | grep "xmc-.*<environment>" # Delete the context and cluster entry kubectl config delete-context <context_name> kubectl config delete-cluster <context_name> - Delete Deployment Folder: Delete the local generated folder:
rm -rf ctk-out/<deployment_name>
3. Mitigations for Teardown Failures
If gcluster destroy gets stuck or fails, use the following workarounds depending on the failure reason:
Scenario A: Helm Timeout / Connection issues in xmc_app
If the destroy gets stuck on the xmc_app group (often due to Helm release deletion timeouts because GKE nodes are scaling down or unreachable), retry skipping xmc_app:
./cluster-toolkit/gcluster destroy ctk-out/<deployment_name> --auto-approve --skip xmc_app
Scenario B: GKE Node Pool stuck in STOPPING state
If the destroy fails because GKE node pools are stuck deleting (which prevents subnetwork deletion):
- Force delete the GKE cluster manually:
gcloud container clusters delete xmc-<deployment_name>-<environment> --location=<location> --project=<project_id> --quiet - Retry destroy skipping both
xmc_appandkubernetes_prereqs(since the cluster is already gone):./cluster-toolkit/gcluster destroy ctk-out/<deployment_name> --auto-approve --skip xmc_app,kubernetes_prereqs
이 스킬의 파일
이 스킬에는 보조 파일이 없습니다.