Skip to content

Commit 2f5f7cb

Browse files
maltesanderclaude
andcommitted
refactor: Fold product_logging into the build step
Move the Vector config building and the `BundleBuilderLogLevel` mapping out of the top-level `product_logging` module into `controller/build/properties/logging.rs`, mirroring hdfs. `build_vector_config` returns `Option<String>` (the agent config or `None` when disabled) and is infallible, so the dead `InvalidLoggingConfig` error path is dropped. The DaemonSet now imports `BundleBuilderLogLevel` from the build module, and the standalone `product_logging.rs` is removed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8e1be27 commit 2f5f7cb

5 files changed

Lines changed: 23 additions & 52 deletions

File tree

rust/operator-binary/src/controller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ use crate::{
7171
APP_NAME, Container, DEFAULT_SERVER_GRACEFUL_SHUTDOWN_TIMEOUT, OPERATOR_NAME,
7272
OpaClusterStatus, OpaConfig, OpaRole, user_info_fetcher, v1alpha2,
7373
},
74+
controller::build::properties::logging::BundleBuilderLogLevel,
7475
discovery::{self, build_discovery_configmaps},
7576
operations::graceful_shutdown::add_graceful_shutdown_config,
76-
product_logging::BundleBuilderLogLevel,
7777
service::{
7878
self, APP_PORT, APP_PORT_NAME, build_rolegroup_headless_service,
7979
build_rolegroup_metrics_service, build_server_role_service,

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use stackable_operator::{
77
builder::{configmap::ConfigMapBuilder, meta::ObjectMetaBuilder},
88
k8s_openapi::api::core::v1::ConfigMap,
99
kvp::ObjectLabels,
10+
product_logging::framework::VECTOR_CONFIG_FILE,
1011
role_utils::RoleGroupRef,
1112
};
1213

13-
use super::properties::{ConfigFileName, config_json, user_info_fetcher};
14+
use super::properties::{ConfigFileName, config_json, logging, user_info_fetcher};
1415
use crate::{
1516
controller::validate::{OpaRoleGroupConfig, ValidatedCluster},
1617
crd::v1alpha2,
17-
product_logging::extend_role_group_config_map,
1818
};
1919

2020
#[derive(Snafu, Debug)]
@@ -35,12 +35,6 @@ pub enum Error {
3535
#[snafu(display("failed to build user-info-fetcher.json"))]
3636
BuildUserInfoFetcher { source: user_info_fetcher::Error },
3737

38-
#[snafu(display("failed to add the logging configuration to the ConfigMap [{cm_name}]"))]
39-
InvalidLoggingConfig {
40-
source: crate::product_logging::Error,
41-
cm_name: String,
42-
},
43-
4438
#[snafu(display("failed to build ConfigMap for [{rolegroup}]"))]
4539
BuildConfigMap {
4640
source: stackable_operator::builder::configmap::Error,
@@ -86,14 +80,11 @@ pub fn build_rolegroup_config_map(
8680
);
8781
}
8882

89-
extend_role_group_config_map(
90-
rolegroup_ref,
91-
&rolegroup_config.merged_config.logging,
92-
&mut cm_builder,
93-
)
94-
.context(InvalidLoggingConfigSnafu {
95-
cm_name: rolegroup_ref.object_name(),
96-
})?;
83+
if let Some(vector_config) =
84+
logging::build_vector_config(rolegroup_ref, &rolegroup_config.merged_config.logging)
85+
{
86+
cm_builder.add_data(VECTOR_CONFIG_FILE, vector_config);
87+
}
9788

9889
cm_builder
9990
.build()
Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use snafu::Snafu;
1+
//! Builds the Vector agent config file and maps log levels for the Stackable Rust sidecars.
2+
23
use stackable_operator::{
3-
builder::configmap::ConfigMapBuilder,
44
product_logging::{
55
self,
66
spec::{ContainerLogConfig, ContainerLogConfigChoice, LogLevel, Logging},
@@ -10,26 +10,6 @@ use stackable_operator::{
1010

1111
use crate::crd::{Container, v1alpha2};
1212

13-
#[derive(Snafu, Debug)]
14-
pub enum Error {
15-
#[snafu(display("object has no namespace"))]
16-
ObjectHasNoNamespace,
17-
#[snafu(display("failed to retrieve the ConfigMap [{cm_name}]"))]
18-
ConfigMapNotFound {
19-
source: stackable_operator::client::Error,
20-
cm_name: String,
21-
},
22-
#[snafu(display("failed to retrieve the entry [{entry}] for ConfigMap [{cm_name}]"))]
23-
MissingConfigMapEntry {
24-
entry: &'static str,
25-
cm_name: String,
26-
},
27-
#[snafu(display("vectorAggregatorConfigMapName must be set"))]
28-
MissingVectorAggregatorAddress,
29-
}
30-
31-
type Result<T, E = Error> = std::result::Result<T, E>;
32-
3313
#[derive(strum::Display)]
3414
#[strum(serialize_all = "UPPERCASE")]
3515
pub enum BundleBuilderLogLevel {
@@ -52,12 +32,16 @@ impl From<LogLevel> for BundleBuilderLogLevel {
5232
}
5333
}
5434

55-
/// Extend the role group ConfigMap with logging and Vector configurations
56-
pub fn extend_role_group_config_map(
35+
/// Builds the Vector agent config (`vector.yaml`) for the role group, or `None` when the Vector
36+
/// agent is disabled.
37+
pub fn build_vector_config(
5738
rolegroup: &RoleGroupRef<v1alpha2::OpaCluster>,
5839
logging: &Logging<Container>,
59-
cm_builder: &mut ConfigMapBuilder,
60-
) -> Result<()> {
40+
) -> Option<String> {
41+
if !logging.enable_vector_agent {
42+
return None;
43+
}
44+
6145
let vector_log_config = if let Some(ContainerLogConfig {
6246
choice: Some(ContainerLogConfigChoice::Automatic(log_config)),
6347
}) = logging.containers.get(&Container::Vector)
@@ -67,12 +51,8 @@ pub fn extend_role_group_config_map(
6751
None
6852
};
6953

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-
Ok(())
54+
Some(product_logging::framework::create_vector_config(
55+
rolegroup,
56+
vector_log_config,
57+
))
7858
}

rust/operator-binary/src/controller/build/properties/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! operators.
77
88
pub mod config_json;
9+
pub mod logging;
910
pub mod user_info_fetcher;
1011

1112
/// The names of the config files assembled into the rolegroup `ConfigMap`.

rust/operator-binary/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ mod controller;
4040
mod crd;
4141
mod discovery;
4242
mod operations;
43-
mod product_logging;
4443
mod service;
4544
mod webhooks;
4645

0 commit comments

Comments
 (0)