Skip to content

Commit f39f11f

Browse files
committed
fix: introduce ConfigFileName enum
1 parent ff4adee commit f39f11f

5 files changed

Lines changed: 36 additions & 15 deletions

File tree

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ use stackable_operator::{
99
k8s_openapi::api::core::v1::EnvVar,
1010
kube::ResourceExt,
1111
product_logging::framework::create_vector_shutdown_file_command,
12-
v2::{
13-
builder::pod::container::EnvVarSet,
14-
product_logging::framework::STACKABLE_LOG_DIR,
15-
},
12+
v2::{builder::pod::container::EnvVarSet, product_logging::framework::STACKABLE_LOG_DIR},
1613
};
1714

1815
use crate::{

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,30 @@
44
pub mod env_vars;
55
pub mod product_logging;
66
pub mod webserver_config;
7+
8+
/// The names of the Airflow config files assembled into the rolegroup `ConfigMap`.
9+
///
10+
/// This is the single source of truth for the on-disk file names; nothing else should hard-code
11+
/// them (the Vector agent config is the exception — its name comes from the upstream
12+
/// `product_logging::framework::VECTOR_CONFIG_FILE` constant).
13+
#[derive(Clone, Copy, Debug, strum::Display)]
14+
pub enum ConfigFileName {
15+
#[strum(serialize = "webserver_config.py")]
16+
WebserverConfig,
17+
#[strum(serialize = "log_config.py")]
18+
LogConfig,
19+
}
20+
21+
#[cfg(test)]
22+
mod tests {
23+
use super::*;
24+
25+
#[test]
26+
fn file_names_match_the_airflow_on_disk_names() {
27+
assert_eq!(
28+
ConfigFileName::WebserverConfig.to_string(),
29+
"webserver_config.py"
30+
);
31+
assert_eq!(ConfigFileName::LogConfig.to_string(), "log_config.py");
32+
}
33+
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use stackable_operator::{
99
v2::product_logging::framework::ValidatedContainerLogConfigChoice,
1010
};
1111

12-
pub const LOG_CONFIG_FILE: &str = "log_config.py";
13-
1412
/// The rotating log file the generated `log_config.py` writes to (consumed by the Vector agent).
1513
const LOG_FILE: &str = "airflow.py.json";
1614

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ use crate::{
1818
controller::{
1919
ValidatedCluster, ValidatedLogging,
2020
build::properties::{
21-
product_logging::{LOG_CONFIG_FILE, create_airflow_config, vector_config_file_content},
21+
ConfigFileName,
22+
product_logging::{create_airflow_config, vector_config_file_content},
2223
webserver_config,
2324
},
2425
},
25-
crd::{AIRFLOW_CONFIG_FILENAME, AirflowConfigOverrides, Container},
26+
crd::{AirflowConfigOverrides, Container},
2627
};
2728

2829
#[derive(Snafu, Debug)]
@@ -72,7 +73,7 @@ pub fn build_rolegroup_config_map(
7273
)
7374
.build(),
7475
)
75-
.add_data(AIRFLOW_CONFIG_FILENAME, config_file);
76+
.add_data(ConfigFileName::WebserverConfig.to_string(), config_file);
7677

7778
// Log config for the main container, when it uses an Automatic log config.
7879
let log_dir = format!("{STACKABLE_LOG_DIR}/{container}");
@@ -81,7 +82,7 @@ pub fn build_rolegroup_config_map(
8182
&log_dir,
8283
&validated_cluster.image,
8384
) {
84-
cm_builder.add_data(LOG_CONFIG_FILE, log_config);
85+
cm_builder.add_data(ConfigFileName::LogConfig.to_string(), log_config);
8586
}
8687

8788
// Vector agent config

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use stackable_operator::{
5454
use strum::{Display, EnumIter, EnumString};
5555

5656
use crate::{
57-
controller::ValidatedCluster,
57+
controller::{ValidatedCluster, build::properties::ConfigFileName},
5858
crd::{
5959
affinity::{get_affinity, get_executor_affinity},
6060
authentication::{
@@ -80,7 +80,6 @@ pub const OPERATOR_NAME: &str = "airflow.stackable.tech";
8080
pub const CONFIG_PATH: &str = "/stackable/app/config";
8181
pub const LOG_CONFIG_DIR: &str = "/stackable/app/log_config";
8282
pub const AIRFLOW_HOME: &str = "/stackable/airflow";
83-
pub const AIRFLOW_CONFIG_FILENAME: &str = "webserver_config.py";
8483

8584
stackable_operator::constant!(pub TEMPLATE_VOLUME_NAME: VolumeName = "airflow-executor-pod-template");
8685
pub const TEMPLATE_LOCATION: &str = "/templates";
@@ -551,11 +550,10 @@ impl AirflowRole {
551550
let database_initialization_enabled =
552551
cluster.cluster_config.database_initialization_enabled;
553552
let has_dag_processors = cluster.has_role(&AirflowRole::DagProcessor);
553+
let webserver_config = ConfigFileName::WebserverConfig;
554554

555555
let mut command = vec![
556-
format!(
557-
"cp -RL {CONFIG_PATH}/{AIRFLOW_CONFIG_FILENAME} {AIRFLOW_HOME}/{AIRFLOW_CONFIG_FILENAME}"
558-
),
556+
format!("cp -RL {CONFIG_PATH}/{webserver_config} {AIRFLOW_HOME}/{webserver_config}"),
559557
// graceful shutdown part
560558
COMMON_BASH_TRAP_FUNCTIONS.to_string(),
561559
remove_vector_shutdown_file_command(STACKABLE_LOG_DIR),

0 commit comments

Comments
 (0)