-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvalidate.rs
More file actions
89 lines (79 loc) · 2.63 KB
/
Copy pathvalidate.rs
File metadata and controls
89 lines (79 loc) · 2.63 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
//! The validate step in the OpaCluster controller
//!
//! Synchronously validates inputs that don't require a Kubernetes client. Produces
//! [`ValidatedInputs`], consumed by the rest of `reconcile_opa`.
use product_config::{ProductConfigManager, types::PropertyNameKind};
use snafu::{ResultExt, Snafu};
use stackable_operator::{
cli::OperatorEnvironmentOptions,
commons::product_image_selection::{self, ResolvedProductImage},
product_config_utils::{
ValidatedRoleConfigByPropertyKind, transform_all_roles_to_config,
validate_all_roles_and_groups_config,
},
};
use crate::crd::{OpaRole, v1alpha2};
#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("failed to resolve product image"))]
ResolveProductImage {
source: product_image_selection::Error,
},
#[snafu(display("failed to transform configs"))]
ProductConfigTransform {
source: stackable_operator::product_config_utils::Error,
},
#[snafu(display("invalid product config"))]
InvalidProductConfig {
source: stackable_operator::product_config_utils::Error,
},
}
type Result<T, E = Error> = std::result::Result<T, E>;
/// Synchronous inputs the rest of `reconcile_opa` needs after dereferencing.
pub struct ValidatedInputs {
pub image: ResolvedProductImage,
pub validated_role_config: ValidatedRoleConfigByPropertyKind,
}
/// Validates the cluster spec and the dereferenced inputs.
pub fn validate(
opa: &v1alpha2::OpaCluster,
operator_environment: &OperatorEnvironmentOptions,
product_config: &ProductConfigManager,
) -> Result<ValidatedInputs> {
let image = opa
.spec
.image
.resolve(
super::CONTAINER_IMAGE_BASE_NAME,
&operator_environment.image_repository,
crate::built_info::PKG_VERSION,
)
.context(ResolveProductImageSnafu)?;
let validated_role_config = validate_all_roles_and_groups_config(
&image.product_version,
&transform_all_roles_to_config(
opa,
&[(
OpaRole::Server.to_string(),
(
vec![
PropertyNameKind::File(super::CONFIG_FILE.to_string()),
PropertyNameKind::Env,
PropertyNameKind::Cli,
],
opa.spec.servers.clone(),
),
)]
.into(),
)
.context(ProductConfigTransformSnafu)?,
product_config,
false,
false,
)
.context(InvalidProductConfigSnafu)?;
Ok(ValidatedInputs {
image,
validated_role_config,
})
}