Skip to content

Commit 7132255

Browse files
committed
review feedback
1 parent 27b0036 commit 7132255

4 files changed

Lines changed: 28 additions & 28 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub enum Error {
5454
/// Builds the Kubernetes resources for the given validated cluster.
5555
///
5656
/// Does not need a Kubernetes client: every reference to another Kubernetes resource is already
57-
/// dereferenced and validated by this point. The remaining errors are resource-assembly failures
58-
/// only.
57+
/// dereferenced and validated by this point.
58+
/// The remaining errors are resource-assembly failures only.
5959
///
6060
/// `service_account_name` is the name of the RBAC `ServiceAccount` the role-group Pods run under
6161
/// (RBAC resources are built and applied separately, in the reconcile step).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn build_pdb(
2727
let pdb = pod_disruption_budget_builder_with_role(
2828
cluster,
2929
&product_name(),
30-
&ValidatedCluster::role_name(role),
30+
&role.into(),
3131
&operator_name(),
3232
&controller_name(),
3333
)

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

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,6 @@ impl ValidatedCluster {
197197
.expect("every DruidRole has a validated role config")
198198
}
199199

200-
/// The type-safe role name for a Druid role.
201-
pub(crate) fn role_name(role: &DruidRole) -> RoleName {
202-
RoleName::from_str(&role.to_string())
203-
.expect("a DruidRole always serializes to a valid role name")
204-
}
205-
206200
fn recommended_labels_with(
207201
&self,
208202
product_version: &ProductVersion,
@@ -232,7 +226,7 @@ impl ValidatedCluster {
232226

233227
/// Recommended labels for a role-group resource.
234228
pub fn recommended_labels(&self, role: &DruidRole, role_group_name: &RoleGroupName) -> Labels {
235-
self.recommended_labels_for(&Self::role_name(role), role_group_name)
229+
self.recommended_labels_for(&role.into(), role_group_name)
236230
}
237231

238232
/// Recommended labels with the constant [`UNVERSIONED_PRODUCT_VERSION`], for PVC templates
@@ -242,21 +236,12 @@ impl ValidatedCluster {
242236
role: &DruidRole,
243237
role_group_name: &RoleGroupName,
244238
) -> Labels {
245-
self.recommended_labels_with(
246-
&UNVERSIONED_PRODUCT_VERSION,
247-
&Self::role_name(role),
248-
role_group_name,
249-
)
239+
self.recommended_labels_with(&UNVERSIONED_PRODUCT_VERSION, &role.into(), role_group_name)
250240
}
251241

252242
/// Selector labels matching the pods of a role group.
253243
pub fn role_group_selector(&self, role: &DruidRole, role_group_name: &RoleGroupName) -> Labels {
254-
role_group_selector(
255-
self,
256-
&product_name(),
257-
&Self::role_name(role),
258-
role_group_name,
259-
)
244+
role_group_selector(self, &product_name(), &role.into(), role_group_name)
260245
}
261246

262247
/// Returns an [`ObjectMetaBuilder`] pre-filled with the namespace, an owner reference back to
@@ -296,7 +281,7 @@ impl ValidatedCluster {
296281
) -> ResourceNames {
297282
ResourceNames {
298283
cluster_name: self.name.clone(),
299-
role_name: Self::role_name(role),
284+
role_name: role.into(),
300285
role_group_name: role_group_name.clone(),
301286
}
302287
}
@@ -610,11 +595,11 @@ spec:
610595

611596
#[cfg(test)]
612597
mod tests {
613-
use stackable_operator::cli::OperatorEnvironmentOptions;
598+
use stackable_operator::{cli::OperatorEnvironmentOptions, v2::types::operator::RoleName};
614599
use strum::IntoEnumIterator;
615600

616601
use super::{
617-
Error, ValidatedCluster,
602+
Error,
618603
test_support::{MINIMAL_DRUID_YAML, druid_from_yaml},
619604
validate,
620605
};
@@ -719,12 +704,13 @@ mod tests {
719704
);
720705
}
721706

722-
/// Locks the invariant behind the `expect` in [`ValidatedCluster::role_name`]: every
723-
/// `DruidRole` variant (present and future) must serialise to a valid `RoleName`.
707+
/// Locks the invariant behind the `expect` in the `From<DruidRole> for RoleName` impls:
708+
/// every `DruidRole` variant (present and future) must serialise to a valid `RoleName`.
724709
#[test]
725710
fn every_druid_role_serialises_to_a_valid_role_name() {
726711
for role in DruidRole::iter() {
727-
ValidatedCluster::role_name(&role);
712+
let _: RoleName = (&role).into();
713+
let _: RoleName = role.into();
728714
}
729715
}
730716
}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use stackable_operator::{
4646
types::{
4747
common::Port,
4848
kubernetes::{ConfigMapName, ContainerName, ListenerClassName},
49-
operator::RoleGroupName,
49+
operator::{RoleGroupName, RoleName},
5050
},
5151
},
5252
versioned::versioned,
@@ -630,6 +630,20 @@ pub enum DruidRole {
630630
Router,
631631
}
632632

633+
impl From<DruidRole> for RoleName {
634+
fn from(value: DruidRole) -> Self {
635+
RoleName::from_str(&value.to_string())
636+
.expect("a DruidRole always serializes to a valid role name")
637+
}
638+
}
639+
640+
impl From<&DruidRole> for RoleName {
641+
fn from(value: &DruidRole) -> Self {
642+
RoleName::from_str(&value.to_string())
643+
.expect("a DruidRole always serializes to a valid role name")
644+
}
645+
}
646+
633647
impl DruidRole {
634648
/// Returns the name of the internal druid process name associated with the role.
635649
/// These strings are used by druid internally to identify processes.

0 commit comments

Comments
 (0)