@@ -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 {
663663mod 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 ( ) {
0 commit comments