@@ -26,7 +26,10 @@ use stackable_operator::{
2626 ServicePort , ServiceSpec , TCPSocketAction , Volume ,
2727 } ,
2828 } ,
29- apimachinery:: pkg:: { apis:: meta:: v1:: LabelSelector , util:: intstr:: IntOrString } ,
29+ apimachinery:: pkg:: {
30+ apis:: meta:: v1:: { LabelSelector , ObjectMeta } ,
31+ util:: intstr:: IntOrString ,
32+ } ,
3033 } ,
3134 kube:: {
3235 Resource , ResourceExt ,
@@ -49,7 +52,13 @@ use stackable_operator::{
4952 compute_conditions, operations:: ClusterOperationsConditionBuilder ,
5053 statefulset:: StatefulSetConditionBuilder ,
5154 } ,
52- v2:: types:: operator:: ClusterName ,
55+ v2:: {
56+ HasName , HasUid , NameIsValidLabelValue ,
57+ types:: {
58+ kubernetes:: { NamespaceName , Uid } ,
59+ operator:: ClusterName ,
60+ } ,
61+ } ,
5362} ;
5463use strum:: { EnumDiscriminants , IntoStaticStr } ;
5564
@@ -90,16 +99,100 @@ pub struct Ctx {
9099/// every role and role group before any resources are created.
91100#[ derive( Clone , Debug ) ]
92101pub struct ValidatedCluster {
102+ /// Backs the [`Resource`] implementation (provides `meta()`/`name_any()`) so the build
103+ /// functions can derive `ObjectMeta`, owner references and labels without the full
104+ /// `HbaseCluster` object. Holds only name, namespace and uid.
105+ metadata : ObjectMeta ,
93106 /// The logical (and Kubernetes object) name of the cluster.
94- // Populated now; consumed by the new build path in a later commit.
95- #[ allow( dead_code) ]
96107 pub name : ClusterName ,
108+ /// The namespace the cluster lives in. Part of the cluster identity; currently consumed via
109+ /// the [`Resource`] metadata (`name_and_namespace`) rather than read directly.
110+ #[ allow( dead_code) ]
111+ pub namespace : NamespaceName ,
112+ /// The UID of the `HbaseCluster` object, used to build owner references.
113+ pub uid : Uid ,
97114 pub image : ResolvedProductImage ,
98115 pub cluster_config : ValidatedClusterConfig ,
99116 pub role_group_configs : BTreeMap < HbaseRole , BTreeMap < String , ValidatedRoleGroupConfig > > ,
100117 pub role_configs : BTreeMap < HbaseRole , ValidatedRoleConfig > ,
101118}
102119
120+ impl ValidatedCluster {
121+ #[ allow( clippy:: too_many_arguments) ]
122+ pub fn new (
123+ name : ClusterName ,
124+ namespace : NamespaceName ,
125+ uid : Uid ,
126+ image : ResolvedProductImage ,
127+ cluster_config : ValidatedClusterConfig ,
128+ role_group_configs : BTreeMap < HbaseRole , BTreeMap < String , ValidatedRoleGroupConfig > > ,
129+ role_configs : BTreeMap < HbaseRole , ValidatedRoleConfig > ,
130+ ) -> Self {
131+ Self {
132+ metadata : ObjectMeta {
133+ name : Some ( name. to_string ( ) ) ,
134+ namespace : Some ( namespace. to_string ( ) ) ,
135+ uid : Some ( uid. to_string ( ) ) ,
136+ ..ObjectMeta :: default ( )
137+ } ,
138+ name,
139+ namespace,
140+ uid,
141+ image,
142+ cluster_config,
143+ role_group_configs,
144+ role_configs,
145+ }
146+ }
147+ }
148+
149+ impl Resource for ValidatedCluster {
150+ type DynamicType = <v1alpha1:: HbaseCluster as Resource >:: DynamicType ;
151+ type Scope = <v1alpha1:: HbaseCluster as Resource >:: Scope ;
152+
153+ fn group ( dt : & Self :: DynamicType ) -> std:: borrow:: Cow < ' _ , str > {
154+ v1alpha1:: HbaseCluster :: group ( dt)
155+ }
156+
157+ fn version ( dt : & Self :: DynamicType ) -> std:: borrow:: Cow < ' _ , str > {
158+ v1alpha1:: HbaseCluster :: version ( dt)
159+ }
160+
161+ fn kind ( dt : & Self :: DynamicType ) -> std:: borrow:: Cow < ' _ , str > {
162+ v1alpha1:: HbaseCluster :: kind ( dt)
163+ }
164+
165+ fn plural ( dt : & Self :: DynamicType ) -> std:: borrow:: Cow < ' _ , str > {
166+ v1alpha1:: HbaseCluster :: plural ( dt)
167+ }
168+
169+ fn meta ( & self ) -> & ObjectMeta {
170+ & self . metadata
171+ }
172+
173+ fn meta_mut ( & mut self ) -> & mut ObjectMeta {
174+ & mut self . metadata
175+ }
176+ }
177+
178+ impl HasName for ValidatedCluster {
179+ fn to_name ( & self ) -> String {
180+ self . name . to_string ( )
181+ }
182+ }
183+
184+ impl HasUid for ValidatedCluster {
185+ fn to_uid ( & self ) -> Uid {
186+ self . uid . clone ( )
187+ }
188+ }
189+
190+ impl NameIsValidLabelValue for ValidatedCluster {
191+ fn to_label_value ( & self ) -> String {
192+ self . name . to_label_value ( )
193+ }
194+ }
195+
103196/// Cluster-wide settings resolved once during validation.
104197#[ derive( Clone , Debug ) ]
105198pub struct ValidatedClusterConfig {
@@ -353,7 +446,6 @@ pub async fn reconcile_hbase(
353446 & validated_cluster,
354447 hbase_role,
355448 & rolegroup,
356- hbase,
357449 )
358450 . context ( BuildRolegroupConfigMapSnafu ) ?;
359451 let rg_statefulset = build_rolegroup_statefulset (
@@ -411,8 +503,8 @@ pub async fn reconcile_hbase(
411503
412504 // Discovery CM will fail to build until the rest of the cluster has been deployed, so do it last
413505 // so that failure won't inhibit the rest of the cluster from booting up.
414- let discovery_cm = build_discovery_config_map ( & validated_cluster , hbase )
415- . context ( BuildDiscoveryConfigMapSnafu ) ?;
506+ let discovery_cm =
507+ build_discovery_config_map ( & validated_cluster ) . context ( BuildDiscoveryConfigMapSnafu ) ?;
416508 cluster_resources
417509 . add ( client, discovery_cm)
418510 . await
@@ -881,12 +973,12 @@ pub fn error_policy(
881973 }
882974}
883975
884- pub fn build_recommended_labels < ' a > (
885- owner : & ' a v1alpha1 :: HbaseCluster ,
976+ pub fn build_recommended_labels < ' a , R > (
977+ owner : & ' a R ,
886978 app_version : & ' a str ,
887979 role : & ' a str ,
888980 role_group : & ' a str ,
889- ) -> ObjectLabels < ' a , v1alpha1 :: HbaseCluster > {
981+ ) -> ObjectLabels < ' a , R > {
890982 ObjectLabels {
891983 owner,
892984 app_name : APP_NAME ,
0 commit comments