Skip to content

Commit 70f457d

Browse files
committed
renamed controller, moved validated structs into controller/mod.rs, added validated cluster usage in place of raw cluster in some places
1 parent 085af20 commit 70f457d

15 files changed

Lines changed: 195 additions & 174 deletions

File tree

rust/operator-binary/src/controller/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Builders that assemble Kubernetes resources from a [`ValidatedCluster`].
22
//!
3-
//! [`ValidatedCluster`]: crate::controller::validate::ValidatedCluster
3+
//! [`ValidatedCluster`]: crate::controller::ValidatedCluster
44
55
pub mod config_map;
66
pub mod git_sync;

rust/operator-binary/src/controller/build/config_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use stackable_operator::{
1313

1414
use crate::{
1515
controller::{
16+
ValidatedCluster,
1617
build::{
1718
git_sync,
1819
properties::{
@@ -21,7 +22,6 @@ use crate::{
2122
},
2223
proxy_hosts,
2324
},
24-
validate::ValidatedCluster,
2525
},
2626
crd::{NifiRole, v1alpha1},
2727
};
@@ -80,7 +80,7 @@ type Result<T, E = Error> = std::result::Result<T, E>;
8080
pub fn build_rolegroup_config_map(
8181
cluster: &ValidatedCluster,
8282
rolegroup: &RoleGroupRef<v1alpha1::NifiCluster>,
83-
recommended_labels: &ObjectLabels<'_, v1alpha1::NifiCluster>,
83+
recommended_labels: &ObjectLabels<'_, ValidatedCluster>,
8484
cluster_info: &KubernetesClusterInfo,
8585
) -> Result<ConfigMap> {
8686
tracing::debug!("building rolegroup ConfigMap");

rust/operator-binary/src/controller/build/git_sync.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ use snafu::{ResultExt, Snafu};
44
use stackable_operator::{crd::git_sync, k8s_openapi::api::core::v1::EnvVar};
55

66
use crate::{
7-
controller::{
8-
LOG_VOLUME_NAME,
9-
validate::{NifiRoleGroupConfig, ValidatedCluster},
10-
},
7+
controller::{ValidatedCluster, validate::NifiRoleGroupConfig},
118
crd::Container,
9+
nifi_controller::LOG_VOLUME_NAME,
1210
};
1311

1412
#[derive(Snafu, Debug)]

rust/operator-binary/src/controller/build/properties.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub(crate) mod test_support {
6969
};
7070

7171
use crate::{
72-
controller::validate::{NifiRoleGroupConfig, ValidatedCluster, ValidatedClusterConfig},
72+
controller::{ValidatedCluster, ValidatedClusterConfig, validate::NifiRoleGroupConfig},
7373
crd::{NifiConfig, NifiRole, v1alpha1},
7474
framework::role_utils::with_validated_config,
7575
security::{

rust/operator-binary/src/controller/build/properties/authorizers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Builder for `authorizers.xml`.
22
3-
use crate::controller::validate::ValidatedCluster;
3+
use crate::controller::ValidatedCluster;
44

55
pub fn build(cluster: &ValidatedCluster) -> String {
66
cluster

rust/operator-binary/src/controller/build/properties/login_identity_providers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Builder for `login-identity-providers.xml`.
22
3-
use crate::controller::validate::ValidatedCluster;
3+
use crate::controller::ValidatedCluster;
44

55
pub fn build(cluster: &ValidatedCluster) -> Result<String, crate::security::authentication::Error> {
66
cluster

rust/operator-binary/src/controller/build/properties/nifi_properties.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
CalculateStorageQuotaSnafu, Error, GenerateOidcConfigSnafu, NIFI_PYTHON_WORKING_DIRECTORY,
1111
Nifi1RequiresZookeeperSnafu, NifiRepository, format_properties,
1212
},
13-
controller::validate::{NifiRoleGroupConfig, ValidatedCluster},
13+
controller::{ValidatedCluster, validate::NifiRoleGroupConfig},
1414
crd::{HTTPS_PORT, v1alpha1},
1515
security::{
1616
authentication::{

rust/operator-binary/src/controller/build/proxy_hosts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::collections::HashSet;
44

55
use stackable_operator::utils::cluster_info::KubernetesClusterInfo;
66

7-
use crate::{controller::validate::ValidatedCluster, crd::HTTPS_PORT, reporting_task};
7+
use crate::{controller::ValidatedCluster, crd::HTTPS_PORT, reporting_task};
88

99
/// Computes the comma-separated NiFi proxy hosts, or `"*"` if `hostHeaderCheck.allowAll` is set.
1010
///
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
//! Controller-level vocabulary: the [`ValidatedCluster`] type produced by the
2+
//! [`validate`] step and consumed by the [`build`] steps, plus the
3+
//! `dereference` / `validate` / `build` sub-modules.
4+
5+
use std::collections::BTreeMap;
6+
7+
use stackable_operator::{
8+
commons::product_image_selection::ResolvedProductImage,
9+
crd::git_sync,
10+
k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta,
11+
kube::Resource,
12+
v2::{
13+
HasName, HasUid,
14+
types::{
15+
kubernetes::{NamespaceName, Uid},
16+
operator::ClusterName,
17+
},
18+
},
19+
};
20+
21+
use crate::{
22+
crd::{
23+
HostHeaderCheckConfig, NifiRole, NifiRoleType,
24+
sensitive_properties::NifiSensitiveKeyAlgorithm, v1alpha1,
25+
},
26+
security::{
27+
authentication::NifiAuthenticationConfig, authorization::ResolvedNifiAuthorizationConfig,
28+
},
29+
};
30+
31+
pub(crate) mod build;
32+
pub(crate) mod dereference;
33+
pub(crate) mod validate;
34+
35+
use validate::NifiRoleGroupConfig;
36+
37+
/// The validated NifiCluster: everything `reconcile_nifi` needs after dereferencing,
38+
/// in fail-safe / resolved form. This is the single resolved representation of the cluster;
39+
/// downstream builders should source everything from here and never touch the raw `NifiCluster`.
40+
pub struct ValidatedCluster {
41+
/// Synthetic metadata (name, namespace, uid) so `ValidatedCluster` can implement
42+
/// [`Resource`] and be used to build OwnerReferences without the raw `NifiCluster`.
43+
metadata: ObjectMeta,
44+
/// The name of the NifiCluster.
45+
pub name: ClusterName,
46+
/// The namespace of the NifiCluster, parsed once in the dereference step and reused everywhere.
47+
pub namespace: NamespaceName,
48+
/// The UID of the NifiCluster, used to build OwnerReferences downstream.
49+
pub uid: Uid,
50+
/// The product image.
51+
pub image: ResolvedProductImage,
52+
/// Cluster wide settings.
53+
pub cluster_config: ValidatedClusterConfig,
54+
/// The raw Node role spec (`spec.nodes`), needed for JVM argument merging in `bootstrap.conf`.
55+
pub nodes: NifiRoleType,
56+
/// Collected configuration per rolegroup.
57+
pub role_group_configs: BTreeMap<NifiRole, BTreeMap<String, NifiRoleGroupConfig>>,
58+
}
59+
60+
/// The resolved `spec.clusterConfig`.
61+
pub struct ValidatedClusterConfig {
62+
/// The cluster authentication settings.
63+
pub authentication: NifiAuthenticationConfig,
64+
/// The cluster authorization settings.
65+
pub authorization: ResolvedNifiAuthorizationConfig,
66+
/// The git-sync specs, resolved into git-sync resources at build time.
67+
pub custom_components_git_sync: Vec<git_sync::v1alpha2::GitSync>,
68+
/// The clustering backend (ZooKeeper or Kubernetes), copied from the spec.
69+
pub clustering_backend: v1alpha1::NifiClusteringBackend,
70+
/// The host-header-check config, resolved into the proxy hosts allow-list at build time.
71+
pub host_header_check: HostHeaderCheckConfig,
72+
/// The validated sensitive properties algorithm.
73+
pub sensitive_properties_algorithm: NifiSensitiveKeyAlgorithm,
74+
}
75+
76+
impl ValidatedCluster {
77+
/// Builds a [`ValidatedCluster`], deriving the synthetic [`ObjectMeta`] from name, namespace
78+
/// and uid so the struct can implement [`Resource`].
79+
pub fn new(
80+
name: ClusterName,
81+
namespace: NamespaceName,
82+
uid: Uid,
83+
image: ResolvedProductImage,
84+
nodes: NifiRoleType,
85+
role_group_configs: BTreeMap<NifiRole, BTreeMap<String, NifiRoleGroupConfig>>,
86+
cluster_config: ValidatedClusterConfig,
87+
) -> Self {
88+
let metadata = ObjectMeta {
89+
name: Some(name.to_string()),
90+
namespace: Some(namespace.to_string()),
91+
uid: Some(uid.to_string()),
92+
..ObjectMeta::default()
93+
};
94+
95+
Self {
96+
metadata,
97+
name,
98+
namespace,
99+
uid,
100+
image,
101+
nodes,
102+
role_group_configs,
103+
cluster_config,
104+
}
105+
}
106+
}
107+
108+
impl HasName for ValidatedCluster {
109+
fn to_name(&self) -> String {
110+
self.name.to_string()
111+
}
112+
}
113+
114+
impl HasUid for ValidatedCluster {
115+
fn to_uid(&self) -> Uid {
116+
self.uid.clone()
117+
}
118+
}
119+
120+
impl Resource for ValidatedCluster {
121+
type DynamicType = <v1alpha1::NifiCluster as Resource>::DynamicType;
122+
type Scope = <v1alpha1::NifiCluster as Resource>::Scope;
123+
124+
fn kind(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
125+
v1alpha1::NifiCluster::kind(dt)
126+
}
127+
128+
fn group(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
129+
v1alpha1::NifiCluster::group(dt)
130+
}
131+
132+
fn version(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
133+
v1alpha1::NifiCluster::version(dt)
134+
}
135+
136+
fn plural(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
137+
v1alpha1::NifiCluster::plural(dt)
138+
}
139+
140+
fn meta(&self) -> &ObjectMeta {
141+
&self.metadata
142+
}
143+
144+
fn meta_mut(&mut self) -> &mut ObjectMeta {
145+
&mut self.metadata
146+
}
147+
}

rust/operator-binary/src/controller/validate.rs

Lines changed: 6 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,17 @@ use std::collections::BTreeMap;
88
use snafu::{OptionExt, ResultExt, Snafu};
99
use stackable_operator::{
1010
cli::OperatorEnvironmentOptions,
11-
commons::product_image_selection::{self, ResolvedProductImage},
12-
crd::git_sync,
13-
k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta,
14-
kube::{Resource, ResourceExt as _},
11+
commons::product_image_selection,
12+
kube::ResourceExt as _,
1513
role_utils::JavaCommonConfig,
16-
v2::{
17-
HasName, HasUid,
18-
controller_utils::{self, get_cluster_name, get_uid},
19-
types::{
20-
kubernetes::{NamespaceName, Uid},
21-
operator::ClusterName,
22-
},
23-
},
14+
v2::controller_utils::{self, get_cluster_name, get_uid},
2415
};
2516
use strum::{EnumDiscriminants, IntoStaticStr};
2617

18+
use super::{ValidatedCluster, ValidatedClusterConfig};
2719
use crate::{
2820
controller::dereference::DereferencedObjects,
29-
crd::{
30-
HostHeaderCheckConfig, NifiConfig, NifiRole, NifiRoleType, sensitive_properties,
31-
sensitive_properties::NifiSensitiveKeyAlgorithm, v1alpha1,
32-
},
21+
crd::{NifiConfig, NifiRole, sensitive_properties, v1alpha1},
3322
framework::role_utils::with_validated_config,
3423
security::{
3524
authentication::{self, NifiAuthenticationConfig},
@@ -75,118 +64,6 @@ pub type NifiRoleGroupConfig = crate::framework::role_utils::RoleGroupConfig<
7564

7665
type Result<T, E = Error> = std::result::Result<T, E>;
7766

78-
/// The validated NifiCluster: everything `reconcile_nifi` needs after dereferencing,
79-
/// in fail-safe / resolved form. This is the single resolved representation of the cluster;
80-
/// downstream builders should source everything from here and never touch the raw `NifiCluster`.
81-
pub struct ValidatedCluster {
82-
/// Synthetic metadata (name, namespace, uid) so `ValidatedCluster` can implement
83-
/// [`Resource`] and be used to build OwnerReferences without the raw `NifiCluster`.
84-
metadata: ObjectMeta,
85-
/// The name of the NifiCluster.
86-
pub name: ClusterName,
87-
/// The namespace of the NifiCluster, parsed once in the dereference step and reused everywhere.
88-
pub namespace: NamespaceName,
89-
/// The UID of the NifiCluster, used to build OwnerReferences downstream.
90-
pub uid: Uid,
91-
/// The product image.
92-
pub image: ResolvedProductImage,
93-
/// Cluster wide settings.
94-
pub cluster_config: ValidatedClusterConfig,
95-
/// The raw Node role spec (`spec.nodes`), needed for JVM argument merging in `bootstrap.conf`.
96-
pub nodes: NifiRoleType,
97-
/// Collected configuration per rolegroup.
98-
pub role_group_configs: BTreeMap<NifiRole, BTreeMap<String, NifiRoleGroupConfig>>,
99-
}
100-
101-
/// The resolved `spec.clusterConfig`.
102-
pub struct ValidatedClusterConfig {
103-
/// The cluster authentication settings.
104-
pub authentication: NifiAuthenticationConfig,
105-
/// The cluster authorization settings.
106-
pub authorization: ResolvedNifiAuthorizationConfig,
107-
/// The git-sync specs, resolved into git-sync resources at build time.
108-
pub custom_components_git_sync: Vec<git_sync::v1alpha2::GitSync>,
109-
/// The clustering backend (ZooKeeper or Kubernetes), copied from the spec.
110-
pub clustering_backend: v1alpha1::NifiClusteringBackend,
111-
/// The host-header-check config, resolved into the proxy hosts allow-list at build time.
112-
pub host_header_check: HostHeaderCheckConfig,
113-
/// The validated sensitive properties algorithm.
114-
pub sensitive_properties_algorithm: NifiSensitiveKeyAlgorithm,
115-
}
116-
117-
impl ValidatedCluster {
118-
/// Builds a [`ValidatedCluster`], deriving the synthetic [`ObjectMeta`] from name, namespace
119-
/// and uid so the struct can implement [`Resource`].
120-
pub fn new(
121-
name: ClusterName,
122-
namespace: NamespaceName,
123-
uid: Uid,
124-
image: ResolvedProductImage,
125-
nodes: NifiRoleType,
126-
role_group_configs: BTreeMap<NifiRole, BTreeMap<String, NifiRoleGroupConfig>>,
127-
cluster_config: ValidatedClusterConfig,
128-
) -> Self {
129-
let metadata = ObjectMeta {
130-
name: Some(name.to_string()),
131-
namespace: Some(namespace.to_string()),
132-
uid: Some(uid.to_string()),
133-
..ObjectMeta::default()
134-
};
135-
136-
Self {
137-
metadata,
138-
name,
139-
namespace,
140-
uid,
141-
image,
142-
nodes,
143-
role_group_configs,
144-
cluster_config,
145-
}
146-
}
147-
}
148-
149-
impl HasName for ValidatedCluster {
150-
fn to_name(&self) -> String {
151-
self.name.to_string()
152-
}
153-
}
154-
155-
impl HasUid for ValidatedCluster {
156-
fn to_uid(&self) -> Uid {
157-
self.uid.clone()
158-
}
159-
}
160-
161-
impl Resource for ValidatedCluster {
162-
type DynamicType = <v1alpha1::NifiCluster as Resource>::DynamicType;
163-
type Scope = <v1alpha1::NifiCluster as Resource>::Scope;
164-
165-
fn kind(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
166-
v1alpha1::NifiCluster::kind(dt)
167-
}
168-
169-
fn group(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
170-
v1alpha1::NifiCluster::group(dt)
171-
}
172-
173-
fn version(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
174-
v1alpha1::NifiCluster::version(dt)
175-
}
176-
177-
fn plural(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
178-
v1alpha1::NifiCluster::plural(dt)
179-
}
180-
181-
fn meta(&self) -> &ObjectMeta {
182-
&self.metadata
183-
}
184-
185-
fn meta_mut(&mut self) -> &mut ObjectMeta {
186-
&mut self.metadata
187-
}
188-
}
189-
19067
/// Validates the cluster spec and the dereferenced inputs.
19168
pub fn validate(
19269
nifi: &v1alpha1::NifiCluster,
@@ -197,7 +74,7 @@ pub fn validate(
19774
.spec
19875
.image
19976
.resolve(
200-
super::CONTAINER_IMAGE_BASE_NAME,
77+
crate::nifi_controller::CONTAINER_IMAGE_BASE_NAME,
20178
&operator_environment.image_repository,
20279
crate::built_info::PKG_VERSION,
20380
)

0 commit comments

Comments
 (0)