-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconfig_map.rs
More file actions
96 lines (84 loc) · 3.18 KB
/
Copy pathconfig_map.rs
File metadata and controls
96 lines (84 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! Builds the rolegroup [`ConfigMap`]: the rendered `webserver_config.py` plus the
//! logging/vector configuration.
use std::collections::BTreeMap;
use snafu::{ResultExt, Snafu};
use stackable_operator::{
builder::configmap::ConfigMapBuilder,
k8s_openapi::api::core::v1::ConfigMap,
product_logging::framework::VECTOR_CONFIG_FILE,
v2::{
product_logging::framework::STACKABLE_LOG_DIR,
types::operator::{RoleGroupName, RoleName},
},
};
use crate::{
controller::{
ValidatedCluster, ValidatedLogging,
build::properties::{
ConfigFileName,
product_logging::{create_airflow_config, vector_config_file_content},
webserver_config,
},
},
crd::{AirflowConfigOverrides, Container},
};
#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("failed to build webserver config for role group {role_group}"))]
BuildWebserverConfig {
source: webserver_config::Error,
role_group: RoleGroupName,
},
#[snafu(display("failed to build ConfigMap for role group {role_group}"))]
BuildConfigMap {
source: stackable_operator::builder::configmap::Error,
role_group: RoleGroupName,
},
}
/// The rolegroup [`ConfigMap`] configures the rolegroup based on the configuration given by the administrator
pub fn build_rolegroup_config_map(
validated_cluster: &ValidatedCluster,
role_name: &RoleName,
role_group_name: &RoleGroupName,
config_overrides: &AirflowConfigOverrides,
logging: &ValidatedLogging,
container: &Container,
) -> Result<ConfigMap, Error> {
// Flatten the typed `webserver_config.py` overrides into a plain map for the file writer.
let config_file_overrides: BTreeMap<String, String> =
config_overrides.webserver_config_py.overrides.clone();
let config_file = webserver_config::build(validated_cluster, &config_file_overrides)
.with_context(|_| BuildWebserverConfigSnafu {
role_group: role_group_name.clone(),
})?;
let mut cm_builder = ConfigMapBuilder::new();
cm_builder
.metadata(
validated_cluster
.object_meta(
validated_cluster
.role_group_resource_names(role_name, role_group_name)
.role_group_config_map()
.to_string(),
validated_cluster.recommended_labels_for(role_name, role_group_name),
)
.build(),
)
.add_data(ConfigFileName::WebserverConfig.to_string(), config_file);
// Log config for the main container, when it uses an Automatic log config.
let log_dir = format!("{STACKABLE_LOG_DIR}/{container}");
if let Some(log_config) = create_airflow_config(
&logging.product_container,
&log_dir,
&validated_cluster.image,
) {
cm_builder.add_data(ConfigFileName::LogConfig.to_string(), log_config);
}
// Vector agent config
if logging.enable_vector_agent {
cm_builder.add_data(VECTOR_CONFIG_FILE, vector_config_file_content());
}
cm_builder.build().with_context(|_| BuildConfigMapSnafu {
role_group: role_group_name.clone(),
})
}