Skip to content

Commit 9c88001

Browse files
committed
added role impl From, more for compatability as only a single, fixed comment
1 parent 05c3244 commit 9c88001

4 files changed

Lines changed: 37 additions & 13 deletions

File tree

rust/operator-binary/src/controller.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,6 @@ impl ValidatedCluster {
228228
}
229229

230230
/// The single Hive role name (`metastore`).
231-
pub fn role_name() -> RoleName {
232-
RoleName::from_str(&HiveRole::MetaStore.to_string())
233-
.expect("the metastore role name is a valid role name")
234-
}
235-
236231
/// Type-safe names for the per-cluster RBAC resources: the ServiceAccount shared by all
237232
/// Pods, its (namespaced) RoleBinding, and the operator-deployed ClusterRole it binds.
238233
pub fn cluster_resource_names(&self) -> role_utils::ResourceNames {
@@ -249,7 +244,7 @@ impl ValidatedCluster {
249244
) -> ResourceNames {
250245
ResourceNames {
251246
cluster_name: self.name.clone(),
252-
role_name: Self::role_name(),
247+
role_name: HiveRole::MetaStore.into(),
253248
role_group_name: role_group_name.clone(),
254249
}
255250
}
@@ -269,7 +264,7 @@ impl ValidatedCluster {
269264
pub fn unversioned_recommended_labels(&self, role_group_name: &RoleGroupName) -> Labels {
270265
self.recommended_labels_with(
271266
&UNVERSIONED_PRODUCT_VERSION,
272-
&Self::role_name(),
267+
&HiveRole::MetaStore.into(),
273268
role_group_name,
274269
)
275270
}
@@ -294,12 +289,17 @@ impl ValidatedCluster {
294289

295290
/// Recommended labels for a role-group resource.
296291
pub fn recommended_labels(&self, role_group_name: &RoleGroupName) -> Labels {
297-
self.recommended_labels_for(&Self::role_name(), role_group_name)
292+
self.recommended_labels_for(&HiveRole::MetaStore.into(), role_group_name)
298293
}
299294

300295
/// Selector labels matching the pods of a role group.
301296
pub fn role_group_selector(&self, role_group_name: &RoleGroupName) -> Labels {
302-
role_group_selector(self, &product_name(), &Self::role_name(), role_group_name)
297+
role_group_selector(
298+
self,
299+
&product_name(),
300+
&HiveRole::MetaStore.into(),
301+
role_group_name,
302+
)
303303
}
304304

305305
/// Whether Kerberos is enabled for this cluster (a Kerberos `SecretClass` was configured).
@@ -663,7 +663,21 @@ pub(crate) mod test_support {
663663
mod tests {
664664
use std::str::FromStr;
665665

666+
use stackable_operator::v2::types::operator::RoleName;
667+
use strum::IntoEnumIterator;
668+
666669
use super::{RoleGroupName, test_support::*};
670+
use crate::crd::HiveRole;
671+
672+
/// Locks the invariant behind the `expect` in the `From<HiveRole> for RoleName` impls:
673+
/// every `HiveRole` variant (present and future) must serialise to a valid `RoleName`.
674+
#[test]
675+
fn every_hive_role_serialises_to_a_valid_role_name() {
676+
for role in HiveRole::iter() {
677+
let _: RoleName = (&role).into();
678+
let _: RoleName = role.into();
679+
}
680+
}
667681

668682
#[test]
669683
fn object_meta_sets_namespace_owner_and_recommended_labels() {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ pub enum Error {
7070
///
7171
/// `cluster_info` carries the Kubernetes cluster domain (needed by the Kerberos config); it is
7272
/// static cluster metadata, not a live client, so the build step stays client-free.
73-
///
74-
/// `service_account_name` is the name of the RBAC `ServiceAccount` the role-group Pods run under
75-
/// (RBAC resources are built and applied separately, in the reconcile step).
7673
pub fn build(
7774
cluster: &ValidatedCluster,
7875
cluster_info: &KubernetesClusterInfo,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn build_pdb(
2323
let pdb = pod_disruption_budget_builder_with_role(
2424
cluster,
2525
&product_name(),
26-
&ValidatedCluster::role_name(),
26+
&HiveRole::MetaStore.into(),
2727
&operator_name(),
2828
&controller_name(),
2929
)

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use stackable_operator::{
3838
kubernetes::{
3939
ConfigMapName, ContainerName, ListenerClassName, SecretClassName, VolumeName,
4040
},
41+
operator::RoleName,
4142
},
4243
},
4344
versioned::versioned,
@@ -261,6 +262,18 @@ pub enum HiveRole {
261262
MetaStore,
262263
}
263264

265+
impl From<HiveRole> for RoleName {
266+
fn from(value: HiveRole) -> Self {
267+
RoleName::from_str(&value.to_string()).expect("a HiveRole is a valid role name")
268+
}
269+
}
270+
271+
impl From<&HiveRole> for RoleName {
272+
fn from(value: &HiveRole) -> Self {
273+
RoleName::from_str(&value.to_string()).expect("a HiveRole is a valid role name")
274+
}
275+
}
276+
264277
impl HiveRole {
265278
/// A Kerberos principal has three parts, with the form username/fully.qualified.domain.name@YOUR-REALM.COM.
266279
/// We only have one role and will use "hive" everywhere (which e.g. differs from the current hdfs implementation).

0 commit comments

Comments
 (0)