Skip to content

Commit 3a1cba9

Browse files
committed
fix 3.7 deployments and tests
1 parent 2627692 commit 3a1cba9

7 files changed

Lines changed: 70 additions & 29 deletions

File tree

rust/operator-binary/src/config/command.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ fn broker_start_command(
7171
false => "".to_string(),
7272
};
7373

74-
let client_port = kafka_security.client_port();
75-
7674
// This should be improved:
7775
// - mount emptyDir as readWriteConfig
7876
if kafka.is_controller_configured() {
@@ -89,7 +87,7 @@ fn broker_start_command(
8987
",
9088
config_dir = STACKABLE_CONFIG_DIR,
9189
properties_file = BROKER_PROPERTIES_FILE,
92-
initial_controller_command = initial_controllers_command(&controller_descriptors, product_version, client_port),
90+
initial_controller_command = initial_controllers_command(&controller_descriptors, product_version),
9391
}
9492
} else {
9593
formatdoc! {"
@@ -151,11 +149,8 @@ wait_for_termination()
151149
pub fn controller_kafka_container_command(
152150
cluster_id: &str,
153151
controller_descriptors: Vec<KafkaPodDescriptor>,
154-
kafka_security: &KafkaTlsSecurity,
155152
product_version: &str,
156153
) -> String {
157-
let client_port = kafka_security.client_port();
158-
159154
// TODO: The properties file from the configmap is copied to the /tmp folder and appended with dynamic properties
160155
// This should be improved:
161156
// - mount emptyDir as readWriteConfig
@@ -183,29 +178,28 @@ pub fn controller_kafka_container_command(
183178
remove_vector_shutdown_file_command = remove_vector_shutdown_file_command(STACKABLE_LOG_DIR),
184179
config_dir = STACKABLE_CONFIG_DIR,
185180
properties_file = CONTROLLER_PROPERTIES_FILE,
186-
initial_controller_command = initial_controllers_command(&controller_descriptors, product_version, client_port),
181+
initial_controller_command = initial_controllers_command(&controller_descriptors, product_version),
187182
create_vector_shutdown_file_command = create_vector_shutdown_file_command(STACKABLE_LOG_DIR)
188183
}
189184
}
190185

191-
fn to_initial_controllers(controller_descriptors: &[KafkaPodDescriptor], port: u16) -> String {
186+
fn to_initial_controllers(controller_descriptors: &[KafkaPodDescriptor]) -> String {
192187
controller_descriptors
193188
.iter()
194-
.map(|desc| desc.as_voter(port))
189+
.map(|desc| desc.as_voter())
195190
.collect::<Vec<String>>()
196191
.join(",")
197192
}
198193

199194
fn initial_controllers_command(
200195
controller_descriptors: &[KafkaPodDescriptor],
201196
product_version: &str,
202-
client_port: u16,
203197
) -> String {
204198
match product_version.starts_with("3.7") {
205199
true => "".to_string(),
206200
false => format!(
207201
"--initial-controllers {initial_controllers}",
208-
initial_controllers = to_initial_controllers(controller_descriptors, client_port),
202+
initial_controllers = to_initial_controllers(controller_descriptors),
209203
),
210204
}
211205
}

rust/operator-binary/src/config/node_id_hasher.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use crate::crd::v1alpha1::KafkaCluster;
66
/// This function generates an integer that is stable for a given role group
77
/// regardless if broker or controllers.
88
/// This integer is then added to the pod index to compute the final node.id
9-
/// TODO: this is dangerous. How high are the chances of these ranges overlapping?
9+
/// The node.id is only set and used in Kraft mode.
10+
/// Warning: this is not safe from collisions.
1011
pub fn node_id_hash32_offset(rolegroup_ref: &RoleGroupRef<KafkaCluster>) -> u32 {
1112
let hash = fnv_hash32(&format!(
1213
"{role}-{rolegroup}",

rust/operator-binary/src/crd/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ impl v1alpha1::KafkaCluster {
263263
&self,
264264
requested_kafka_role: Option<&KafkaRole>,
265265
cluster_info: &KubernetesClusterInfo,
266+
client_port: u16,
266267
) -> Result<Vec<KafkaPodDescriptor>, Error> {
267268
let namespace = self.metadata.namespace.clone().context(NoNamespaceSnafu)?;
268269
let mut pod_descriptors = Vec::new();
@@ -303,6 +304,7 @@ impl v1alpha1::KafkaCluster {
303304
replica,
304305
cluster_domain: cluster_info.cluster_domain.clone(),
305306
node_id: node_id_hash_offset + u32::from(replica),
307+
client_port,
306308
});
307309
}
308310
}
@@ -352,6 +354,7 @@ pub struct KafkaPodDescriptor {
352354
cluster_domain: DomainName,
353355
node_id: u32,
354356
pub role: String,
357+
pub client_port: u16,
355358
}
356359

357360
impl KafkaPodDescriptor {
@@ -380,18 +383,20 @@ impl KafkaPodDescriptor {
380383
/// * controller-0 is the replica's host,
381384
/// * 1234 is the replica's port.
382385
// NOTE(@maltesander): Even though the used Uuid states to be type 4 it does not work... 0000000000-00000000000 works...
383-
pub fn as_voter(&self, port: u16) -> String {
386+
pub fn as_voter(&self) -> String {
384387
format!(
385388
"{node_id}@{fqdn}:{port}:0000000000-{node_id:0>11}",
386389
node_id = self.node_id,
390+
port = self.client_port,
387391
fqdn = self.fqdn(),
388392
)
389393
}
390394

391-
pub fn as_quorum_voter(&self, port: u16) -> String {
395+
pub fn as_quorum_voter(&self) -> String {
392396
format!(
393397
"{node_id}@{fqdn}:{port}",
394398
node_id = self.node_id,
399+
port = self.client_port,
395400
fqdn = self.fqdn(),
396401
)
397402
}

rust/operator-binary/src/crd/role/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ pub const KAFKA_CONTROLLER_QUORUM_BOOTSTRAP_SERVERS: &str = "controller.quorum.b
6868

6969
/// Map of id/endpoint information for the set of voters in a comma-separated list of {id}@{host}:{port} entries.
7070
/// For example: 1@localhost:9092,2@localhost:9093,3@localhost:9094
71-
/// TODO: maybe re-enable
72-
// pub const KAFKA_CONTROLLER_QUORUM_VOTERS: &str = "controller.quorum.voters";
71+
pub const KAFKA_CONTROLLER_QUORUM_VOTERS: &str = "controller.quorum.voters";
7372

7473
#[derive(Snafu, Debug)]
7574
pub enum Error {

rust/operator-binary/src/kafka_controller.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,11 @@ pub async fn reconcile_kafka(
379379
.context(InvalidKafkaListenersSnafu)?;
380380

381381
let pod_descriptors = kafka
382-
.pod_descriptors(None, &client.kubernetes_cluster_info)
382+
.pod_descriptors(
383+
None,
384+
&client.kubernetes_cluster_info,
385+
kafka_security.client_port(),
386+
)
383387
.context(BuildPodDescriptorsSnafu)?;
384388

385389
let rg_configmap = build_rolegroup_config_map(

rust/operator-binary/src/resource/configmap.rs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use crate::{
1818
listener::{KafkaListenerConfig, KafkaListenerName},
1919
role::{
2020
AnyConfig, KAFKA_ADVERTISED_LISTENERS, KAFKA_CONTROLLER_QUORUM_BOOTSTRAP_SERVERS,
21-
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP, KAFKA_LISTENERS, KAFKA_LOG_DIRS, KAFKA_NODE_ID,
22-
KAFKA_PROCESS_ROLES, KafkaRole,
21+
KAFKA_CONTROLLER_QUORUM_VOTERS, KAFKA_LISTENER_SECURITY_PROTOCOL_MAP, KAFKA_LISTENERS,
22+
KAFKA_LOG_DIRS, KAFKA_NODE_ID, KAFKA_PROCESS_ROLES, KafkaRole,
2323
},
2424
security::KafkaTlsSecurity,
2525
v1alpha1,
@@ -94,6 +94,7 @@ pub fn build_rolegroup_config_map(
9494
pod_descriptors,
9595
listener_config,
9696
opa_connect_string,
97+
resolved_product_image.product_version.starts_with("3.7"), // needs_quorum_voters
9798
)?;
9899

99100
// Need to call this to get configOverrides :(
@@ -198,6 +199,7 @@ fn server_properties_file(
198199
pod_descriptors: &[KafkaPodDescriptor],
199200
listener_config: &KafkaListenerConfig,
200201
opa_connect_string: Option<&str>,
202+
needs_quorum_voters: bool,
201203
) -> Result<BTreeMap<String, String>, Error> {
202204
let kraft_controllers = kraft_controllers(pod_descriptors);
203205

@@ -209,7 +211,7 @@ fn server_properties_file(
209211
KafkaRole::Controller => {
210212
let kraft_controllers = kraft_controllers.context(NoKraftControllersFoundSnafu)?;
211213

212-
Ok(BTreeMap::from([
214+
let mut result = BTreeMap::from([
213215
(
214216
KAFKA_LOG_DIRS.to_string(),
215217
"/stackable/data/kraft".to_string(),
@@ -227,10 +229,6 @@ fn server_properties_file(
227229
KAFKA_CONTROLLER_QUORUM_BOOTSTRAP_SERVERS.to_string(),
228230
kraft_controllers.clone(),
229231
),
230-
// TODO: figure this out
231-
//(KAFKA_CONTROLLER_QUORUM_VOTERS.to_string(),
232-
//kraft_controllers,
233-
//),
234232
(
235233
KAFKA_LISTENERS.to_string(),
236234
"CONTROLLER://${env:POD_NAME}.${env:ROLEGROUP_HEADLESS_SERVICE_NAME}.${env:NAMESPACE}.svc.${env:CLUSTER_DOMAIN}:${env:KAFKA_CLIENT_PORT}".to_string(),
@@ -240,7 +238,16 @@ fn server_properties_file(
240238
listener_config
241239
.listener_security_protocol_map_for_listener(&KafkaListenerName::Controller)
242240
.unwrap_or("".to_string())),
243-
]))
241+
]);
242+
243+
if needs_quorum_voters {
244+
let kraft_voters =
245+
kraft_voters(pod_descriptors).context(NoKraftControllersFoundSnafu)?;
246+
247+
result.extend([(KAFKA_CONTROLLER_QUORUM_VOTERS.to_string(), kraft_voters)]);
248+
}
249+
250+
Ok(result)
244251
}
245252
KafkaRole::Broker => {
246253
let mut result = BTreeMap::from([
@@ -278,6 +285,13 @@ fn server_properties_file(
278285
kraft_controllers.clone(),
279286
),
280287
]);
288+
289+
if needs_quorum_voters {
290+
let kraft_voters =
291+
kraft_voters(pod_descriptors).context(NoKraftControllersFoundSnafu)?;
292+
293+
result.extend([(KAFKA_CONTROLLER_QUORUM_VOTERS.to_string(), kraft_voters)]);
294+
}
281295
} else {
282296
// Running with ZooKeeper enabled
283297
result.extend([(
@@ -313,7 +327,28 @@ fn kraft_controllers(pod_descriptors: &[KafkaPodDescriptor]) -> Option<String> {
313327
let result = pod_descriptors
314328
.iter()
315329
.filter(|pd| pd.role == KafkaRole::Controller.to_string())
316-
.map(|desc| format!("{fqdn}:${{env:KAFKA_CLIENT_PORT}}", fqdn = desc.fqdn()))
330+
.map(|desc| {
331+
format!(
332+
"{fqdn}:{client_port}",
333+
fqdn = desc.fqdn(),
334+
client_port = desc.client_port
335+
)
336+
})
337+
.collect::<Vec<String>>()
338+
.join(",");
339+
340+
if result.is_empty() {
341+
None
342+
} else {
343+
Some(result)
344+
}
345+
}
346+
347+
fn kraft_voters(pod_descriptors: &[KafkaPodDescriptor]) -> Option<String> {
348+
let result = pod_descriptors
349+
.iter()
350+
.filter(|pd| pd.role == KafkaRole::Controller.to_string())
351+
.map(|desc| desc.as_quorum_voter())
317352
.collect::<Vec<String>>()
318353
.join(",");
319354

rust/operator-binary/src/resource/statefulset.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ pub fn build_broker_rolegroup_statefulset(
299299
cluster_id,
300300
// we need controller pods
301301
kafka
302-
.pod_descriptors(Some(&KafkaRole::Controller), cluster_info)
302+
.pod_descriptors(
303+
Some(&KafkaRole::Controller),
304+
cluster_info,
305+
kafka_security.client_port(),
306+
)
303307
.context(BuildPodDescriptorsSnafu)?,
304308
kafka_security,
305309
&resolved_product_image.product_version,
@@ -642,9 +646,8 @@ pub fn build_controller_rolegroup_statefulset(
642646
.args(vec![controller_kafka_container_command(
643647
kafka.cluster_id().context(ClusterIdMissingSnafu)?,
644648
kafka
645-
.pod_descriptors(Some(kafka_role), cluster_info)
649+
.pod_descriptors(Some(kafka_role), cluster_info, kafka_security.client_port())
646650
.context(BuildPodDescriptorsSnafu)?,
647-
kafka_security,
648651
&resolved_product_image.product_version,
649652
)])
650653
.add_env_var("PRE_STOP_CONTROLLER_SLEEP_SECONDS", "10")

0 commit comments

Comments
 (0)