@@ -12,9 +12,9 @@ use crate::crd::{
1212 listener:: { KafkaListenerConfig , KafkaListenerName , node_address_cmd} ,
1313 role:: {
1414 KAFKA_ADVERTISED_LISTENERS , KAFKA_BROKER_ID_OFFSET ,
15- KAFKA_CONTROLLER_QUORUM_BOOTSTRAP_SERVERS , KAFKA_LISTENER_SECURITY_PROTOCOL_MAP ,
16- KAFKA_LISTENERS , KAFKA_NODE_ID , KafkaRole , broker :: BROKER_PROPERTIES_FILE ,
17- controller:: CONTROLLER_PROPERTIES_FILE ,
15+ KAFKA_CONTROLLER_QUORUM_BOOTSTRAP_SERVERS , KAFKA_CONTROLLER_QUORUM_VOTERS ,
16+ KAFKA_LISTENER_SECURITY_PROTOCOL_MAP , KAFKA_LISTENERS , KAFKA_NODE_ID , KafkaRole ,
17+ broker :: BROKER_PROPERTIES_FILE , controller:: CONTROLLER_PROPERTIES_FILE ,
1818 } ,
1919 security:: KafkaTlsSecurity ,
2020 v1alpha1,
@@ -28,6 +28,7 @@ pub fn broker_kafka_container_commands(
2828 kafka_listeners : & KafkaListenerConfig ,
2929 opa_connect_string : Option < & str > ,
3030 kafka_security : & KafkaTlsSecurity ,
31+ product_version : & str ,
3132) -> String {
3233 formatdoc ! { "
3334 {COMMON_BASH_TRAP_FUNCTIONS}
@@ -47,7 +48,7 @@ pub fn broker_kafka_container_commands(
4748 true => format!( "export KERBEROS_REALM=$(grep -oP 'default_realm = \\ K.*' {})" , STACKABLE_KERBEROS_KRB5_PATH ) ,
4849 false => "" . to_string( ) ,
4950 } ,
50- broker_start_command = broker_start_command( kafka, cluster_id, controller_descriptors, kafka_listeners, opa_connect_string, kafka_security) ,
51+ broker_start_command = broker_start_command( kafka, cluster_id, controller_descriptors, kafka_listeners, opa_connect_string, kafka_security, product_version ) ,
5152 }
5253}
5354
@@ -58,6 +59,7 @@ fn broker_start_command(
5859 kafka_listeners : & KafkaListenerConfig ,
5960 opa_connect_string : Option < & str > ,
6061 kafka_security : & KafkaTlsSecurity ,
62+ product_version : & str ,
6163) -> String {
6264 let opa_config = match opa_connect_string {
6365 None => "" . to_string ( ) ,
@@ -90,17 +92,23 @@ fn broker_start_command(
9092 echo \" {KAFKA_LISTENERS}={listeners}\" >> /tmp/{properties_file}
9193 echo \" {KAFKA_ADVERTISED_LISTENERS}={advertised_listeners}\" >> /tmp/{properties_file}
9294 echo \" {KAFKA_LISTENER_SECURITY_PROTOCOL_MAP}={listener_security_protocol_map}\" >> /tmp/{properties_file}
93-
94- bin/kafka-storage.sh format --cluster-id {cluster_id} --config /tmp/{properties_file} --initial-controllers {initial_controllers} --ignore-formatted
95+ {controller_quorum_voters}
96+
97+ bin/kafka-storage.sh format --cluster-id {cluster_id} --config /tmp/{properties_file} --ignore-formatted {initial_controller_command}
9598 bin/kafka-server-start.sh /tmp/{properties_file} {opa_config}{jaas_config} &
9699 " ,
97100 config_dir = STACKABLE_CONFIG_DIR ,
98101 properties_file = BROKER_PROPERTIES_FILE ,
99102 bootstrap_servers = to_bootstrap_servers( & controller_descriptors, client_port) ,
100- initial_controllers = to_initial_controllers( & controller_descriptors, client_port) ,
101103 listeners = kafka_listeners. listeners( ) ,
102104 advertised_listeners = kafka_listeners. advertised_listeners( ) ,
103105 listener_security_protocol_map = kafka_listeners. listener_security_protocol_map( ) ,
106+ controller_quorum_voters = controller_quorum_voters_command(
107+ product_version,
108+ BROKER_PROPERTIES_FILE ,
109+ & to_quorum_voters( & controller_descriptors, client_port)
110+ ) ,
111+ initial_controller_command = initial_controllers_command( & controller_descriptors, product_version, client_port) ,
104112 }
105113 } else {
106114 formatdoc ! { "
@@ -126,8 +134,10 @@ pub fn controller_kafka_container_command(
126134 controller_descriptors : Vec < KafkaPodDescriptor > ,
127135 kafka_listeners : & KafkaListenerConfig ,
128136 kafka_security : & KafkaTlsSecurity ,
137+ product_version : & str ,
129138) -> String {
130139 let client_port = kafka_security. client_port ( ) ;
140+
131141 // TODO: copy to tmp? mount readwrite folder?
132142 formatdoc ! { "
133143 {COMMON_BASH_TRAP_FUNCTIONS}
@@ -142,8 +152,10 @@ pub fn controller_kafka_container_command(
142152 echo \" {KAFKA_CONTROLLER_QUORUM_BOOTSTRAP_SERVERS}={bootstrap_servers}\" >> /tmp/{properties_file}
143153 echo \" {KAFKA_LISTENERS}={listeners}\" >> /tmp/{properties_file}
144154 echo \" {KAFKA_LISTENER_SECURITY_PROTOCOL_MAP}={listener_security_protocol_map}\" >> /tmp/{properties_file}
155+ {controller_quorum_voters}
156+ cat /tmp/{properties_file}
145157
146- bin/kafka-storage.sh format --cluster-id {cluster_id} --config /tmp/{properties_file} --initial-controllers {initial_controllers} --ignore-formatted
158+ bin/kafka-storage.sh format --cluster-id {cluster_id} --config /tmp/{properties_file} --ignore-formatted {initial_controller_command}
147159 bin/kafka-server-start.sh /tmp/{properties_file} &
148160
149161 wait_for_termination $!
@@ -155,7 +167,12 @@ pub fn controller_kafka_container_command(
155167 bootstrap_servers = to_bootstrap_servers( & controller_descriptors, client_port) ,
156168 listeners = to_listeners( client_port) ,
157169 listener_security_protocol_map = to_listener_security_protocol_map( kafka_listeners) ,
158- initial_controllers = to_initial_controllers( & controller_descriptors, client_port) ,
170+ initial_controller_command = initial_controllers_command( & controller_descriptors, product_version, client_port) ,
171+ controller_quorum_voters = controller_quorum_voters_command(
172+ product_version,
173+ CONTROLLER_PROPERTIES_FILE ,
174+ & to_quorum_voters( & controller_descriptors, client_port)
175+ ) ,
159176 create_vector_shutdown_file_command = create_vector_shutdown_file_command( STACKABLE_LOG_DIR )
160177 }
161178}
@@ -186,10 +203,45 @@ fn to_initial_controllers(controller_descriptors: &[KafkaPodDescriptor], port: u
186203 . join ( "," )
187204}
188205
206+ fn to_quorum_voters ( controller_descriptors : & [ KafkaPodDescriptor ] , port : u16 ) -> String {
207+ controller_descriptors
208+ . iter ( )
209+ . map ( |desc| desc. as_quorum_voter ( port) )
210+ . collect :: < Vec < String > > ( )
211+ . join ( "," )
212+ }
213+
189214fn to_bootstrap_servers ( controller_descriptors : & [ KafkaPodDescriptor ] , port : u16 ) -> String {
190215 controller_descriptors
191216 . iter ( )
192217 . map ( |desc| format ! ( "{fqdn}:{port}" , fqdn = desc. fqdn( ) ) )
193218 . collect :: < Vec < String > > ( )
194219 . join ( "," )
195220}
221+
222+ fn initial_controllers_command (
223+ controller_descriptors : & [ KafkaPodDescriptor ] ,
224+ product_version : & str ,
225+ client_port : u16 ,
226+ ) -> String {
227+ match product_version. starts_with ( "3.7" ) {
228+ true => "" . to_string ( ) ,
229+ false => format ! (
230+ "--initial-controllers {initial_controllers}" ,
231+ initial_controllers = to_initial_controllers( controller_descriptors, client_port) ,
232+ ) ,
233+ }
234+ }
235+
236+ fn controller_quorum_voters_command (
237+ product_version : & str ,
238+ properties_file : & str ,
239+ quorum_voters : & str ,
240+ ) -> String {
241+ match product_version. starts_with ( "3.7" ) {
242+ true => format ! (
243+ "echo \" {KAFKA_CONTROLLER_QUORUM_VOTERS}={quorum_voters}\" >> /tmp/{properties_file}"
244+ ) ,
245+ false => "" . to_string ( ) ,
246+ }
247+ }
0 commit comments