Skip to content

Commit 6eb76b1

Browse files
committed
refactor: introduce ValidatedRoleConfig
1 parent 4e8723c commit 6eb76b1

3 files changed

Lines changed: 46 additions & 10 deletions

File tree

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use stackable_operator::{
1717
kvp::label::{recommended_labels, role_group_selector},
1818
role_group_utils::ResourceNames,
1919
types::{
20-
kubernetes::{NamespaceName, Uid},
20+
kubernetes::{ListenerClassName, NamespaceName, Uid},
2121
operator::{
2222
ClusterName, ControllerName, OperatorName, ProductName, ProductVersion,
2323
RoleGroupName as RoleGroupNameV2, RoleName,
@@ -98,6 +98,17 @@ impl ValidatedTrinoConfig {
9898
}
9999
}
100100

101+
/// Per-role configuration extracted during validation.
102+
///
103+
/// Lets the reconciler and build steps consume this controller-owned type instead of re-reading
104+
/// the raw [`v1alpha1::TrinoCluster`] (mirroring the hive-operator's `ValidatedRoleConfig`).
105+
#[derive(Clone, Debug)]
106+
pub struct ValidatedRoleConfig {
107+
pub pdb: stackable_operator::commons::pdb::PdbConfig,
108+
/// The listener class for the role's group listener, if it has one (coordinator only).
109+
pub listener_class: Option<ListenerClassName>,
110+
}
111+
101112
/// The validated TrinoCluster. The output of the validate step.
102113
#[derive(Clone, Debug)]
103114
pub struct ValidatedCluster {
@@ -113,6 +124,7 @@ pub struct ValidatedCluster {
113124
pub image: ResolvedProductImage,
114125
pub product_version: u16,
115126
pub cluster_config: ValidatedClusterConfig,
127+
pub role_configs: BTreeMap<TrinoRole, ValidatedRoleConfig>,
116128
pub role_group_configs: BTreeMap<TrinoRole, BTreeMap<RoleGroupName, TrinoRoleGroupConfig>>,
117129
}
118130

@@ -125,6 +137,7 @@ impl ValidatedCluster {
125137
image: ResolvedProductImage,
126138
product_version: u16,
127139
cluster_config: ValidatedClusterConfig,
140+
role_configs: BTreeMap<TrinoRole, ValidatedRoleConfig>,
128141
role_group_configs: BTreeMap<TrinoRole, BTreeMap<RoleGroupName, TrinoRoleGroupConfig>>,
129142
) -> Self {
130143
Self {
@@ -140,10 +153,16 @@ impl ValidatedCluster {
140153
image,
141154
product_version,
142155
cluster_config,
156+
role_configs,
143157
role_group_configs,
144158
}
145159
}
146160

161+
/// The validated per-role config for `role`, if the role is defined.
162+
pub(crate) fn role_config(&self, role: &TrinoRole) -> Option<&ValidatedRoleConfig> {
163+
self.role_configs.get(role)
164+
}
165+
147166
/// Whether the (client-facing) server TLS is enabled.
148167
pub fn server_tls_enabled(&self) -> bool {
149168
self.cluster_config.tls.server.is_some()

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ use stackable_operator::{
2626
};
2727
use strum::{EnumDiscriminants, IntoEnumIterator, IntoStaticStr};
2828

29-
use super::{ValidatedCluster, ValidatedClusterConfig, ValidatedTls, ValidatedTrinoConfig};
29+
use super::{
30+
ValidatedCluster, ValidatedClusterConfig, ValidatedRoleConfig, ValidatedTls,
31+
ValidatedTrinoConfig,
32+
};
3033
use crate::{
3134
authentication::{self, TrinoAuthenticationConfig, TrinoAuthenticationTypes},
3235
controller::dereference::DereferencedObjects,
@@ -205,6 +208,7 @@ pub fn validate(
205208
.vector_aggregator_config_map_name
206209
.clone();
207210

211+
let mut role_configs: BTreeMap<TrinoRole, ValidatedRoleConfig> = BTreeMap::new();
208212
let mut role_group_configs: BTreeMap<TrinoRole, BTreeMap<RoleGroupName, TrinoRoleGroupConfig>> =
209213
BTreeMap::new();
210214
for trino_role in TrinoRole::iter() {
@@ -213,6 +217,20 @@ pub fn validate(
213217
.with_context(|_| MissingTrinoRoleSnafu {
214218
role: trino_role.to_string(),
215219
})?;
220+
221+
// Extract the per-role PDB and (optional) listener class up-front, so the reconciler and
222+
// build steps consume the validated config instead of re-reading the raw cluster.
223+
role_configs.insert(
224+
trino_role.clone(),
225+
ValidatedRoleConfig {
226+
pdb: trino
227+
.generic_role_config(&trino_role)
228+
.map(|rc| rc.pod_disruption_budget.clone())
229+
.unwrap_or_default(),
230+
listener_class: trino_role.listener_class_name(trino),
231+
},
232+
);
233+
216234
let default_config = v1alpha1::TrinoConfig::default_config(
217235
&trino.name_any(),
218236
&trino_role,
@@ -266,6 +284,7 @@ pub fn validate(
266284
image,
267285
product_version,
268286
cluster_config,
287+
role_configs,
269288
role_group_configs,
270289
))
271290
}

rust/operator-binary/src/trino_controller.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use stackable_operator::{
1414
},
1515
logging::controller::ReconcilerError,
1616
memory::{BinaryMultiple, MemoryQuantity},
17-
role_utils::GenericRoleConfig,
1817
shared::time::Duration,
1918
status::condition::{
2019
compute_conditions, operations::ClusterOperationsConditionBuilder,
@@ -346,7 +345,11 @@ pub async fn reconcile_trino(
346345
);
347346
}
348347

349-
if let Some(listener_class) = trino_role.listener_class_name(trino)
348+
let Some(role_config) = validated_cluster.role_config(trino_role) else {
349+
continue;
350+
};
351+
352+
if let Some(listener_class) = &role_config.listener_class
350353
&& let Some(listener_group_name) = group_listener_name(&validated_cluster, trino_role)
351354
{
352355
let role_group_listener = build_group_listener(
@@ -362,12 +365,7 @@ pub async fn reconcile_trino(
362365
.context(ApplyGroupListenerSnafu)?;
363366
}
364367

365-
let role_config = trino.generic_role_config(trino_role);
366-
if let Some(GenericRoleConfig {
367-
pod_disruption_budget: pdb,
368-
}) = role_config
369-
&& let Some(pdb) = build_pdb(pdb, &validated_cluster, trino_role)
370-
{
368+
if let Some(pdb) = build_pdb(&role_config.pdb, &validated_cluster, trino_role) {
371369
cluster_resources
372370
.add(client, pdb)
373371
.await

0 commit comments

Comments
 (0)