Skip to content

Commit 11c014d

Browse files
committed
fix: consolidate ValidatedClusterConfig, use EnvarSet and operator-rs v2 RoleGroupConfig
1 parent 04171b1 commit 11c014d

5 files changed

Lines changed: 119 additions & 95 deletions

File tree

rust/operator-binary/src/airflow_controller.rs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -118,29 +118,35 @@ pub struct ValidatedRoleConfig {
118118

119119
/// Per-rolegroup configuration: the merged CRD config plus overrides.
120120
///
121-
/// `config_overrides` is kept as the typed [`AirflowConfigOverrides`] (role-group merged over
122-
/// role); it is flattened into the rendered config file later, in the build step. This mirrors
123-
/// hdfs-operator. `env_overrides` is already a flat map.
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.
124135
#[derive(Clone, Debug)]
125-
pub struct ValidatedRoleGroupConfig {
126-
pub merged_config: AirflowConfig,
127-
pub config_overrides: AirflowConfigOverrides,
128-
pub env_overrides: HashMap<String, String>,
129-
pub replicas: Option<u16>,
130-
pub pod_overrides: PodTemplateSpec,
136+
pub struct ValidatedClusterConfig {
137+
pub executor: AirflowExecutor,
138+
pub authentication_config: AirflowClientAuthenticationDetailsResolved,
139+
pub authorization_config: AirflowAuthorizationResolved,
131140
}
132141

133142
/// The validated cluster: proves that config merging succeeded for every role and
134-
/// role group before any resources are created. It also carries the dereferenced
135-
/// external references, so every downstream build step reads them from here.
143+
/// role group before any resources are created.
136144
#[derive(Clone, Debug)]
137-
pub struct ValidatedAirflowCluster {
145+
pub struct ValidatedCluster {
138146
pub image: ResolvedProductImage,
139-
pub role_groups: BTreeMap<AirflowRole, BTreeMap<String, ValidatedRoleGroupConfig>>,
147+
pub cluster_config: ValidatedClusterConfig,
148+
pub role_groups: BTreeMap<AirflowRole, BTreeMap<String, AirflowRoleGroupConfig>>,
140149
pub role_configs: BTreeMap<AirflowRole, ValidatedRoleConfig>,
141-
pub executor: AirflowExecutor,
142-
pub authentication_config: AirflowClientAuthenticationDetailsResolved,
143-
pub authorization_config: AirflowAuthorizationResolved,
144150
}
145151

146152
#[derive(Snafu, Debug, EnumDiscriminants)]
@@ -450,7 +456,7 @@ pub async fn reconcile_airflow(
450456
// collection there will be a pod template created to be used for pod provisioning
451457
if let AirflowExecutor::KubernetesExecutors {
452458
common_configuration,
453-
} = &validated_cluster.executor
459+
} = &validated_cluster.cluster_config.executor
454460
{
455461
build_executor_template(
456462
airflow,
@@ -506,11 +512,11 @@ pub async fn reconcile_airflow(
506512
let git_sync_resources = git_sync::v1alpha2::GitSyncResources::new(
507513
&airflow.spec.cluster_config.dags_git_sync,
508514
&validated_cluster.image,
509-
&env_vars_from_overrides(&validated_rg_config.env_overrides),
515+
&Vec::<EnvVar>::from(validated_rg_config.env_overrides.clone()),
510516
&airflow.volume_mounts(),
511517
LOG_VOLUME_NAME,
512518
&validated_rg_config
513-
.merged_config
519+
.config
514520
.logging
515521
.for_container(&Container::GitSync),
516522
)
@@ -566,7 +572,7 @@ pub async fn reconcile_airflow(
566572
&validated_cluster,
567573
&rolegroup,
568574
&validated_rg_config.config_overrides,
569-
&validated_rg_config.merged_config.logging,
575+
&validated_rg_config.config.logging,
570576
&Container::Airflow,
571577
)
572578
.context(BuildConfigMapSnafu)?;
@@ -624,7 +630,7 @@ async fn build_executor_template(
624630
airflow: &v1alpha2::AirflowCluster,
625631
common_config: &AirflowExecutorCommonConfiguration,
626632
metadata_database_connection_details: &SqlAlchemyDatabaseConnectionDetails,
627-
validated_cluster: &ValidatedAirflowCluster,
633+
validated_cluster: &ValidatedCluster,
628634
cluster_resources: &mut ClusterResources<'_>,
629635
client: &stackable_operator::client::Client,
630636
rbac_sa: &stackable_operator::k8s_openapi::api::core::v1::ServiceAccount,
@@ -671,7 +677,7 @@ async fn build_executor_template(
671677
let worker_pod_template_config_map = build_executor_template_config_map(
672678
airflow,
673679
&validated_cluster.image,
674-
&validated_cluster.authentication_config,
680+
&validated_cluster.cluster_config.authentication_config,
675681
metadata_database_connection_details,
676682
&rbac_sa.name_unchecked(),
677683
&merged_executor_config,
@@ -750,10 +756,10 @@ fn listener_ports() -> Vec<listener::v1alpha1::ListenerPort> {
750756
#[allow(clippy::too_many_arguments)]
751757
fn build_server_rolegroup_statefulset(
752758
airflow: &v1alpha2::AirflowCluster,
753-
validated_cluster: &ValidatedAirflowCluster,
759+
validated_cluster: &ValidatedCluster,
754760
airflow_role: &AirflowRole,
755761
rolegroup_ref: &RoleGroupRef<v1alpha2::AirflowCluster>,
756-
validated_rg_config: &ValidatedRoleGroupConfig,
762+
validated_rg_config: &AirflowRoleGroupConfig,
757763
metadata_database_connection_details: &SqlAlchemyDatabaseConnectionDetails,
758764
celery_database_connection_details: &Option<(
759765
CeleryDatabaseConnectionDetails,
@@ -762,13 +768,13 @@ fn build_server_rolegroup_statefulset(
762768
service_account: &ServiceAccount,
763769
git_sync_resources: &git_sync::v1alpha2::GitSyncResources,
764770
) -> Result<StatefulSet> {
765-
let merged_airflow_config = &validated_rg_config.merged_config;
771+
let merged_airflow_config = &validated_rg_config.config;
766772
let env_overrides = &validated_rg_config.env_overrides;
767773

768774
let resolved_product_image = &validated_cluster.image;
769-
let authentication_config = &validated_cluster.authentication_config;
770-
let authorization_config = &validated_cluster.authorization_config;
771-
let executor = &validated_cluster.executor;
775+
let authentication_config = &validated_cluster.cluster_config.authentication_config;
776+
let authorization_config = &validated_cluster.cluster_config.authorization_config;
777+
let executor = &validated_cluster.cluster_config.executor;
772778

773779
let mut pb = PodBuilder::new();
774780
let recommended_object_labels = build_recommended_labels(
@@ -1044,7 +1050,7 @@ fn build_server_rolegroup_statefulset(
10441050
}
10451051
.to_string(),
10461052
),
1047-
replicas: validated_rg_config.replicas.map(i32::from),
1053+
replicas: Some(i32::from(validated_rg_config.replicas)),
10481054
selector: LabelSelector {
10491055
match_labels: Some(statefulset_match_labels.into()),
10501056
..LabelSelector::default()
@@ -1123,7 +1129,6 @@ fn build_executor_template_config_map(
11231129
let mut airflow_container =
11241130
ContainerBuilder::new(&Container::Base.to_string()).context(InvalidContainerNameSnafu)?;
11251131

1126-
// Works too, had been changed
11271132
add_authentication_volumes_and_volume_mounts(
11281133
authentication_config,
11291134
&mut airflow_container,

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +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::crd::{
11-
AirflowConfigOptions, authentication::AirflowClientAuthenticationDetailsResolved,
12-
authorization::AirflowAuthorizationResolved,
13-
};
10+
use crate::{airflow_controller::ValidatedCluster, crd::AirflowConfigOptions};
1411

1512
/// Marks arbitrary Python code to prepend verbatim to the generated file.
1613
const CONFIG_OVERRIDE_FILE_HEADER_KEY: &str = "FILE_HEADER";
@@ -35,19 +32,17 @@ pub enum Error {
3532
/// resolved authentication/authorization config) with the user's `config_overrides`
3633
/// applied last, wrapped by the optional `FILE_HEADER`/`FILE_FOOTER` Python blocks.
3734
pub fn build(
38-
authentication_config: &AirflowClientAuthenticationDetailsResolved,
39-
authorization_config: &AirflowAuthorizationResolved,
40-
product_version: &str,
35+
validated_cluster: &ValidatedCluster,
4136
config_file_overrides: &BTreeMap<String, String>,
4237
) -> Result<String, Error> {
4338
let mut config: BTreeMap<String, String> = BTreeMap::new();
4439

4540
// this will call default values from AirflowClientAuthenticationDetails
4641
add_airflow_config(
4742
&mut config,
48-
authentication_config,
49-
authorization_config,
50-
product_version,
43+
&validated_cluster.cluster_config.authentication_config,
44+
&validated_cluster.cluster_config.authorization_config,
45+
&validated_cluster.image.product_version,
5146
)
5247
.context(ConstructConfigSnafu)?;
5348

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use stackable_operator::{
1515
};
1616

1717
use crate::{
18-
airflow_controller::{AIRFLOW_CONTROLLER_NAME, ValidatedAirflowCluster},
18+
airflow_controller::{AIRFLOW_CONTROLLER_NAME, ValidatedCluster},
1919
config::webserver_config,
2020
crd::{
2121
AIRFLOW_CONFIG_FILENAME, AirflowConfigOverrides, Container, STACKABLE_LOG_DIR,
@@ -58,7 +58,7 @@ pub enum Error {
5858
/// The rolegroup [`ConfigMap`] configures the rolegroup based on the configuration given by the administrator
5959
pub fn build_rolegroup_config_map(
6060
airflow: &v1alpha2::AirflowCluster,
61-
validated_cluster: &ValidatedAirflowCluster,
61+
validated_cluster: &ValidatedCluster,
6262
rolegroup: &RoleGroupRef<v1alpha2::AirflowCluster>,
6363
config_overrides: &AirflowConfigOverrides,
6464
logging: &Logging<Container>,
@@ -68,15 +68,10 @@ pub fn build_rolegroup_config_map(
6868
let config_file_overrides: BTreeMap<String, String> =
6969
config_overrides.webserver_config_py.overrides.clone();
7070

71-
let config_file = webserver_config::build(
72-
&validated_cluster.authentication_config,
73-
&validated_cluster.authorization_config,
74-
&validated_cluster.image.product_version,
75-
&config_file_overrides,
76-
)
77-
.with_context(|_| BuildWebserverConfigSnafu {
78-
rolegroup: rolegroup.clone(),
79-
})?;
71+
let config_file = webserver_config::build(validated_cluster, &config_file_overrides)
72+
.with_context(|_| BuildWebserverConfigSnafu {
73+
rolegroup: rolegroup.clone(),
74+
})?;
8075

8176
let mut cm_builder = ConfigMapBuilder::new();
8277

0 commit comments

Comments
 (0)