-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvalidate.rs
More file actions
115 lines (97 loc) · 3.49 KB
/
Copy pathvalidate.rs
File metadata and controls
115 lines (97 loc) · 3.49 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
use std::{collections::BTreeMap, str::FromStr};
use product_config::ProductConfigManager;
use snafu::{ResultExt, Snafu};
use stackable_operator::{
commons::product_image_selection,
product_config_utils::{transform_all_roles_to_config, validate_all_roles_and_groups_config},
role_utils::GenericRoleConfig,
};
use crate::{
crd::{HdfsNodeRole, v1alpha1},
hdfs_controller::{
CONTAINER_IMAGE_BASE_NAME, ValidatedCluster, ValidatedRoleConfig, ValidatedRoleGroupConfig,
},
security::opa::HdfsOpaConfig,
};
#[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 configuration"))]
InvalidProductConfig {
source: stackable_operator::product_config_utils::Error,
},
#[snafu(display("could not parse HDFS role [{role}]"))]
UnidentifiedHdfsRole {
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(
hdfs: &v1alpha1::HdfsCluster,
image_repository: &str,
product_config_manager: &ProductConfigManager,
hdfs_opa_config: Option<HdfsOpaConfig>,
) -> Result<ValidatedCluster, Error> {
let resolved_product_image = hdfs
.spec
.image
.resolve(
CONTAINER_IMAGE_BASE_NAME,
image_repository,
crate::built_info::PKG_VERSION,
)
.context(ResolveProductImageSnafu)?;
let roles = hdfs.build_role_properties().context(RolePropertiesSnafu)?;
let validated_config = validate_all_roles_and_groups_config(
&resolved_product_image.product_version,
&transform_all_roles_to_config(hdfs, &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 hdfs_role = HdfsNodeRole::from_str(role_name).context(UnidentifiedHdfsRoleSnafu {
role: role_name.to_string(),
})?;
if let Some(GenericRoleConfig {
pod_disruption_budget: pdb,
}) = hdfs.role_config(&hdfs_role)
{
role_configs.insert(hdfs_role, ValidatedRoleConfig { pdb: pdb.clone() });
}
let mut group_configs = BTreeMap::new();
for (rolegroup_name, rolegroup_config) in group_config.iter() {
let merged_config = hdfs_role
.merged_config(hdfs, rolegroup_name)
.context(FailedToResolveConfigSnafu)?;
group_configs.insert(
rolegroup_name.clone(),
ValidatedRoleGroupConfig {
merged_config,
product_config_properties: rolegroup_config.clone(),
},
);
}
role_groups.insert(hdfs_role, group_configs);
}
Ok(ValidatedCluster {
image: resolved_product_image,
role_groups,
role_configs,
hdfs_opa_config,
})
}