Skip to content

Commit ae62c32

Browse files
committed
refactor: move ValidatedCluster structs to controller/mod.rs
1 parent f0dd42b commit ae62c32

5 files changed

Lines changed: 127 additions & 114 deletions

File tree

rust/operator-binary/src/airflow_controller.rs

Lines changed: 6 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,17 @@ use stackable_operator::{
6767
use strum::{EnumDiscriminants, IntoStaticStr};
6868

6969
use crate::{
70-
controller::build::config_map,
70+
controller::{AirflowRoleGroupConfig, ValidatedCluster, build::config_map},
7171
controller_commons::{self, CONFIG_VOLUME_NAME, LOG_CONFIG_VOLUME_NAME, LOG_VOLUME_NAME},
7272
crd::{
73-
self, APP_NAME, AirflowClusterStatus, AirflowConfig, AirflowConfigOverrides,
74-
AirflowExecutor, AirflowExecutorCommonConfiguration, AirflowRole, CONFIG_PATH, Container,
75-
ExecutorConfig, HTTP_PORT, HTTP_PORT_NAME, LISTENER_VOLUME_DIR, LISTENER_VOLUME_NAME,
76-
LOG_CONFIG_DIR, METRICS_PORT, METRICS_PORT_NAME, OPERATOR_NAME, STACKABLE_LOG_DIR,
77-
TEMPLATE_LOCATION, TEMPLATE_NAME, TEMPLATE_VOLUME_NAME,
73+
self, APP_NAME, AirflowClusterStatus, AirflowConfigOverrides, AirflowExecutor,
74+
AirflowExecutorCommonConfiguration, AirflowRole, CONFIG_PATH, Container, ExecutorConfig,
75+
HTTP_PORT, HTTP_PORT_NAME, LISTENER_VOLUME_DIR, LISTENER_VOLUME_NAME, LOG_CONFIG_DIR,
76+
METRICS_PORT, METRICS_PORT_NAME, OPERATOR_NAME, STACKABLE_LOG_DIR, TEMPLATE_LOCATION,
77+
TEMPLATE_NAME, TEMPLATE_VOLUME_NAME,
7878
authentication::{
7979
AirflowAuthenticationClassResolved, AirflowClientAuthenticationDetailsResolved,
8080
},
81-
authorization::AirflowAuthorizationResolved,
8281
build_recommended_labels,
8382
internal_secret::{
8483
FERNET_KEY_SECRET_KEY, INTERNAL_SECRET_SECRET_KEY, JWT_SECRET_SECRET_KEY,
@@ -108,106 +107,6 @@ pub struct Ctx {
108107
pub operator_environment: OperatorEnvironmentOptions,
109108
}
110109

111-
/// Per-role configuration extracted during validation.
112-
#[derive(Clone, Debug)]
113-
pub struct ValidatedRoleConfig {
114-
pub pdb: Option<stackable_operator::commons::pdb::PdbConfig>,
115-
pub listener_class: Option<String>,
116-
pub group_listener_name: Option<String>,
117-
}
118-
119-
/// Per-rolegroup configuration: the merged CRD config plus overrides.
120-
///
121-
/// This is the generic [`stackable_operator::v2::role_utils::RoleGroupConfig`]: the merged config
122-
/// fragment in `config`, the typed `config_overrides` (role-group merged over role) and the merged
123-
/// `env_overrides`/`cli_overrides`/`pod_overrides`. The config overrides are kept typed
124-
/// ([`AirflowConfigOverrides`]) and flattened into the rendered config file later, in the build step.
125-
pub type AirflowRoleGroupConfig = stackable_operator::v2::role_utils::RoleGroupConfig<
126-
AirflowConfig,
127-
stackable_operator::v2::role_utils::GenericCommonConfig,
128-
AirflowConfigOverrides,
129-
>;
130-
131-
/// Cluster-wide configuration that applies to every role and role group.
132-
///
133-
/// Carries the dereferenced external references, so every downstream build step reads them from
134-
/// here rather than from the raw cluster object.
135-
#[derive(Clone, Debug)]
136-
pub struct ValidatedClusterConfig {
137-
pub executor: AirflowExecutor,
138-
pub authentication_config: AirflowClientAuthenticationDetailsResolved,
139-
pub authorization_config: AirflowAuthorizationResolved,
140-
}
141-
142-
/// The validated cluster: proves that config merging succeeded for every role and
143-
/// role group before any resources are created.
144-
#[derive(Clone, Debug)]
145-
pub 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,
149-
pub image: ResolvedProductImage,
150-
pub cluster_config: ValidatedClusterConfig,
151-
pub role_groups: BTreeMap<AirflowRole, BTreeMap<String, AirflowRoleGroupConfig>>,
152-
pub role_configs: BTreeMap<AirflowRole, ValidatedRoleConfig>,
153-
}
154-
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-
211110
#[derive(Snafu, Debug, EnumDiscriminants)]
212111
#[strum_discriminants(derive(IntoStaticStr))]
213112
pub enum Error {

rust/operator-binary/src/config/webserver_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use snafu::{ResultExt, Snafu};
77
use stackable_operator::v2::flask_config_writer;
88

99
use super::{PYTHON_IMPORTS, add_airflow_config};
10-
use crate::{airflow_controller::ValidatedCluster, crd::AirflowConfigOptions};
10+
use crate::{controller::ValidatedCluster, crd::AirflowConfigOptions};
1111

1212
/// Marks arbitrary Python code to prepend verbatim to the generated file.
1313
const CONFIG_OVERRIDE_FILE_HEADER_KEY: &str = "FILE_HEADER";

rust/operator-binary/src/controller/build/config_map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ use stackable_operator::{
1515
};
1616

1717
use crate::{
18-
airflow_controller::{AIRFLOW_CONTROLLER_NAME, ValidatedCluster},
18+
airflow_controller::AIRFLOW_CONTROLLER_NAME,
1919
config::webserver_config,
20+
controller::ValidatedCluster,
2021
crd::{
2122
AIRFLOW_CONFIG_FILENAME, AirflowConfigOverrides, Container, STACKABLE_LOG_DIR,
2223
build_recommended_labels, v1alpha2,
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,116 @@
1+
use std::collections::BTreeMap;
2+
3+
use stackable_operator::{
4+
commons::product_image_selection::ResolvedProductImage,
5+
kube::{Resource, ResourceExt, api::ObjectMeta},
6+
};
7+
8+
use crate::crd::{
9+
AirflowConfig, AirflowConfigOverrides, AirflowExecutor, AirflowRole,
10+
authentication::AirflowClientAuthenticationDetailsResolved,
11+
authorization::AirflowAuthorizationResolved, v1alpha2,
12+
};
13+
114
pub mod build;
215
pub mod dereference;
316
pub mod validate;
17+
18+
/// Per-role configuration extracted during validation.
19+
#[derive(Clone, Debug)]
20+
pub struct ValidatedRoleConfig {
21+
pub pdb: Option<stackable_operator::commons::pdb::PdbConfig>,
22+
pub listener_class: Option<String>,
23+
pub group_listener_name: Option<String>,
24+
}
25+
26+
/// Per-rolegroup configuration: the merged CRD config plus overrides.
27+
///
28+
/// This is the generic [`stackable_operator::v2::role_utils::RoleGroupConfig`]: the merged config
29+
/// fragment in `config`, the typed `config_overrides` (role-group merged over role) and the merged
30+
/// `env_overrides`/`cli_overrides`/`pod_overrides`. The config overrides are kept typed
31+
/// ([`AirflowConfigOverrides`]) and flattened into the rendered config file later, in the build step.
32+
pub type AirflowRoleGroupConfig = stackable_operator::v2::role_utils::RoleGroupConfig<
33+
AirflowConfig,
34+
stackable_operator::v2::role_utils::GenericCommonConfig,
35+
AirflowConfigOverrides,
36+
>;
37+
38+
/// Cluster-wide configuration that applies to every role and role group.
39+
///
40+
/// Carries the dereferenced external references, so every downstream build step reads them from
41+
/// here rather than from the raw cluster object.
42+
#[derive(Clone, Debug)]
43+
pub struct ValidatedClusterConfig {
44+
pub executor: AirflowExecutor,
45+
pub authentication_config: AirflowClientAuthenticationDetailsResolved,
46+
pub authorization_config: AirflowAuthorizationResolved,
47+
}
48+
49+
/// The validated cluster: proves that config merging succeeded for every role and
50+
/// role group before any resources are created.
51+
#[derive(Clone, Debug)]
52+
pub struct ValidatedCluster {
53+
/// `ObjectMeta` carrying `name`, `namespace` and `uid`, captured during validation, so this
54+
/// struct can stand in as the owner [`Resource`] for child objects.
55+
metadata: ObjectMeta,
56+
pub image: ResolvedProductImage,
57+
pub cluster_config: ValidatedClusterConfig,
58+
pub role_groups: BTreeMap<AirflowRole, BTreeMap<String, AirflowRoleGroupConfig>>,
59+
pub role_configs: BTreeMap<AirflowRole, ValidatedRoleConfig>,
60+
}
61+
62+
impl ValidatedCluster {
63+
pub fn new(
64+
airflow: &v1alpha2::AirflowCluster,
65+
image: ResolvedProductImage,
66+
cluster_config: ValidatedClusterConfig,
67+
role_groups: BTreeMap<AirflowRole, BTreeMap<String, AirflowRoleGroupConfig>>,
68+
role_configs: BTreeMap<AirflowRole, ValidatedRoleConfig>,
69+
) -> Self {
70+
Self {
71+
// Capture only the identity fields needed to own child objects.
72+
metadata: ObjectMeta {
73+
name: Some(airflow.name_any()),
74+
namespace: airflow.namespace(),
75+
uid: airflow.uid(),
76+
..ObjectMeta::default()
77+
},
78+
image,
79+
cluster_config,
80+
role_groups,
81+
role_configs,
82+
}
83+
}
84+
}
85+
86+
/// Lets [`ValidatedCluster`] stand in for the raw [`v1alpha2::AirflowCluster`] when building owner
87+
/// references and metadata for child objects. Kind/group/version are delegated to the CRD; the
88+
/// `metadata` (name, namespace, uid) is captured during validation.
89+
impl Resource for ValidatedCluster {
90+
type DynamicType = <v1alpha2::AirflowCluster as Resource>::DynamicType;
91+
type Scope = <v1alpha2::AirflowCluster as Resource>::Scope;
92+
93+
fn kind(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
94+
v1alpha2::AirflowCluster::kind(dt)
95+
}
96+
97+
fn group(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
98+
v1alpha2::AirflowCluster::group(dt)
99+
}
100+
101+
fn version(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
102+
v1alpha2::AirflowCluster::version(dt)
103+
}
104+
105+
fn plural(dt: &Self::DynamicType) -> std::borrow::Cow<'_, str> {
106+
v1alpha2::AirflowCluster::plural(dt)
107+
}
108+
109+
fn meta(&self) -> &ObjectMeta {
110+
&self.metadata
111+
}
112+
113+
fn meta_mut(&mut self) -> &mut ObjectMeta {
114+
&mut self.metadata
115+
}
116+
}

rust/operator-binary/src/controller/validate.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ use stackable_operator::{
1313
};
1414
use strum::IntoEnumIterator;
1515

16-
use super::dereference::DereferencedObjects;
16+
use super::{
17+
AirflowRoleGroupConfig, ValidatedCluster, ValidatedClusterConfig, ValidatedRoleConfig,
18+
dereference::DereferencedObjects,
19+
};
1720
use crate::{
18-
airflow_controller::{
19-
AirflowRoleGroupConfig, CONTAINER_IMAGE_BASE_NAME, ValidatedCluster,
20-
ValidatedClusterConfig, ValidatedRoleConfig,
21-
},
21+
airflow_controller::CONTAINER_IMAGE_BASE_NAME,
2222
crd::{
2323
AirflowConfig, AirflowConfigFragment, AirflowConfigOverrides, AirflowRole, AirflowRoleType,
2424
v1alpha2,

0 commit comments

Comments
 (0)