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

[id='proc-changing-topic-operator-mode-{context}']
= Switching between Topic Operator modes

[role="_abstract"]
You can switch between topic management modes when upgrading or downgrading Strimzi, or when using the same version of Strimzi, as long as the mode is supported for that version. 

.Switching from bidirectional to unidirectional topic management mode

. xref:ref-operator-unidirectional-topic-operator-feature-gate-str[Enable the `UnidirectionalTopicOperator` feature gate]. 
+
The Cluster Operator deploys the Entity Operator with the Topic Operator in unidirectional topic management mode.

. The internal topics that support the Topic Operator running in bidirectional topic management mode are no longer required, so you can delete the `KafkaTopic` resources to manage them:
+
[source,shell,subs=+quotes]
----
kubectl delete $(kubectl get kt -n <namespace_name> -o name | grep strimzi-store-topic) \
  && kubectl delete $(kubectl get kt -n <namespace_name> -o name | grep strimzi-topic-operator)
---- 
+
This command deletes the internal topics, which have names starting `strimzi-store-topic` and `strimzi-topic-operator`.

. The internal topics for storing consumer offsets and transaction states must be retained in Kafka. So, you must first discontinue their management by the Topic Operator before deleting the `KafkaTopic` resources.  
+
.. Discontinue management of the topics:
+
[source,shell,subs=+quotes]
----
kubectl annotate $(kubectl get kt -n <namespace_name> -o name | grep consumer-offsets) strimzi.io/managed="false" \
  && kubectl annotate $(kubectl get kt -n <namespace_name> -o name | grep transaction-state) strimzi.io/managed="false"
----
+
By annotating the `KafkaTopic` resources with `strimzi.io/managed="false"`, you indicate that the Topic Operator should no longer manage those topics. 
In this case, we are adding the annotation to resources for managing the internal topics with names starting `consumer-offsets` and `transaction-state`.
+
.. When their management is discontinued, delete the `KafkaTopic` resources (without deleting the topics inside Kafka):
+
[source,shell,subs=+quotes]
----
kubectl delete $(kubectl get kt -n <namespace_name> -o name | grep consumer-offsets) \
  && kubectl delete $(kubectl get kt -n <namespace_name> -o name | grep transaction-state)
---- 

.Switching from unidirectional to bidirectional topic management mode

. xref:ref-operator-unidirectional-topic-operator-feature-gate-str[Disable the `UnidirectionalTopicOperator` feature gate].
+
The Cluster Operator deploys the Entity Operator with the Topic Operator in bidirectional topic management mode.
+
The internal topics required by the Topic Operator running in bidirectional topic management mode are created.

. Check whether finalizers are being used to control topic deletion. 
If `KafkaTopic` resources are using finalizers, ensure that you do one of the following after making the switch:
** xref:con-removing-topic-finalizers-{context}[Remove all finalizers from topics].
** Disable the finalizers by setting the `STRIMZI_USE_FINALIZERS` environment variable to `false` in the Topic Operator `env` configuration.
+
Use the same configuration for a Topic Operator running in a Strimzi-managed cluster or as a standalone deployment. 
+
.Disabling topic finalizers in a Strimzi-managed cluster
[source,shell,subs=+attributes]
----
apiVersion: {KafkaApiVersion}
kind: Kafka
metadata:
  name: my-cluster
spec:
  # ...
  entityOperator:
    topicOperator: {}
    userOperator: {}
    template:
      topicOperatorContainer:
        env:
          - name: STRIMZI_USE_FINALIZERS
            value: "false"
# ...
----
+
.Disabling topic finalizers in a standalone deployment
[source,shell,subs=+quotes]
----
apiVersion: apps/v1
kind: Deployment
metadata:
  name: strimzi-topic-operator
spec:
  template:
    spec:
      containers:
        - name: STRIMZI_USE_FINALIZERS
          value: "false"
# ...
----
+
The Topic Operator does not use finalizers in bidirectional mode.
If they are retained after making the switch from unidirectional mode, you won't be able to delete `KafkaTopic` and related resources. 

After switching between between Topic Operator modes, try creating a topic to make sure the operator is running correctly.
For more information, see xref:proc-configuring-kafka-topic-str[].  