-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathvalidate.rs
More file actions
65 lines (55 loc) · 2.02 KB
/
Copy pathvalidate.rs
File metadata and controls
65 lines (55 loc) · 2.02 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
//! The validate step in the ZookeeperZnode controller.
//!
//! Synchronously validates inputs that don't require a Kubernetes client. Produces
//! [`ValidatedInputs`], consumed by the rest of `reconcile_znode`.
use snafu::{ResultExt, Snafu};
use stackable_operator::{
cli::OperatorEnvironmentOptions,
commons::product_image_selection::{self, ResolvedProductImage},
};
use crate::{
crd::{CONTAINER_IMAGE_BASE_NAME, authentication, security::ZookeeperSecurity, v1alpha1},
znode_controller::dereference::DereferencedObjects,
};
#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("failed to resolve product image"))]
ResolveProductImage {
source: product_image_selection::Error,
},
#[snafu(display("failed to validate authentication classes"))]
InvalidAuthenticationClassConfiguration { source: authentication::Error },
}
type Result<T, E = Error> = std::result::Result<T, E>;
/// Synchronous inputs the rest of `reconcile_znode` needs after dereferencing.
pub struct ValidatedInputs {
pub resolved_product_image: ResolvedProductImage,
pub zookeeper_security: ZookeeperSecurity,
}
/// Validates the dereferenced inputs.
pub fn validate(
_znode: &v1alpha1::ZookeeperZnode,
dereferenced_objects: &DereferencedObjects,
operator_environment: &OperatorEnvironmentOptions,
) -> Result<ValidatedInputs> {
let resolved_product_image = dereferenced_objects
.zk
.spec
.image
.resolve(
CONTAINER_IMAGE_BASE_NAME,
&operator_environment.image_repository,
crate::built_info::PKG_VERSION,
)
.context(ResolveProductImageSnafu)?;
let resolved_authentication_classes = dereferenced_objects
.authentication_classes
.validate()
.context(InvalidAuthenticationClassConfigurationSnafu)?;
let zookeeper_security =
ZookeeperSecurity::new(&dereferenced_objects.zk, resolved_authentication_classes);
Ok(ValidatedInputs {
resolved_product_image,
zookeeper_security,
})
}