@@ -17,7 +17,9 @@ use stackable_operator::{
1717 product_logging:: framework:: { ValidatedContainerLogConfigChoice , VectorContainerLogConfig } ,
1818 role_group_utils:: ResourceNames ,
1919 types:: {
20- kubernetes:: { ConfigMapName , ListenerClassName , ListenerName , SecretName , Uid } ,
20+ kubernetes:: {
21+ ConfigMapName , ListenerClassName , ListenerName , NamespaceName , SecretName , Uid ,
22+ } ,
2123 operator:: {
2224 ClusterName , ControllerName , OperatorName , ProductName , ProductVersion ,
2325 RoleGroupName , RoleName ,
@@ -120,6 +122,11 @@ pub struct ValidatedCluster {
120122 metadata : ObjectMeta ,
121123 /// The cluster name as a type-safe value, used to build resource names and labels.
122124 pub name : ClusterName ,
125+ /// The cluster's namespace as a type-safe value, captured during validation.
126+ pub namespace : NamespaceName ,
127+ /// The cluster's UID as a type-safe value, captured during validation (used for owner
128+ /// references).
129+ pub uid : Uid ,
123130 /// The product version as a valid label value, for the recommended `app.kubernetes.io/version`
124131 /// label. Derived from the resolved image's app-version label value.
125132 pub product_version : ProductVersion ,
@@ -131,8 +138,9 @@ pub struct ValidatedCluster {
131138
132139impl ValidatedCluster {
133140 pub fn new (
134- airflow : & v1alpha2:: AirflowCluster ,
135141 name : ClusterName ,
142+ namespace : NamespaceName ,
143+ uid : Uid ,
136144 image : ResolvedProductImage ,
137145 cluster_config : ValidatedClusterConfig ,
138146 role_groups : BTreeMap < AirflowRole , BTreeMap < RoleGroupName , AirflowRoleGroup > > ,
@@ -145,12 +153,14 @@ impl ValidatedCluster {
145153 Self {
146154 // Capture only the identity fields needed to own child objects.
147155 metadata : ObjectMeta {
148- name : Some ( airflow . name_any ( ) ) ,
149- namespace : airflow . namespace ( ) ,
150- uid : airflow . uid ( ) ,
156+ name : Some ( name . to_string ( ) ) ,
157+ namespace : Some ( namespace. to_string ( ) ) ,
158+ uid : Some ( uid. to_string ( ) ) ,
151159 ..ObjectMeta :: default ( )
152160 } ,
153161 name,
162+ namespace,
163+ uid,
154164 product_version,
155165 image,
156166 cluster_config,
@@ -159,11 +169,6 @@ impl ValidatedCluster {
159169 }
160170 }
161171
162- /// The cluster's namespace, captured during validation.
163- pub fn namespace ( & self ) -> Option < String > {
164- self . metadata . namespace . clone ( )
165- }
166-
167172 /// Whether the cluster has the given role configured (i.e. it has role groups for it).
168173 pub fn has_role ( & self , role : & AirflowRole ) -> bool {
169174 self . role_groups . contains_key ( role)
@@ -356,13 +361,6 @@ impl NameIsValidLabelValue for ValidatedCluster {
356361
357362impl HasUid for ValidatedCluster {
358363 fn to_uid ( & self ) -> Uid {
359- Uid :: from_str (
360- & self
361- . metadata
362- . uid
363- . clone ( )
364- . expect ( "the uid is captured during validation" ) ,
365- )
366- . expect ( "the uid is a valid Kubernetes UID" )
364+ self . uid . clone ( )
367365 }
368366}
0 commit comments