@@ -8,28 +8,17 @@ use std::collections::BTreeMap;
88use snafu:: { OptionExt , ResultExt , Snafu } ;
99use 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} ;
2516use strum:: { EnumDiscriminants , IntoStaticStr } ;
2617
18+ use super :: { ValidatedCluster , ValidatedClusterConfig } ;
2719use 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
7665type 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.
19168pub 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