@@ -293,11 +293,18 @@ pub enum Container {
293293 Vector ,
294294}
295295
296+ // Typed container names. They must match the strum `Display` (kebab-case) of the variants above,
297+ // which is pinned by a unit test.
298+ constant ! ( HIVE_CONTAINER_NAME : ContainerName = "hive" ) ;
299+ constant ! ( VECTOR_CONTAINER_NAME : ContainerName = "vector" ) ;
300+
296301impl Container {
297- /// The type-safe container name for this variant (matching its kebab-case serialization).
298- pub fn to_container_name ( & self ) -> ContainerName {
299- ContainerName :: from_str ( & self . to_string ( ) )
300- . expect ( "a Container variant name is a valid container name" )
302+ /// The typed container name of this variant.
303+ pub fn name ( & self ) -> & ' static ContainerName {
304+ match self {
305+ Container :: Hive => & HIVE_CONTAINER_NAME ,
306+ Container :: Vector => & VECTOR_CONTAINER_NAME ,
307+ }
301308 }
302309}
303310
@@ -396,6 +403,7 @@ pub struct HiveClusterStatus {
396403#[ cfg( test) ]
397404mod tests {
398405 use stackable_operator:: versioned:: test_utils:: RoundtripTestData ;
406+ use strum:: IntoEnumIterator ;
399407
400408 use super :: * ;
401409
@@ -408,6 +416,17 @@ mod tests {
408416 let _ = * STACKABLE_CONFIG_MOUNT_DIR_NAME ;
409417 let _ = * STACKABLE_LOG_DIR_NAME ;
410418 let _ = * STACKABLE_LOG_CONFIG_MOUNT_DIR_NAME ;
419+ let _ = * HIVE_CONTAINER_NAME ;
420+ let _ = * VECTOR_CONTAINER_NAME ;
421+ }
422+
423+ /// The typed container names returned by `name` must agree with the strum `Display`
424+ /// of `Container`, which the logging configuration still uses as the per-container key.
425+ #[ test]
426+ fn container_names_match_display ( ) {
427+ for container in Container :: iter ( ) {
428+ assert_eq ! ( container. name( ) . to_string( ) , container. to_string( ) ) ;
429+ }
411430 }
412431
413432 impl RoundtripTestData for v1alpha1:: HiveClusterSpec {
0 commit comments