---
# System prepended metadata

title: Purging(Force Deletion) of Shoot cluster
tags: ['#purge', '#forcedeletion', '#zonecontroller']

---

# Purging(Force Deletion) of Shoot cluster

**Issue** - https://github.com/gardener/gardener/issues/3110

**Task** - https://github.com/gardener/gardener/issues/3110#issuecomment-1705500823

Can get some motivation from - https://github.com/gardener/gardener/pull/5150

**Working branch** - https://github.com/acumino/gardener/tree/purge-shoot

**Final PR** - https://github.com/gardener/gardener/pull/8414




<hr>

First meeting with Vedran and Rafael

- Try Normal cluster deletion
    - If not Purge forcefully
- Purge only if cluster is in failed delete state
- Error code is there then only delete the cluster
<hr>

**IDEATION** - 
- How about start if only there is error code which says there is user error code? **YES** :heavy_check_mark:
- Don't allow purge for workerless :heavy_check_mark:
- Should we store the terraform state somewhere - 
  - Sync with Kon :hourglass:
- Hibernated cluster vs Not Hibernated cluster.
  - Nothing special done should be fine. :hourglass:
  - Fully hibernated (No CP) :hourglass:
    - Can't happen (Purge is not needed as we only purge if deletion timestamp is set and we wake up the CP if deletion time stamp is set on shoot. and it is case 3)
  - Hibernating and stuck :hourglass:
  - Waking up and stuck :hourglass:
  - Not hibernated - 
    - Deleting -
      - We only deal with shoot with error codes :heavy_check_mark:
    - Normal - 
      - Don't do anything (Can't purge cluster if not already marked for deletion) :heavy_check_mark:

 - Don't allow purge for migrating/restoring shoot.


<hr>


## Task:

### Gardener:
- [x] Introduce annnotation for `confirmation.gardener.cloud/force-deletion=true` for force deletion
- [x] Add validation that shoot with only deletion time stamp and error codes can be purged
  - Error code allowed for purging
    - ERR_CLEANUP_CLUSTER_RESOURCES
    - ERR_CONFIGURATION_PROBLEM
    - ERR_INFRA_DEPENDENCIES
    - ERR_INFRA_UNAUTHENTICATED
    - ERR_INFRA_UNAUTHORIZED
- [x] Add validation that `confirmation.gardener.cloud/force-deletion=true` cannot be removed
- [x]  check if the cluster can be present extensions list.
- [x]  Keep only `secrets` in the kubernetes list.
- [x] use `DestroyETCD` method instead of `DeleteEtcd` function.
- [x] Seprate seed and shoot managed resource deletion.
- [x] Remove `kubernetesutils.SetMetaDataAnnotation(obj, v1beta1constants.AnnotationConfirmationForceDeletion, "true")` annotation. We should depend upon cluster object to check if the shoot has the forcedeletion annotation set and hence the worker controller should take the `forcedeletion` flow to delete the worker.
- [x] Above point means we don't need `func ConfirmForceDeletion(ctx context.Context, w client.Writer, obj client.Object)` function.
- [x] Add a helper function `IsForceDeletion` to check if the annotation is present.
- [x] Add feature gate as changes are dependent on providers.
- [x] Increase shoot generation on adding force-delete annotation (This is necessary as shoot in failed state should instantenly reconciled.) 
- [x] Disable `ShootForceDeletion` plugin in local setup (So we test whole flow).
- [x] Add e2e test
- [x] Add Docs

### Extensions:
There are resources(e.g. - `Machine`, `MachineSet` etc.) for which Gardenlet doesn't have deletion access and we also don't want to allow that permission just for supporting forceful deletion other than that there are resources that are deployed by provider-extensions about which gardener doesn't have any knowledge. 
In case of forceful deletion provider extension should take care of the above responsibility.
  - [x] provider-alicloud ,  released with [`?`](https://github.com/gardener/gardener-extension-provider-alicloud/releases/tag/?)
  - [x] provider-aws ,  released with [`?`](https://github.com/gardener/gardener-extension-provider-aws/releases/tag/?)
  - [x] provider-azure , released with [`?`](https://github.com/gardener/gardener-extension-provider-azure/releases/tag/?)
  - [x] provider-gcp , released with [`?`](https://github.com/gardener/gardener-extension-provider-gcp/releases/tag/?)
  - [x] provider-openstack , released with [`?`](https://github.com/gardener/gardener-extension-provider-openstack/releases/tag/?)
  - [x] provider-vsphere , released with [`?`](https://github.com/gardener/gardener-extension-provider-vsphere/releases/tag/?)
  - [x] provider-equinix-metal , released with [`?`](https://github.com/gardener/gardener-extension-provider-equinix-metal/releases/tag/?)

<hr>

#### Not Sure

Addon nginx - load balancer - (What if this gets into error state or can it be) - (Should be a concern as it get created using user secret and no issues be leaked)