Skip to content

Commit 347bdec

Browse files
authored
fix: make container name accessor infallible (#764)
* fix: make container name accessor infallible * changelog
1 parent e7e7573 commit 347bdec

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ All notable changes to this project will be documented in this file.
2323
StatefulSets created by older operator versions cannot be updated in place: after the
2424
operator upgrade, delete each metastore StatefulSet so that the operator immediately recreates it with
2525
the new labels ([#748]).
26-
- Make operations infallible where dependent on static inputs ([#759]).
26+
- Make operations infallible where dependent on static inputs ([#759], [#764]).
2727

2828
### Fixed
2929

@@ -44,6 +44,7 @@ All notable changes to this project will be documented in this file.
4444
[#748]: https://github.com/stackabletech/hive-operator/pull/748
4545
[#754]: https://github.com/stackabletech/hive-operator/pull/754
4646
[#759]: https://github.com/stackabletech/hive-operator/pull/759
47+
[#764]: https://github.com/stackabletech/hive-operator/pull/764
4748

4849
## [26.7.0] - 2026-07-21
4950

‎rust/operator-binary/src/controller/build/resource/statefulset.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub(crate) fn build_metastore_rolegroup_statefulset(
167167
let merged_config = &rg.config;
168168
let hive_opa_config = cluster.cluster_config.hive_opa_config.as_ref();
169169

170-
let mut container_builder = new_container_builder(&Container::Hive.to_container_name());
170+
let mut container_builder = new_container_builder(Container::Hive.name());
171171

172172
// Operator-set env vars first; the user's `envOverrides` are merged on top last and win.
173173
let mut env = EnvVarSet::new()
@@ -455,7 +455,7 @@ pub(crate) fn build_metastore_rolegroup_statefulset(
455455
// default, is started first and can provide any dependencies that vector expects
456456
if let Some(vector_log_config) = &rg.config.logging.vector_container {
457457
pod_builder.add_container(vector_container(
458-
&Container::Vector.to_container_name(),
458+
Container::Vector.name(),
459459
resolved_product_image,
460460
vector_log_config,
461461
&resource_names,
@@ -612,7 +612,7 @@ mod tests {
612612
.expect("the pod template has a spec")
613613
.containers
614614
.into_iter()
615-
.find(|container| container.name == Container::Hive.to_container_name().to_string())
615+
.find(|container| container.name == Container::Hive.name().to_string())
616616
.expect("the hive container exists")
617617
.env
618618
.expect("the hive container has env vars")

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
296301
impl 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)]
397404
mod 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

Comments
 (0)