Skip to content

Commit 8ad1112

Browse files
committed
refactor: carry PDB config via ValidatedRoleConfig, drop last raw-CRD read
1 parent ea5bed0 commit 8ad1112

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

rust/operator-binary/src/zk_controller.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ use strum::{EnumDiscriminants, IntoStaticStr};
2929

3030
use crate::{
3131
APP_NAME, OPERATOR_NAME, ObjectRef,
32-
crd::{
33-
ZookeeperRole,
34-
v1alpha1::{self, ZookeeperServerRoleConfig},
35-
},
32+
crd::{ZookeeperRole, v1alpha1},
3633
zk_controller::{
3734
build::resource::{
3835
config_map, discovery,
@@ -328,9 +325,8 @@ pub async fn reconcile_zk(
328325
);
329326
}
330327

331-
let role_config = zk.role_config(&zk_role);
332-
if let Some(ZookeeperServerRoleConfig { common, .. }) = role_config
333-
&& let Some(pdb) = build_pdb(&common.pod_disruption_budget, &validated_cluster, &zk_role)
328+
if let Some(role_config) = &validated_cluster.role_config
329+
&& let Some(pdb) = build_pdb(&role_config.pdb, &validated_cluster, &zk_role)
334330
{
335331
cluster_resources
336332
.add(client, pdb)

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use stackable_operator::{
1515
cli::OperatorEnvironmentOptions,
1616
commons::{
1717
cluster_operation::ClusterOperation,
18+
pdb::PdbConfig,
1819
product_image_selection::{self, ResolvedProductImage},
1920
},
2021
config::fragment,
@@ -215,6 +216,9 @@ pub struct ValidatedCluster {
215216
/// `app.kubernetes.io/version` label. Derived from the resolved image's app version label value.
216217
pub product_version: ProductVersion,
217218
pub cluster_config: ValidatedClusterConfig,
219+
/// Per-role config (currently just the PodDisruptionBudget), extracted during validation so the
220+
/// apply step does not reach into the raw [`crate::crd::v1alpha1::ZookeeperCluster`].
221+
pub role_config: Option<ValidatedRoleConfig>,
218222
pub role_group_configs:
219223
BTreeMap<ZookeeperRole, BTreeMap<RoleGroupName, ValidatedRoleGroupConfig>>,
220224
/// The cluster's operation settings (pause/stop), from which the
@@ -235,6 +239,7 @@ impl ValidatedCluster {
235239
image: ResolvedProductImage,
236240
product_version: ProductVersion,
237241
cluster_config: ValidatedClusterConfig,
242+
role_config: Option<ValidatedRoleConfig>,
238243
role_group_configs: BTreeMap<
239244
ZookeeperRole,
240245
BTreeMap<RoleGroupName, ValidatedRoleGroupConfig>,
@@ -255,6 +260,7 @@ impl ValidatedCluster {
255260
image,
256261
product_version,
257262
cluster_config,
263+
role_config,
258264
role_group_configs,
259265
cluster_operation,
260266
object_overrides,
@@ -416,6 +422,12 @@ pub struct ValidatedClusterConfig {
416422
pub listener_class: ListenerClassName,
417423
}
418424

425+
/// Per-role configuration extracted during validation.
426+
#[derive(Clone, Debug)]
427+
pub struct ValidatedRoleConfig {
428+
pub pdb: PdbConfig,
429+
}
430+
419431
/// Validates the cluster spec and the dereferenced inputs.
420432
pub fn validate(
421433
zk: &v1alpha1::ZookeeperCluster,
@@ -496,6 +508,12 @@ pub fn validate(
496508
cluster_info,
497509
);
498510

511+
let role_config = zk.role_config(&ZookeeperRole::Server).map(
512+
|ZookeeperServerRoleConfig { common, .. }| ValidatedRoleConfig {
513+
pdb: common.pod_disruption_budget.clone(),
514+
},
515+
);
516+
499517
Ok(ValidatedCluster::new(
500518
name,
501519
namespace,
@@ -507,6 +525,7 @@ pub fn validate(
507525
server_addresses,
508526
listener_class,
509527
},
528+
role_config,
510529
role_group_configs,
511530
zk.spec.cluster_operation.clone(),
512531
zk.spec.object_overrides.clone(),

0 commit comments

Comments
 (0)