Skip to content

Commit f785875

Browse files
committed
fix: remove raw cluster & last RoleGroupRef
1 parent b6a2bdf commit f785875

3 files changed

Lines changed: 11 additions & 78 deletions

File tree

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

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use stackable_operator::{
3131
self,
3232
spec::{ContainerLogConfig, Logging},
3333
},
34-
role_utils::{self, GenericRoleConfig, Role, RoleGroupRef},
34+
role_utils::{self, GenericRoleConfig, Role},
3535
schemars::{self, JsonSchema},
3636
shared::time::Duration,
3737
status::condition::{ClusterCondition, HasStatusCondition},
@@ -264,71 +264,6 @@ impl v1alpha1::HdfsCluster {
264264
}
265265
}
266266

267-
pub fn rolegroup_ref(
268-
&self,
269-
role_name: impl Into<String>,
270-
group_name: impl Into<String>,
271-
) -> RoleGroupRef<v1alpha1::HdfsCluster> {
272-
RoleGroupRef {
273-
cluster: ObjectRef::from_obj(self),
274-
role: role_name.into(),
275-
role_group: group_name.into(),
276-
}
277-
}
278-
279-
pub fn rolegroup_ref_and_replicas(
280-
&self,
281-
role: &HdfsNodeRole,
282-
) -> Vec<(RoleGroupRef<v1alpha1::HdfsCluster>, u16)> {
283-
match role {
284-
HdfsNodeRole::Name => self
285-
.spec
286-
.name_nodes
287-
.iter()
288-
.flat_map(|role| &role.role_groups)
289-
// Order rolegroups consistently, to avoid spurious downstream rewrites
290-
.collect::<BTreeMap<_, _>>()
291-
.into_iter()
292-
.map(|(rolegroup_name, role_group)| {
293-
(
294-
self.rolegroup_ref(HdfsNodeRole::Name.to_string(), rolegroup_name),
295-
role_group.replicas.unwrap_or_default(),
296-
)
297-
})
298-
.collect(),
299-
HdfsNodeRole::Data => self
300-
.spec
301-
.data_nodes
302-
.iter()
303-
.flat_map(|role| &role.role_groups)
304-
// Order rolegroups consistently, to avoid spurious downstream rewrites
305-
.collect::<BTreeMap<_, _>>()
306-
.into_iter()
307-
.map(|(rolegroup_name, role_group)| {
308-
(
309-
self.rolegroup_ref(HdfsNodeRole::Data.to_string(), rolegroup_name),
310-
role_group.replicas.unwrap_or_default(),
311-
)
312-
})
313-
.collect(),
314-
HdfsNodeRole::Journal => self
315-
.spec
316-
.journal_nodes
317-
.iter()
318-
.flat_map(|role| &role.role_groups)
319-
// Order rolegroups consistently, to avoid spurious downstream rewrites
320-
.collect::<BTreeMap<_, _>>()
321-
.into_iter()
322-
.map(|(rolegroup_name, role_group)| {
323-
(
324-
self.rolegroup_ref(HdfsNodeRole::Journal.to_string(), rolegroup_name),
325-
role_group.replicas.unwrap_or_default(),
326-
)
327-
})
328-
.collect(),
329-
}
330-
}
331-
332267
pub fn upgrade_state(&self) -> Result<Option<UpgradeState>, UpgradeStateError> {
333268
use upgrade_state_error::*;
334269
let Some(status) = self.status.as_ref() else {

rust/operator-binary/src/event.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ use stackable_operator::{
55
};
66
use strum::{EnumDiscriminants, IntoStaticStr};
77

8-
use crate::{
9-
crd::{HdfsNodeRole, v1alpha1},
10-
hdfs_controller::Ctx,
11-
};
8+
use crate::{controller::ValidatedCluster, crd::HdfsNodeRole, hdfs_controller::Ctx};
129

1310
#[derive(Snafu, Debug, EnumDiscriminants)]
1411
#[strum_discriminants(derive(IntoStaticStr))]
@@ -43,16 +40,18 @@ pub async fn publish_warning_event(
4340
}
4441

4542
pub fn build_invalid_replica_message(
46-
hdfs: &v1alpha1::HdfsCluster,
43+
validated_cluster: &ValidatedCluster,
4744
role: &HdfsNodeRole,
48-
dfs_replication: u8,
4945
) -> Option<String> {
50-
let replicas: u16 = hdfs
51-
.rolegroup_ref_and_replicas(role)
52-
.iter()
53-
.map(|tuple| tuple.1)
46+
let replicas: u16 = validated_cluster
47+
.role_groups
48+
.get(role)
49+
.into_iter()
50+
.flatten()
51+
.map(|(_, role_group)| role_group.replicas.unwrap_or_default())
5452
.sum();
5553

54+
let dfs_replication = validated_cluster.cluster_config.dfs_replication;
5655
let role_name = role.to_string();
5756
let min_replicas = role.min_replicas();
5857

rust/operator-binary/src/hdfs_controller.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ pub async fn reconcile_hdfs(
213213
.await
214214
.context(ApplyRoleBindingSnafu)?;
215215

216-
let dfs_replication = hdfs.spec.cluster_config.dfs_replication;
217216
let mut ss_cond_builder = StatefulSetConditionBuilder::default();
218217

219218
let upgrade_state = validated_cluster.status.upgrade_state;
@@ -238,7 +237,7 @@ pub async fn reconcile_hdfs(
238237
continue;
239238
};
240239

241-
if let Some(message) = build_invalid_replica_message(hdfs, &role, dfs_replication) {
240+
if let Some(message) = build_invalid_replica_message(&validated_cluster, &role) {
242241
publish_warning_event(
243242
&ctx,
244243
&hdfs_obj_ref,

0 commit comments

Comments
 (0)