@@ -9,7 +9,7 @@ use std::{collections::BTreeMap, hash::Hasher, sync::Arc};
99use const_format:: concatcp;
1010use fnv:: FnvHasher ;
1111use indoc:: formatdoc;
12- use snafu:: { OptionExt , ResultExt , Snafu } ;
12+ use snafu:: { ResultExt , Snafu } ;
1313use stackable_operator:: {
1414 builder:: {
1515 self ,
@@ -48,6 +48,7 @@ use stackable_operator::{
4848 } ,
4949 kube:: {
5050 Resource , ResourceExt ,
51+ api:: ObjectMeta ,
5152 core:: { DeserializeGuard , error_boundary} ,
5253 runtime:: controller:: Action ,
5354 } ,
@@ -115,9 +116,6 @@ pub struct Ctx {
115116#[ strum_discriminants( derive( strum:: IntoStaticStr ) ) ]
116117#[ allow( clippy:: enum_variant_names) ]
117118pub enum Error {
118- #[ snafu( display( "object defines no namespace" ) ) ]
119- ObjectHasNoNamespace ,
120-
121119 #[ snafu( display( "failed to apply Service for {rolegroup}" ) ) ]
122120 ApplyRoleGroupService {
123121 source : stackable_operator:: cluster_resources:: Error ,
@@ -303,18 +301,82 @@ pub type HiveRoleGroupConfig = crate::framework::role_utils::RoleGroupConfig<
303301
304302/// The validated cluster: the typed, merged result of the validate step. Subsequent
305303/// build steps consume this struct instead of re-reading the raw CRD.
304+ ///
305+ /// The cluster identity (`name`, `namespace`, `uid`) is captured here so that owner
306+ /// references for child objects can be built straight from this struct
307+ /// (via its [`Resource`] impl) without threading the raw [`v1alpha1::HiveCluster`]
308+ /// around. This mirrors the opensearch-operator's `ValidatedCluster`.
306309pub struct ValidatedCluster {
307- /// The validated cluster name. Part of the validated cluster identity (mirrors the
308- /// shared `v2` framework / trino-operator); consumed as more logic migrates onto
309- /// `ValidatedCluster`.
310- #[ allow( dead_code) ]
310+ /// `ObjectMeta` carrying `name`, `namespace` and `uid`, so this struct can act as the
311+ /// owner [`Resource`] for child objects.
312+ metadata : ObjectMeta ,
311313 pub name : stackable_operator:: v2:: types:: operator:: ClusterName ,
314+ pub namespace : stackable_operator:: v2:: types:: kubernetes:: NamespaceName ,
312315 pub image : ResolvedProductImage ,
313316 pub role_config : Option < ValidatedRoleConfig > ,
314317 pub cluster_config : ValidatedClusterConfig ,
315318 pub role_group_configs : BTreeMap < HiveRole , BTreeMap < RoleGroupName , HiveRoleGroupConfig > > ,
316319}
317320
321+ impl ValidatedCluster {
322+ pub fn new (
323+ name : stackable_operator:: v2:: types:: operator:: ClusterName ,
324+ namespace : stackable_operator:: v2:: types:: kubernetes:: NamespaceName ,
325+ uid : stackable_operator:: v2:: types:: kubernetes:: Uid ,
326+ image : ResolvedProductImage ,
327+ role_config : Option < ValidatedRoleConfig > ,
328+ cluster_config : ValidatedClusterConfig ,
329+ role_group_configs : BTreeMap < HiveRole , BTreeMap < RoleGroupName , HiveRoleGroupConfig > > ,
330+ ) -> Self {
331+ Self {
332+ metadata : ObjectMeta {
333+ name : Some ( name. to_string ( ) ) ,
334+ namespace : Some ( namespace. to_string ( ) ) ,
335+ uid : Some ( uid. to_string ( ) ) ,
336+ ..ObjectMeta :: default ( )
337+ } ,
338+ name,
339+ namespace,
340+ image,
341+ role_config,
342+ cluster_config,
343+ role_group_configs,
344+ }
345+ }
346+ }
347+
348+ /// Lets [`ValidatedCluster`] stand in for the raw [`v1alpha1::HiveCluster`] when building owner
349+ /// references and metadata for child objects. Kind/group/version are delegated to the CRD; the
350+ /// `metadata` (name, namespace, uid) is captured during validation.
351+ impl Resource for ValidatedCluster {
352+ type DynamicType = <v1alpha1:: HiveCluster as Resource >:: DynamicType ;
353+ type Scope = <v1alpha1:: HiveCluster as Resource >:: Scope ;
354+
355+ fn kind ( dt : & Self :: DynamicType ) -> std:: borrow:: Cow < ' _ , str > {
356+ v1alpha1:: HiveCluster :: kind ( dt)
357+ }
358+
359+ fn group ( dt : & Self :: DynamicType ) -> std:: borrow:: Cow < ' _ , str > {
360+ v1alpha1:: HiveCluster :: group ( dt)
361+ }
362+
363+ fn version ( dt : & Self :: DynamicType ) -> std:: borrow:: Cow < ' _ , str > {
364+ v1alpha1:: HiveCluster :: version ( dt)
365+ }
366+
367+ fn plural ( dt : & Self :: DynamicType ) -> std:: borrow:: Cow < ' _ , str > {
368+ v1alpha1:: HiveCluster :: plural ( dt)
369+ }
370+
371+ fn meta ( & self ) -> & ObjectMeta {
372+ & self . metadata
373+ }
374+
375+ fn meta_mut ( & mut self ) -> & mut ObjectMeta {
376+ & mut self . metadata
377+ }
378+ }
379+
318380/// Cluster-wide settings resolved during validation and dereferencing.
319381///
320382/// Everything the config-file builders need is resolved here so they never have to
@@ -350,7 +412,6 @@ pub async fn reconcile_hive(
350412 . map_err ( error_boundary:: InvalidObject :: clone)
351413 . context ( InvalidHiveClusterSnafu ) ?;
352414 let client = & ctx. client ;
353- let hive_namespace = hive. namespace ( ) . context ( ObjectHasNoNamespaceSnafu ) ?;
354415
355416 let dereferenced_objects = crate :: controller:: dereference:: dereference ( client, hive)
356417 . await
@@ -359,7 +420,6 @@ pub async fn reconcile_hive(
359420 let validated_cluster = validate:: validate_cluster (
360421 hive,
361422 & ctx. operator_environment . image_repository ,
362- & hive_namespace,
363423 & client. kubernetes_cluster_info ,
364424 dereferenced_objects,
365425 )
@@ -411,7 +471,7 @@ pub async fn reconcile_hive(
411471 let rg_configmap = build:: config_map:: build_metastore_rolegroup_config_map (
412472 & validated_cluster,
413473 & rolegroup,
414- hive ,
474+ rg ,
415475 )
416476 . with_context ( |_| BuildRoleGroupConfigMapSnafu {
417477 rolegroup : rolegroup. clone ( ) ,
@@ -464,7 +524,7 @@ pub async fn reconcile_hive(
464524 // We don't /need/ stability, but it's still nice to avoid spurious changes where possible.
465525 let mut discovery_hash = FnvHasher :: with_key ( 0 ) ;
466526
467- if let Some ( role_config) = validated_cluster. role_config {
527+ if let Some ( role_config) = & validated_cluster. role_config {
468528 add_pdbs (
469529 & role_config. pdb ,
470530 hive,
@@ -489,8 +549,7 @@ pub async fn reconcile_hive(
489549 ) ?;
490550
491551 for discovery_cm in discovery:: build_discovery_configmaps (
492- hive,
493- hive,
552+ & validated_cluster,
494553 HiveRole :: MetaStore ,
495554 & validated_cluster. image ,
496555 None ,
0 commit comments