// Module included in the following assemblies:
//
// assembly-upgrade-resources.adoc

[id='proc-upgrade-kafka-resources-{context}']
= Upgrading Kafka resources to support {ApiVersion}

.Prerequisites

* A Cluster Operator supporting the `{ApiVersion}` API version is up and running.

.Procedure
Perform the following steps for each `Kafka` custom resource in your deployment.

. Update the `Kafka` custom resource in an editor.
+
[source,shell,subs="+quotes,attributes"]
----
kubectl edit kafka _KAFKA-CLUSTER_
----

. If you have not already done so, update `.spec.kafka.listener` to the new generic listener format, as described in xref:con-upgrade-listeners-{context}[].
+
[WARNING]
====
The old listener format is not supported in API version `{ApiVersion}`.
====

. If present, move `affinity` from `.spec.kafka.affinity` to `.spec.kafka.template.pod.affinity`.

. If present, move `tolerations` from `.spec.kafka.tolerations` to `.spec.kafka.template.pod.tolerations`.

. If present, remove `.spec.kafka.template.tlsSidecarContainer`.

. If present, remove `.spec.kafka.tlsSidecarContainer`.

. If either of the following policy configurations exist:

* `.spec.kafka.template.externalBootstrapService.externalTrafficPolicy`
* `.spec.kafka.template.perPodService.externalTrafficPolicy`

.. Move the configuration to `.spec.kafka.listeners[].configuration.externalTrafficPolicy`, for both `type: loadbalancer` and `type: nodeport` listeners.

.. Remove `.spec.kafka.template.externalBootstrapService.externalTrafficPolicy` or `.spec.kafka.template.perPodService.externalTrafficPolicy`.

. If either of the following `loadbalancer` listener configurations exist:

* `.spec.kafka.template.externalBootstrapService.loadBalancerSourceRanges`
* `.spec.kafka.template.perPodService.loadBalancerSourceRanges`

.. Move the configuration to `.spec.kafka.listeners[].configuration.loadBalancerSourceRanges`, for `type: loadbalancer` listeners.

.. Remove `.spec.kafka.template.externalBootstrapService.loadBalancerSourceRanges` or `.spec.kafka.template.perPodService.loadBalancerSourceRanges`.

. If `type: external` logging is configured in `.spec.kafka.logging`:
+
Replace the `name` of the ConfigMap containing the logging configuration:
+
[source,yaml,subs="attributes+"]
----
logging:
  type: external
  name: my-config-map
----
+
With the `valueFrom.configMapKeyRef` field, and specify both the ConfigMap `name` and the `key` under which the logging is stored:
+
[source,yaml,subs="attributes+"]
----
logging:
  type: external
  valueFrom:
    configMapKeyRef:
      name: my-config-map
      key: log4j.properties
----

. If the `.spec.kafka.metrics` field is used to enable metrics:

.. Create a new ConfigMap that stores the YAML configuration for the JMX Prometheus exporter under a key. 
The YAML must match what is currently in the `.spec.kafka.metrics` field.
+
[source,yaml,subs="attributes+"]
----
kind: ConfigMap
apiVersion: v1
metadata:
  name: kafka-metrics
  labels:
    app: strimzi
data:
  kafka-metrics-config.yaml: |
      <YAML>
----

.. Add a `.spec.kafka.metricsConfig` property that points to the ConfigMap and key:
+
[source,yaml,subs="attributes+"]
----
metricsConfig:
  type: jmxPrometheusExporter
  valueFrom:
    configMapKeyRef:
      name: kafka-metrics
      key: kafka-metrics-config.yaml
----

.. Delete the old `.spec.kafka.metrics` field.

. Save the file, exit the editor and wait for the updated custom resource to be reconciled.

.What to do next

For each `Kafka` custom resource, upgrade the configurations for ZooKeeper, Topic Operator, Entity Operator, and Cruise Control (if deployed) to support version `{ApiVersion}`. 
This is described in the following procedures.

When all `Kafka` configurations are updated to support `{ApiVersion}`, you can xref:proc-upgrade-kafka-api-version-{context}[upgrade the `Kafka` custom resource to `{ApiVersion}`]. 