-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvalidate.rs
More file actions
122 lines (103 loc) · 3.87 KB
/
Copy pathvalidate.rs
File metadata and controls
122 lines (103 loc) · 3.87 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
use std::{collections::BTreeMap, str::FromStr};
use product_config::ProductConfigManager;
use snafu::{ResultExt, Snafu};
use stackable_operator::{
commons::product_image_selection::{self},
product_config_utils::{transform_all_roles_to_config, validate_all_roles_and_groups_config},
role_utils::GenericRoleConfig,
};
use crate::{
controller::dereference::DereferencedObjects,
crd::{HbaseRole, v1alpha1},
hbase_controller::{
CONTAINER_IMAGE_BASE_NAME, ValidatedCluster, ValidatedRoleConfig, ValidatedRoleGroupConfig,
},
};
#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("failed to resolve product image"))]
ResolveProductImage {
source: product_image_selection::Error,
},
#[snafu(display("invalid role properties"))]
RoleProperties { source: crate::crd::Error },
#[snafu(display("failed to generate product config"))]
GenerateProductConfig {
source: stackable_operator::product_config_utils::Error,
},
#[snafu(display("invalid product config"))]
InvalidProductConfig {
source: stackable_operator::product_config_utils::Error,
},
#[snafu(display("could not parse Hbase role [{role}]"))]
UnidentifiedHbaseRole {
source: strum::ParseError,
role: String,
},
#[snafu(display("failed to resolve and merge config for role and role group"))]
FailedToResolveConfig { source: crate::crd::Error },
}
pub fn validate_cluster(
hbase: &v1alpha1::HbaseCluster,
image_repository: &str,
product_config_manager: &ProductConfigManager,
dereferenced_objects: DereferencedObjects,
) -> Result<ValidatedCluster, Error> {
let resolved_product_image = hbase
.spec
.image
.resolve(
CONTAINER_IMAGE_BASE_NAME,
image_repository,
crate::built_info::PKG_VERSION,
)
.context(ResolveProductImageSnafu)?;
let roles = hbase.build_role_properties().context(RolePropertiesSnafu)?;
let validated_config = validate_all_roles_and_groups_config(
&resolved_product_image.product_version,
&transform_all_roles_to_config(hbase, &roles).context(GenerateProductConfigSnafu)?,
product_config_manager,
false,
false,
)
.context(InvalidProductConfigSnafu)?;
let mut role_groups = BTreeMap::new();
let mut role_configs = BTreeMap::new();
for (role_name, group_config) in validated_config.iter() {
let hbase_role = HbaseRole::from_str(role_name).context(UnidentifiedHbaseRoleSnafu {
role: role_name.to_string(),
})?;
if let Some(GenericRoleConfig {
pod_disruption_budget: pdb,
}) = hbase.role_config(&hbase_role)
{
role_configs.insert(hbase_role.clone(), ValidatedRoleConfig { pdb: pdb.clone() });
}
let mut group_configs = BTreeMap::new();
for (rolegroup_name, rolegroup_config) in group_config.iter() {
let rolegroup = hbase.server_rolegroup_ref(role_name, rolegroup_name);
let merged_config = hbase
.merged_config(
&hbase_role,
&rolegroup.role_group,
&hbase.spec.cluster_config.hdfs_config_map_name,
)
.context(FailedToResolveConfigSnafu)?;
group_configs.insert(
rolegroup_name.clone(),
ValidatedRoleGroupConfig {
merged_config,
product_config_properties: rolegroup_config.clone(),
},
);
}
role_groups.insert(hbase_role, group_configs);
}
Ok(ValidatedCluster {
image: resolved_product_image,
role_groups,
role_configs,
zookeeper_connection_information: dereferenced_objects.zookeeper_connection_information,
hbase_opa_config: dereferenced_objects.hbase_opa_config,
})
}