-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdereference.rs
More file actions
74 lines (63 loc) · 2.46 KB
/
Copy pathdereference.rs
File metadata and controls
74 lines (63 loc) · 2.46 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
//! The dereference step in the NifiCluster controller
//!
//! Fetches all Kubernetes objects referenced by the NifiCluster spec and returns
//! them in [`DereferencedObjects`].
use snafu::{ResultExt, Snafu};
use stackable_operator::{
client::Client,
commons::networking::DomainName,
v2::{
controller_utils::{self, get_namespace},
types::kubernetes::NamespaceName,
},
};
use crate::{
crd::v1alpha1,
security::{
authentication::{self, DereferencedAuthenticationClasses},
authorization::{self as authorization_mod, DereferencedAuthorization},
},
};
#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("failed to get the namespace"))]
GetNamespace { source: controller_utils::Error },
#[snafu(display("failed to dereference NiFi authentication classes"))]
DereferenceAuthenticationClasses { source: authentication::Error },
#[snafu(display("failed to dereference NiFi authorization config"))]
DereferenceAuthorization { source: authorization_mod::Error },
}
type Result<T, E = Error> = std::result::Result<T, E>;
/// Kubernetes objects referenced from the [`v1alpha1::NifiCluster`] spec, already fetched.
pub struct DereferencedObjects {
/// The namespace of the [`v1alpha1::NifiCluster`], parsed once here and reused everywhere.
pub namespace: NamespaceName,
/// The Kubernetes cluster domain, captured from the client here so the build step needs no
/// client to assemble in-cluster DNS names.
pub cluster_domain: DomainName,
pub authentication_classes: DereferencedAuthenticationClasses,
pub authorization: DereferencedAuthorization,
}
/// Fetches all Kubernetes objects referenced from the [`v1alpha1::NifiCluster`] spec.
pub async fn dereference(
client: &Client,
nifi: &v1alpha1::NifiCluster,
) -> Result<DereferencedObjects> {
let namespace = get_namespace(nifi).context(GetNamespaceSnafu)?;
let authentication_classes = DereferencedAuthenticationClasses::dereference(nifi, client)
.await
.context(DereferenceAuthenticationClassesSnafu)?;
let authorization = DereferencedAuthorization::dereference(
&nifi.spec.cluster_config.authorization,
client,
namespace.as_ref(),
)
.await
.context(DereferenceAuthorizationSnafu)?;
Ok(DereferencedObjects {
namespace,
cluster_domain: client.kubernetes_cluster_info.cluster_domain.clone(),
authentication_classes,
authorization,
})
}