// Module included in the following assemblies:
//
// assembly-using-the-topic-operator.adoc

[id='con-deleting-managed-topics-{context}']
= Deleting managed topics

[role="_abstract"]
Unidirectional topic management supports the deletion of topics managed through the `KafkaTopic` resource with or without Kubernetes finalizers.
This is determined by the `STRIMZI_USE_FINALIZERS` Topic Operator environment variable.
By default, this is set to `true`, though it can be set to `false` in the Topic Operator `env` configuration if you do not want the Topic Operator to add finalizers.

Finalizers ensure orderly and controlled deletion of `KafkaTopic` resources.
A finalizer for the Topic Operator is added to the metadata of the `KafkaTopic` resource:

.Finalizer to control topic deletion
[source,shell,subs="+attributes"]
----
apiVersion: {KafkaTopicApiVersion}
kind: KafkaTopic
metadata:
  generation: 1
  name: my-topic-1
  finalizers: 
    - strimzi.io/topic-operator
  labels:
    strimzi.io/cluster: my-cluster
----

In this example, the finalizer is added for topic `my-topic-1`.
The finalizer prevents the topic from being fully deleted until the finalization process is complete.
If you then delete the topic using `kubectl delete kafkatopic my-topic-1`, a timestamp is added to the metadata:

.Finalizer timestamp on deletion
[source,shell,subs="+attributes"]
----
apiVersion: {KafkaTopicApiVersion}
kind: KafkaTopic
metadata:
  generation: 1
  name: my-topic-1
  finalizers: 
    - strimzi.io/topic-operator
  labels:
    strimzi.io/cluster: my-cluster
  deletionTimestamp: 20230301T000000.000  
----

The resource is still present.
If the deletion fails, it is shown in the status of the resource.

When the finalization tasks are successfully executed, the finalizer is removed from the metadata, and the resource is fully deleted.  

Finalizers also serve to prevent related resources from being deleted. 
If the unidirectional Topic Operator is not running, it won't be able to remove its finalizer from the `metadata.finalizers`. 
And any attempt to directly delete the `KafkaTopic` resources or the namespace will fail or timeout, leaving the namespace in a stuck terminating state.
If this happens, you can bypass the finalization process by xref:con-removing-topic-finalizers-{context}[removing the finalizers on topics]. 