Skip to content

Commit 9b21372

Browse files
committed
fix: use build structure for pdb instead of mutating.
1 parent 510df9b commit 9b21372

2 files changed

Lines changed: 17 additions & 36 deletions

File tree

rust/operator-binary/src/controller.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use crate::{
4646
resource::{
4747
discovery,
4848
listener::build_role_listener,
49-
pdb::add_pdbs,
49+
pdb::build_pdb,
5050
service::{build_rolegroup_headless_service, build_rolegroup_metrics_service},
5151
},
5252
},
@@ -125,9 +125,9 @@ pub enum Error {
125125
#[snafu(display("internal operator failure"))]
126126
InternalOperatorFailure { source: crate::crd::Error },
127127

128-
#[snafu(display("failed to create PodDisruptionBudget"))]
129-
FailedToCreatePdb {
130-
source: crate::controller::build::resource::pdb::Error,
128+
#[snafu(display("failed to apply PodDisruptionBudget"))]
129+
ApplyPdb {
130+
source: stackable_operator::cluster_resources::Error,
131131
},
132132

133133
#[snafu(display("failed to get required Labels"))]
@@ -542,15 +542,12 @@ pub async fn reconcile_hive(
542542
let mut discovery_hash = FnvHasher::with_key(0);
543543

544544
if let Some(role_config) = &validated_cluster.role_config {
545-
add_pdbs(
546-
&role_config.pdb,
547-
&validated_cluster,
548-
&HiveRole::MetaStore,
549-
client,
550-
&mut cluster_resources,
551-
)
552-
.await
553-
.context(FailedToCreatePdbSnafu)?;
545+
if let Some(pdb) = build_pdb(&role_config.pdb, &validated_cluster, &HiveRole::MetaStore) {
546+
cluster_resources
547+
.add(client, pdb)
548+
.await
549+
.context(ApplyPdbSnafu)?;
550+
}
554551

555552
let role_listener: Listener = build_role_listener(
556553
&validated_cluster,

rust/operator-binary/src/controller/build/resource/pdb.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
1-
use snafu::{ResultExt, Snafu};
21
use stackable_operator::{
3-
client::Client, cluster_resources::ClusterResources, commons::pdb::PdbConfig,
4-
kube::ResourceExt, v2::builder::pdb::pod_disruption_budget_builder_with_role,
2+
commons::pdb::PdbConfig, k8s_openapi::api::policy::v1::PodDisruptionBudget,
3+
v2::builder::pdb::pod_disruption_budget_builder_with_role,
54
};
65

76
use crate::{
87
controller::{ValidatedCluster, controller_name, operator_name, product_name},
98
crd::HiveRole,
109
};
1110

12-
#[derive(Snafu, Debug)]
13-
pub enum Error {
14-
#[snafu(display("Cannot apply PodDisruptionBudget [{name}]"))]
15-
ApplyPdb {
16-
source: stackable_operator::cluster_resources::Error,
17-
name: String,
18-
},
19-
}
20-
21-
pub async fn add_pdbs(
11+
/// Builds the [`PodDisruptionBudget`] for the given `role`, or `None` if PDBs are disabled.
12+
pub fn build_pdb(
2213
pdb: &PdbConfig,
2314
cluster: &ValidatedCluster,
2415
role: &HiveRole,
25-
client: &Client,
26-
cluster_resources: &mut ClusterResources<'_>,
27-
) -> Result<(), Error> {
16+
) -> Option<PodDisruptionBudget> {
2817
if !pdb.enabled {
29-
return Ok(());
18+
return None;
3019
}
3120
let max_unavailable = pdb.max_unavailable.unwrap_or(match role {
3221
HiveRole::MetaStore => max_unavailable_metastores(),
@@ -40,13 +29,8 @@ pub async fn add_pdbs(
4029
)
4130
.with_max_unavailable(max_unavailable)
4231
.build();
43-
let pdb_name = pdb.name_any();
44-
cluster_resources
45-
.add(client, pdb)
46-
.await
47-
.with_context(|_| ApplyPdbSnafu { name: pdb_name })?;
4832

49-
Ok(())
33+
Some(pdb)
5034
}
5135

5236
fn max_unavailable_metastores() -> u16 {

0 commit comments

Comments
 (0)