Skip to content

Commit c00ab43

Browse files
committed
bring addition of log config config maps inline
1 parent cd28b2a commit c00ab43

2 files changed

Lines changed: 39 additions & 65 deletions

File tree

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

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ use snafu::{ResultExt, Snafu};
77
use stackable_operator::{
88
builder::{configmap::ConfigMapBuilder, meta::ObjectMetaBuilder},
99
k8s_openapi::api::core::v1::ConfigMap,
10-
product_logging::spec::Logging,
10+
product_logging::{
11+
self,
12+
spec::{ContainerLogConfig, ContainerLogConfigChoice, Logging},
13+
},
1114
role_utils::RoleGroupRef,
1215
};
1316

1417
use crate::{
1518
airflow_controller::AIRFLOW_CONTROLLER_NAME,
1619
config::webserver_config,
1720
controller::validate::ValidatedAirflowCluster,
18-
crd::{AIRFLOW_CONFIG_FILENAME, Container, build_recommended_labels, v1alpha2},
19-
product_logging::extend_config_map_with_log_config,
21+
crd::{
22+
AIRFLOW_CONFIG_FILENAME, Container, STACKABLE_LOG_DIR, build_recommended_labels, v1alpha2,
23+
},
24+
product_logging::{LOG_CONFIG_FILE, create_airflow_config},
2025
};
2126

2227
#[derive(Snafu, Debug)]
@@ -91,14 +96,33 @@ pub fn build_rolegroup_config_map(
9196
)
9297
.add_data(AIRFLOW_CONFIG_FILENAME, config_file);
9398

94-
extend_config_map_with_log_config(
95-
rolegroup,
96-
logging,
97-
container,
98-
&Container::Vector,
99-
&mut cm_builder,
100-
&validated_cluster.image,
101-
);
99+
// Log config for the main container, when it uses an Automatic log config.
100+
if let Some(ContainerLogConfig {
101+
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
102+
}) = logging.containers.get(container)
103+
{
104+
let log_dir = format!("{STACKABLE_LOG_DIR}/{container}");
105+
cm_builder.add_data(
106+
LOG_CONFIG_FILE,
107+
create_airflow_config(log_config, &log_dir, &validated_cluster.image),
108+
);
109+
}
110+
111+
// Vector agent config, when enabled.
112+
if logging.enable_vector_agent {
113+
let vector_log_config = if let Some(ContainerLogConfig {
114+
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
115+
}) = logging.containers.get(&Container::Vector)
116+
{
117+
Some(log_config)
118+
} else {
119+
None
120+
};
121+
cm_builder.add_data(
122+
product_logging::framework::VECTOR_CONFIG_FILE,
123+
product_logging::framework::create_vector_config(rolegroup, vector_log_config),
124+
);
125+
}
102126

103127
cm_builder.build().with_context(|_| BuildConfigMapSnafu {
104128
rolegroup: rolegroup.clone(),

rust/operator-binary/src/product_logging.rs

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
use std::fmt::{Display, Write};
1+
use std::fmt::Write;
22

33
use snafu::Snafu;
44
use stackable_operator::{
5-
builder::configmap::ConfigMapBuilder,
65
commons::product_image_selection::ResolvedProductImage,
7-
kube::Resource,
8-
product_logging::{
9-
self,
10-
spec::{
11-
AutomaticContainerLogConfig, ContainerLogConfig, ContainerLogConfigChoice, Logging,
12-
},
13-
},
14-
role_utils::RoleGroupRef,
6+
product_logging::spec::AutomaticContainerLogConfig,
157
};
168

17-
use crate::crd::STACKABLE_LOG_DIR;
18-
199
#[derive(Snafu, Debug)]
2010
pub enum Error {
2111
#[snafu(display("failed to retrieve the ConfigMap [{cm_name}]"))]
@@ -32,50 +22,10 @@ pub enum Error {
3222
MissingVectorAggregatorAddress,
3323
}
3424

35-
const LOG_CONFIG_FILE: &str = "log_config.py";
25+
pub const LOG_CONFIG_FILE: &str = "log_config.py";
3626
const LOG_FILE: &str = "airflow.py.json";
3727

38-
/// Extend the ConfigMap with logging and Vector configurations
39-
pub fn extend_config_map_with_log_config<C, K>(
40-
rolegroup: &RoleGroupRef<K>,
41-
logging: &Logging<C>,
42-
main_container: &C,
43-
vector_container: &C,
44-
cm_builder: &mut ConfigMapBuilder,
45-
resolved_product_image: &ResolvedProductImage,
46-
) where
47-
C: Clone + Ord + Display,
48-
K: Resource,
49-
{
50-
if let Some(ContainerLogConfig {
51-
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
52-
}) = logging.containers.get(main_container)
53-
{
54-
let log_dir = format!("{STACKABLE_LOG_DIR}/{main_container}");
55-
cm_builder.add_data(
56-
LOG_CONFIG_FILE,
57-
create_airflow_config(log_config, &log_dir, resolved_product_image),
58-
);
59-
}
60-
61-
let vector_log_config = if let Some(ContainerLogConfig {
62-
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
63-
}) = logging.containers.get(vector_container)
64-
{
65-
Some(log_config)
66-
} else {
67-
None
68-
};
69-
70-
if logging.enable_vector_agent {
71-
cm_builder.add_data(
72-
product_logging::framework::VECTOR_CONFIG_FILE,
73-
product_logging::framework::create_vector_config(rolegroup, vector_log_config),
74-
);
75-
}
76-
}
77-
78-
fn create_airflow_config(
28+
pub fn create_airflow_config(
7929
log_config: &AutomaticContainerLogConfig,
8030
log_dir: &str,
8131
resolved_product_image: &ResolvedProductImage,

0 commit comments

Comments
 (0)