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

[id='proc-converting-managed-topics-{context}']
= Managing KafkaTopic resources without impacting Kafka topics

[role="_abstract"]
This procedure describes how to convert Kafka topics that are currently managed through the `KafkaTopic` resource into unmanaged topics.
This capability can be useful in various scenarios. 
For instance, you might want to update the `metadata.name` of a `KafkaTopic` resource.
You can only do that by deleting the original `KafkaTopic` resource and recreating a new one.

By annotating a `KafkaTopic` resource with `strimzi.io/managed=false`, you indicate that the Topic Operator should no longer manage that particular topic. 
This allows you to retain the Kafka topic while making changes to the resource's configuration or other administrative tasks.

.Prerequisites

* xref:deploying-cluster-operator-str[The Cluster Operator must be deployed.]

.Procedure

. Annotate the `KafkaTopic` resource in Kubernetes, setting `strimzi.io/managed` to `false`:
+
[source,shell,subs="+quotes"]
----
kubectl annotate kafkatopic my-topic-1 strimzi.io/managed="false" --overwrite
----
+
Specify the `metadata.name` of the topic in your `KafkaTopic` resource, which is `my-topic-1` in this example.

. Check the status of the `KafkaTopic` resource to make sure the request was successful:
+
[source,shell,subs="+quotes"]
----
kubectl get kafkatopic my-topic-1 -o yaml
----
+
.Example topic with an `Unmanaged` status
[source,shell,subs="+attributes"]
----
apiVersion: {KafkaTopicApiVersion}
kind: KafkaTopic
metadata:
  generation: 124
  name: my-topic-1
  finalizer: 
  - strimzi.io/topic-operator
  labels:
    strimzi.io/cluster: my-cluster
  annotations:
    strimzi.io/managed: "false"
spec:
  partitions: 10
  replicas: 2
  config:
    retention.ms: 432000000
status: 
  observedGeneration: 124 # <1>
  conditions:
  - lastTransitionTime: "2024-08-22T06:07:57.671085635Z"
    status: "True"
    type: Unmanaged # <2>
----
<1> The value of `metadata.generation` must `match status.observedGeneration`.
<2> The `Unmanaged` condition means that the `KafkaTopic` is no longer reconciled.

. You can now make changes to the `KafkaTopic` resource without it affecting the Kafka topic it was managing.
+
For example, to change the `metadata.name`, do as follows:
+
.. Delete the original `KafkaTopic` resource:
+
[source,shell,subs="+quotes"]
----
kubectl delete kafkatopic <kafka_topic_name>
----
.. Recreate the `KafkaTopic` resource with a different `metadata.name`, but use `spec.topicName` to refer to the same topic that was managed by the original

. If you haven't deleted the original `KafkaTopic` resource, and you wish to resume management of the Kafka topic again, set the `strimzi.io/managed` annotation to `true` or remove the annotation.