> For the complete documentation index, see [llms.txt](https://experience-digital-transform.gitbook.io/experience-digital-transformation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://experience-digital-transform.gitbook.io/experience-digital-transformation/cloud-for-dpi/chapter-4/cleanup-remove-resources-through-their-owner.md).

# Cleanup: remove resources through their owner

Several controllers now hold desired state, so cleanup begins by stopping those reconciliation loops. The approved configuration revision first removes the two child declarations. The workload ApplicationSet and lifecycle Application are then removed from Argo CD, leaving the live CAPI objects in place because pruning is disabled.

Child registrations are removed while both APIs still respond. Only then are the stable OpenStack compute, port, volume and API-load-balancer IDs captured and the owning CAPI Cluster objects deleted:

```bash
# Remove Git intent and stop Argo CD before deleting CAPI-owned clusters.
git -C "$CONFIG_REPO" rm \
  clusters/service-a*.yaml clusters/loadbalancer*.yaml
kubectl --kubeconfig "$KUBECONFIG" -n argocd \
  delete applicationset/registered-workload-clusters --cascade=orphan
kubectl --kubeconfig "$KUBECONFIG" -n argocd \
  delete application/service-a-workload-demo --cascade=orphan --ignore-not-found
kubectl --kubeconfig "$KUBECONFIG" -n argocd \
  delete application/child-cluster-lifecycle --cascade=orphan

# Capture stable IDs, then let CAPI remove the complete ownership chain.
python3 scripts/capture-openstack-ids.py \
  "$KUBECONFIG" "$MANAGEMENT_CONTEXT" \
  service-a service-a "$OS_CLOUD" evidence/service-a-resource-ids.json
CONFIRM_MANAGEMENT_CONTEXT="$MANAGEMENT_CONTEXT" CONFIRM_DELETE_CLUSTER=service-a/service-a \
  ./scripts/cleanup.sh "$KUBECONFIG" "$MANAGEMENT_CONTEXT" \
  service-a service-a evidence/service-a-resource-ids.json "$OS_CLOUD"

# Remove the management-side add-on objects after the child has gone.
kubectl --kubeconfig "$KUBECONFIG" delete \
  -f rendered/addons/service-a-cert-manager.yaml \
  -f rendered/addons/service-a-contour.yaml \
  -f rendered/addons/service-a-storage.yaml --ignore-not-found
```

Representative success output:

```
cluster service-a/service-a is absent from the management API
all captured OpenStack resource IDs are absent
clusterresourceset.cluster.x-k8s.io "service-a-cert-manager" deleted
```

The cleanup helper waits for the Cluster object to disappear and queries every captured OpenStack ID. Shared networks, security groups, key pairs and credential inputs remain because the child Cluster objects do not own them. The Management cluster and its OpenTofu state stay available until every child deletion and absence check succeeds.

[Walkthrough 9: Cleanup](https://git.vanillacore.net/giga/content/src/branch/main/chapter-4/lab/walkthroughs/09-cleanup.md) contains the approved-revision guard, Argo CD unregister sequence, both child clusters and bounded absence checks. [C4-P9](https://git.vanillacore.net/giga/content/src/branch/main/chapter-4/VIDEO_SCOPES.md#c4-p9-cleanup-stop-reconciliation-and-delete-through-the-owner) shows the order from Git change to verified infrastructure absence.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://experience-digital-transform.gitbook.io/experience-digital-transformation/cloud-for-dpi/chapter-4/cleanup-remove-resources-through-their-owner.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
