Skip to content

Commit b6a01a0

Browse files
committed
add config map data explicitly
1 parent af0ceba commit b6a01a0

2 files changed

Lines changed: 76 additions & 66 deletions

File tree

rust/operator-binary/src/controller/build/config_map.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
role::AnyConfig,
1919
v1alpha1,
2020
},
21-
product_logging::extend_role_group_config_map,
21+
product_logging::role_group_config_map_data,
2222
utils::build_recommended_labels,
2323
};
2424

@@ -187,12 +187,16 @@ pub fn build_rolegroup_config_map(
187187
tracing::debug!(?kafka_config, "Applied kafka config");
188188
tracing::debug!(?jvm_sec_props, "Applied JVM config");
189189

190-
extend_role_group_config_map(
190+
let config_data = role_group_config_map_data(
191191
&resolved_product_image.product_version,
192192
rolegroup,
193193
&validated_rg.merged_config,
194-
&mut cm_builder,
195194
);
195+
for (file_name, data) in config_data {
196+
if let Some(data) = data {
197+
cm_builder.add_data(file_name, data);
198+
}
199+
}
196200

197201
cm_builder
198202
.build()
Lines changed: 69 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::{borrow::Cow, fmt::Display};
1+
use std::{borrow::Cow, collections::BTreeMap, fmt::Display};
22

33
use stackable_operator::{
4-
builder::configmap::ConfigMapBuilder,
54
memory::{BinaryMultiple, MemoryQuantity},
65
product_logging::{
76
self,
@@ -45,36 +44,43 @@ pub fn kafka_log_opts_env_var() -> String {
4544
"KAFKA_LOG4J_OPTS".to_string()
4645
}
4746

48-
/// Extend the role group ConfigMap with logging and Vector configurations
49-
pub fn extend_role_group_config_map(
47+
/// Get the role group ConfigMap data with logging and Vector configurations
48+
pub fn role_group_config_map_data(
5049
product_version: &str,
5150
rolegroup: &RoleGroupRef<v1alpha1::KafkaCluster>,
5251
merged_config: &AnyConfig,
53-
cm_builder: &mut ConfigMapBuilder,
54-
) {
52+
) -> BTreeMap<String, Option<String>> {
5553
let container_name = match merged_config {
5654
AnyConfig::Broker(_) => BrokerContainer::Kafka.to_string(),
5755
AnyConfig::Controller(_) => ControllerContainer::Kafka.to_string(),
5856
};
5957

58+
let mut configs: BTreeMap<String, Option<String>> = BTreeMap::new();
59+
6060
// Starting with Kafka 4.0, log4j2 is used instead of log4j.
6161
match product_version.starts_with("3.") {
62-
true => add_log4j_config_if_automatic(
63-
cm_builder,
64-
Some(merged_config.kafka_logging()),
65-
LOG4J_CONFIG_FILE,
66-
container_name,
67-
KAFKA_LOG4J_FILE,
68-
MAX_KAFKA_LOG_FILES_SIZE,
69-
),
70-
false => add_log4j2_config_if_automatic(
71-
cm_builder,
72-
Some(merged_config.kafka_logging()),
73-
LOG4J2_CONFIG_FILE,
74-
container_name,
75-
KAFKA_LOG4J2_FILE,
76-
MAX_KAFKA_LOG_FILES_SIZE,
77-
),
62+
true => {
63+
configs.insert(
64+
LOG4J_CONFIG_FILE.to_string(),
65+
log4j_config_if_automatic(
66+
Some(merged_config.kafka_logging()),
67+
container_name,
68+
KAFKA_LOG4J_FILE,
69+
MAX_KAFKA_LOG_FILES_SIZE,
70+
),
71+
);
72+
}
73+
false => {
74+
configs.insert(
75+
LOG4J2_CONFIG_FILE.to_string(),
76+
log4j2_config_if_automatic(
77+
Some(merged_config.kafka_logging()),
78+
container_name,
79+
KAFKA_LOG4J2_FILE,
80+
MAX_KAFKA_LOG_FILES_SIZE,
81+
),
82+
);
83+
}
7884
}
7985

8086
let vector_log_config = merged_config.vector_logging();
@@ -88,65 +94,65 @@ pub fn extend_role_group_config_map(
8894
};
8995

9096
if merged_config.vector_logging_enabled() {
91-
cm_builder.add_data(
92-
product_logging::framework::VECTOR_CONFIG_FILE,
93-
product_logging::framework::create_vector_config(rolegroup, vector_log_config),
97+
configs.insert(
98+
product_logging::framework::VECTOR_CONFIG_FILE.to_string(),
99+
Some(product_logging::framework::create_vector_config(
100+
rolegroup,
101+
vector_log_config,
102+
)),
94103
);
95104
}
105+
configs
96106
}
97107

98-
fn add_log4j_config_if_automatic(
99-
cm_builder: &mut ConfigMapBuilder,
108+
fn log4j_config_if_automatic(
100109
log_config: Option<Cow<ContainerLogConfig>>,
101-
log_config_file: &str,
102110
container_name: impl Display,
103111
log_file: &str,
104112
max_log_file_size: MemoryQuantity,
105-
) {
106-
if let Some(ContainerLogConfig {
113+
) -> Option<String> {
114+
let config = if let Some(ContainerLogConfig {
107115
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
108116
}) = log_config.as_deref()
109117
{
110-
cm_builder.add_data(
111-
log_config_file,
112-
product_logging::framework::create_log4j_config(
113-
&format!("{STACKABLE_LOG_DIR}/{container_name}"),
114-
log_file,
115-
max_log_file_size
116-
.scale_to(BinaryMultiple::Mebi)
117-
.floor()
118-
.value as u32,
119-
CONSOLE_CONVERSION_PATTERN_LOG4J,
120-
log_config,
121-
),
122-
);
123-
}
118+
Some(product_logging::framework::create_log4j_config(
119+
&format!("{STACKABLE_LOG_DIR}/{container_name}"),
120+
log_file,
121+
max_log_file_size
122+
.scale_to(BinaryMultiple::Mebi)
123+
.floor()
124+
.value as u32,
125+
CONSOLE_CONVERSION_PATTERN_LOG4J,
126+
log_config,
127+
))
128+
} else {
129+
None
130+
};
131+
config
124132
}
125133

126-
fn add_log4j2_config_if_automatic(
127-
cm_builder: &mut ConfigMapBuilder,
134+
fn log4j2_config_if_automatic(
128135
log_config: Option<Cow<ContainerLogConfig>>,
129-
log_config_file: &str,
130136
container_name: impl Display,
131137
log_file: &str,
132138
max_log_file_size: MemoryQuantity,
133-
) {
134-
if let Some(ContainerLogConfig {
139+
) -> Option<String> {
140+
let config = if let Some(ContainerLogConfig {
135141
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
136142
}) = log_config.as_deref()
137143
{
138-
cm_builder.add_data(
139-
log_config_file,
140-
product_logging::framework::create_log4j2_config(
141-
&format!("{STACKABLE_LOG_DIR}/{container_name}",),
142-
log_file,
143-
max_log_file_size
144-
.scale_to(BinaryMultiple::Mebi)
145-
.floor()
146-
.value as u32,
147-
CONSOLE_CONVERSION_PATTERN_LOG4J2,
148-
log_config,
149-
),
150-
);
151-
}
144+
Some(product_logging::framework::create_log4j2_config(
145+
&format!("{STACKABLE_LOG_DIR}/{container_name}",),
146+
log_file,
147+
max_log_file_size
148+
.scale_to(BinaryMultiple::Mebi)
149+
.floor()
150+
.value as u32,
151+
CONSOLE_CONVERSION_PATTERN_LOG4J2,
152+
log_config,
153+
))
154+
} else {
155+
None
156+
};
157+
config
152158
}

0 commit comments

Comments
 (0)