@@ -153,35 +153,32 @@ func configureBrokerKRaftMode(bConfig *v1beta1.BrokerConfig, brokerID int32, kaf
153153 quorumVoters []string , serverPasses map [string ]string , extListenerStatuses , intListenerStatuses map [string ]v1beta1.ListenerStatusList , log logr.Logger ,
154154 brokerReadOnlyConfig * properties.Properties ) {
155155
156- // configure "node.id" and "process.roles" by default OR when MigrationBrokerKRaftMode is set and 'true'.
157- // this is to support the zk to kRaft migration
158- if migrationBrokerKRaftMode , found := brokerReadOnlyConfig .Get (kafkautils .MigrationBrokerKRaftMode ); ! found || migrationBrokerKRaftMode .Value () == "true" {
156+ controllerListenerName := generateControlPlaneListener (kafkaCluster .Spec .ListenersConfig .InternalListeners )
157+
158+ // when kRaft is enabled for the cluster, brokers can still be configured to use zookeeper for metadata.
159+ // this is to support the zk to kRaft migration where both zookeeper and kRaft controllers are running in parallel.
160+ if shouldUseKRaftModeForBroker (brokerReadOnlyConfig ) {
159161 if err := config .Set (kafkautils .KafkaConfigNodeID , brokerID ); err != nil {
160162 log .Error (err , fmt .Sprintf (kafkautils .BrokerConfigErrorMsgTemplate , kafkautils .KafkaConfigNodeID ))
161163 }
162164
163165 if err := config .Set (kafkautils .KafkaConfigProcessRoles , bConfig .Roles ); err != nil {
164166 log .Error (err , fmt .Sprintf (kafkautils .BrokerConfigErrorMsgTemplate , kafkautils .KafkaConfigProcessRoles ))
165167 }
166- } else { // migrationBrokerKRaftMode.Value() == "false" -> use zk mode for broker
167- // when in zk mode, "broker.id" and "control.plane.listener.name" are set so it can communicate with zookeeper
168+ } else { // use zk mode for broker.
169+ // when in zk mode, "broker.id" and "control.plane.listener.name" are configured so it will communicate with zookeeper
168170 if err := config .Set (kafkautils .KafkaConfigBrokerID , brokerID ); err != nil {
169171 log .Error (err , fmt .Sprintf (kafkautils .BrokerConfigErrorMsgTemplate , kafkautils .KafkaConfigBrokerID ))
170172 }
171173
172- cclConf := generateControlPlaneListener (kafkaCluster .Spec .ListenersConfig .InternalListeners )
173- if cclConf != "" {
174- if err := config .Set (kafkautils .KafkaConfigControlPlaneListener , cclConf ); err != nil {
174+ if controllerListenerName != "" {
175+ if err := config .Set (kafkautils .KafkaConfigControlPlaneListener , controllerListenerName ); err != nil {
175176 log .Error (err , fmt .Sprintf (kafkautils .BrokerConfigErrorMsgTemplate , kafkautils .KafkaConfigControlPlaneListener ))
176177 }
177178 }
178179 }
179180
180- controllerListenerName := generateControlPlaneListener (kafkaCluster .Spec .ListenersConfig .InternalListeners )
181-
182- // configure "controller.quorum.voters" and "controller.listener.names" by default OR when MigrationBrokerControllerQuorumConfigEnabled is set and 'true'.
183- // this is to support the zk to kRaft migration
184- if migrationBrokerControllerQuorumConfigEnabled , found := brokerReadOnlyConfig .Get (kafkautils .MigrationBrokerControllerQuorumConfigEnabled ); ! found || migrationBrokerControllerQuorumConfigEnabled .Value () == "true" {
181+ if shouldConfigureControllerQuorumForBroker (brokerReadOnlyConfig ) {
185182 if err := config .Set (kafkautils .KafkaConfigControllerQuorumVoters , quorumVoters ); err != nil {
186183 log .Error (err , fmt .Sprintf (kafkautils .BrokerConfigErrorMsgTemplate , kafkautils .KafkaConfigControllerQuorumVoters ))
187184 }
@@ -239,6 +236,20 @@ func configureBrokerKRaftMode(bConfig *v1beta1.BrokerConfig, brokerID int32, kaf
239236 }
240237}
241238
239+ // Returns true by default (not in migration configured) OR when MigrationBrokerKRaftMode is set and 'true'.
240+ // this is to support the zk to kRaft migration
241+ func shouldUseKRaftModeForBroker (brokerReadOnlyConfig * properties.Properties ) bool {
242+ migrationBrokerKRaftMode , found := brokerReadOnlyConfig .Get (kafkautils .MigrationBrokerKRaftMode )
243+ return ! found || migrationBrokerKRaftMode .Value () == "true"
244+ }
245+
246+ // Returns true by default (not in migration) OR when MigrationBrokerControllerQuorumConfigEnabled is set and 'true'.
247+ // this is to support the zk to kRaft migration
248+ func shouldConfigureControllerQuorumForBroker (brokerReadOnlyConfig * properties.Properties ) bool {
249+ migrationBrokerControllerQuorumConfigEnabled , found := brokerReadOnlyConfig .Get (kafkautils .MigrationBrokerControllerQuorumConfigEnabled )
250+ return ! found || migrationBrokerControllerQuorumConfigEnabled .Value () == "true"
251+ }
252+
242253func configureBrokerZKMode (brokerID int32 , kafkaCluster * v1beta1.KafkaCluster , config * properties.Properties ,
243254 serverPasses map [string ]string , extListenerStatuses , intListenerStatuses ,
244255 controllerIntListenerStatuses map [string ]v1beta1.ListenerStatusList , log logr.Logger ) {
0 commit comments