-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig_map.rs
More file actions
144 lines (128 loc) · 5.04 KB
/
Copy pathconfig_map.rs
File metadata and controls
144 lines (128 loc) · 5.04 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use snafu::{ResultExt, Snafu};
use stackable_operator::{
builder::configmap::ConfigMapBuilder, k8s_openapi::api::core::v1::ConfigMap,
product_logging::framework::VECTOR_CONFIG_FILE, v2::types::operator::RoleGroupName,
};
use crate::{
controller::{
ValidatedCluster, ValidatedSupersetConfig,
build::properties::{ConfigFileName, product_logging, superset_config},
},
crd::{SupersetRole, v1alpha1::SupersetConfigOverrides},
};
#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("failed to build {config_file} for role group {role_group_name}", config_file = ConfigFileName::SupersetConfig))]
SupersetConfig {
source: superset_config::Error,
role_group_name: RoleGroupName,
},
#[snafu(display("failed to build ConfigMap for role group {role_group_name}"))]
RoleGroupConfig {
source: stackable_operator::builder::configmap::Error,
role_group_name: RoleGroupName,
},
}
type Result<T, E = Error> = std::result::Result<T, E>;
/// The rolegroup [`ConfigMap`] configures the rolegroup based on the configuration given by the administrator
pub fn build_rolegroup_config_map(
validated: &ValidatedCluster,
role: &SupersetRole,
role_group_name: &RoleGroupName,
config: &ValidatedSupersetConfig,
config_overrides: &SupersetConfigOverrides,
) -> Result<ConfigMap, Error> {
let config_file = superset_config::build(validated, role, config, config_overrides)
.with_context(|_| SupersetConfigSnafu {
role_group_name: role_group_name.clone(),
})?;
let mut cm_builder = ConfigMapBuilder::new();
cm_builder
.metadata(
validated
.object_meta(
validated
.role_group_resource_names(role, role_group_name)
.role_group_config_map()
.to_string(),
role,
role_group_name,
)
.build(),
)
.add_data(ConfigFileName::SupersetConfig.to_string(), config_file);
if let Some(log_config) = product_logging::build_log_config(&config.logging.superset_container)
{
cm_builder.add_data(ConfigFileName::LogConfig.to_string(), log_config);
}
if let Some(vector_config) =
product_logging::build_vector_config(config.logging.enable_vector_agent)
{
cm_builder.add_data(VECTOR_CONFIG_FILE, vector_config);
}
cm_builder.build().with_context(|_| RoleGroupConfigSnafu {
role_group_name: role_group_name.clone(),
})
}
#[cfg(test)]
mod tests {
use stackable_operator::utils::yaml_from_str_singleton_map;
use super::*;
use crate::{
controller::{test_support::default_dereferenced, validate::validate_cluster},
crd::v1alpha1,
};
/// The rolegroup ConfigMap carries `superset_config.py` and (for automatic logging)
/// `log_config.py`, and omits `vector.yaml` while the Vector agent is disabled (the default).
#[test]
fn build_rolegroup_config_map_renders_expected_data() {
let input = r#"
apiVersion: superset.stackable.tech/v1alpha1
kind: SupersetCluster
metadata:
name: simple-superset
namespace: default
uid: 01234567-89ab-cdef-0123-456789abcdef
spec:
image:
productVersion: 4.1.4
clusterConfig:
credentialsSecret: superset-admin-credentials
metadataDatabase:
postgresql:
host: superset-postgresql
database: superset
credentialsSecretName: superset-postgresql-credentials
nodes:
roleGroups:
default:
replicas: 1
"#;
let superset: v1alpha1::SupersetCluster =
yaml_from_str_singleton_map(input).expect("illegal test input");
let validated =
validate_cluster(&superset, default_dereferenced(), "test-repo").expect("validated");
let role_group_name: RoleGroupName = "default".parse().expect("valid role group name");
let rolegroup_config = validated
.role_groups
.get(&SupersetRole::Node)
.and_then(|groups| groups.get(&role_group_name))
.expect("node default rolegroup");
let config_map = build_rolegroup_config_map(
&validated,
&SupersetRole::Node,
&role_group_name,
&rolegroup_config.config,
&rolegroup_config.config_overrides,
)
.expect("config map built");
let data = config_map.data.expect("config map has data");
assert!(data.contains_key("superset_config.py"));
assert!(data.contains_key("log_config.py"));
// The Vector agent is disabled by default, so no `vector.yaml` is rendered.
assert!(!data.contains_key("vector.yaml"));
let superset_config = &data["superset_config.py"];
assert!(superset_config.contains("SQLALCHEMY_DATABASE_URI"));
assert!(superset_config.contains("StatsdStatsLogger"));
}
}