@@ -143,12 +143,71 @@ pub struct ValidatedClusterConfig {
143143/// role group before any resources are created.
144144#[ derive( Clone , Debug ) ]
145145pub struct ValidatedCluster {
146+ /// `ObjectMeta` carrying `name`, `namespace` and `uid`, captured during validation, so this
147+ /// struct can stand in as the owner [`Resource`] for child objects.
148+ metadata : ObjectMeta ,
146149 pub image : ResolvedProductImage ,
147150 pub cluster_config : ValidatedClusterConfig ,
148151 pub role_groups : BTreeMap < AirflowRole , BTreeMap < String , AirflowRoleGroupConfig > > ,
149152 pub role_configs : BTreeMap < AirflowRole , ValidatedRoleConfig > ,
150153}
151154
155+ impl ValidatedCluster {
156+ pub fn new (
157+ airflow : & v1alpha2:: AirflowCluster ,
158+ image : ResolvedProductImage ,
159+ cluster_config : ValidatedClusterConfig ,
160+ role_groups : BTreeMap < AirflowRole , BTreeMap < String , AirflowRoleGroupConfig > > ,
161+ role_configs : BTreeMap < AirflowRole , ValidatedRoleConfig > ,
162+ ) -> Self {
163+ Self {
164+ // Capture only the identity fields needed to own child objects.
165+ metadata : ObjectMeta {
166+ name : Some ( airflow. name_any ( ) ) ,
167+ namespace : airflow. namespace ( ) ,
168+ uid : airflow. uid ( ) ,
169+ ..ObjectMeta :: default ( )
170+ } ,
171+ image,
172+ cluster_config,
173+ role_groups,
174+ role_configs,
175+ }
176+ }
177+ }
178+
179+ /// Lets [`ValidatedCluster`] stand in for the raw [`v1alpha2::AirflowCluster`] when building owner
180+ /// references and metadata for child objects. Kind/group/version are delegated to the CRD; the
181+ /// `metadata` (name, namespace, uid) is captured during validation.
182+ impl Resource for ValidatedCluster {
183+ type DynamicType = <v1alpha2:: AirflowCluster as Resource >:: DynamicType ;
184+ type Scope = <v1alpha2:: AirflowCluster as Resource >:: Scope ;
185+
186+ fn kind ( dt : & Self :: DynamicType ) -> std:: borrow:: Cow < ' _ , str > {
187+ v1alpha2:: AirflowCluster :: kind ( dt)
188+ }
189+
190+ fn group ( dt : & Self :: DynamicType ) -> std:: borrow:: Cow < ' _ , str > {
191+ v1alpha2:: AirflowCluster :: group ( dt)
192+ }
193+
194+ fn version ( dt : & Self :: DynamicType ) -> std:: borrow:: Cow < ' _ , str > {
195+ v1alpha2:: AirflowCluster :: version ( dt)
196+ }
197+
198+ fn plural ( dt : & Self :: DynamicType ) -> std:: borrow:: Cow < ' _ , str > {
199+ v1alpha2:: AirflowCluster :: plural ( dt)
200+ }
201+
202+ fn meta ( & self ) -> & ObjectMeta {
203+ & self . metadata
204+ }
205+
206+ fn meta_mut ( & mut self ) -> & mut ObjectMeta {
207+ & mut self . metadata
208+ }
209+ }
210+
152211#[ derive( Snafu , Debug , EnumDiscriminants ) ]
153212#[ strum_discriminants( derive( IntoStaticStr ) ) ]
154213pub enum Error {
@@ -568,7 +627,6 @@ pub async fn reconcile_airflow(
568627 } ) ?;
569628
570629 let rg_configmap = config_map:: build_rolegroup_config_map (
571- airflow,
572630 & validated_cluster,
573631 & rolegroup,
574632 & validated_rg_config. config_overrides ,
@@ -645,7 +703,6 @@ async fn build_executor_template(
645703 } ;
646704
647705 let rg_configmap = config_map:: build_rolegroup_config_map (
648- airflow,
649706 validated_cluster,
650707 & rolegroup,
651708 // The kubernetes-executor pod template does not apply webserver_config.py overrides
0 commit comments