Skip to content

Commit 3c10d6b

Browse files
committed
refactor: use strict v2 VolumeName/ContainerName types
1 parent dfd6551 commit 3c10d6b

2 files changed

Lines changed: 37 additions & 29 deletions

File tree

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

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use stackable_operator::{
4040
product_logging::framework::{
4141
STACKABLE_LOG_DIR, ValidatedContainerLogConfigChoice, vector_container,
4242
},
43-
types::kubernetes::{ContainerName, PersistentVolumeClaimName, VolumeName},
43+
types::kubernetes::{PersistentVolumeClaimName, VolumeName},
4444
},
4545
};
4646

@@ -58,10 +58,10 @@ use crate::{
5858
},
5959
},
6060
crd::{
61-
HIVE_PORT, HIVE_PORT_NAME, HiveRole, METRICS_PORT, METRICS_PORT_NAME, STACKABLE_CONFIG_DIR,
62-
STACKABLE_CONFIG_DIR_NAME, STACKABLE_CONFIG_MOUNT_DIR, STACKABLE_CONFIG_MOUNT_DIR_NAME,
63-
STACKABLE_LOG_CONFIG_MOUNT_DIR, STACKABLE_LOG_CONFIG_MOUNT_DIR_NAME,
64-
STACKABLE_LOG_DIR_NAME,
61+
Container, HIVE_PORT, HIVE_PORT_NAME, HiveRole, METRICS_PORT, METRICS_PORT_NAME,
62+
STACKABLE_CONFIG_DIR, STACKABLE_CONFIG_DIR_NAME, STACKABLE_CONFIG_MOUNT_DIR,
63+
STACKABLE_CONFIG_MOUNT_DIR_NAME, STACKABLE_LOG_CONFIG_MOUNT_DIR,
64+
STACKABLE_LOG_CONFIG_MOUNT_DIR_NAME, STACKABLE_LOG_DIR_NAME,
6565
},
6666
};
6767

@@ -110,14 +110,8 @@ pub enum Error {
110110

111111
type Result<T, E = Error> = std::result::Result<T, E>;
112112

113-
stackable_operator::constant!(VECTOR_CONTAINER_NAME: ContainerName = "vector");
114-
115-
// The main Hive container's name. Reuses the `APP_NAME` value (`hive`) so the produced
116-
// Container `name` is unchanged.
117-
stackable_operator::constant!(HIVE_CONTAINER_NAME: ContainerName = "hive");
118-
119-
// Typed name for the listener-operator PersistentVolumeClaim. Reuses the existing
120-
// `LISTENER_VOLUME_NAME` string value (`listener`) so the produced PVC name is unchanged.
113+
// Typed name for the listener-operator PersistentVolumeClaim. The volume mount that exposes the
114+
// PVC reuses this same name, since a volume mount references its claim by name.
121115
stackable_operator::constant!(LISTENER_PVC_NAME: PersistentVolumeClaimName = "listener");
122116

123117
// Typed `VolumeName`s for the Vector container's log-config and log volumes. These reuse the
@@ -126,8 +120,7 @@ stackable_operator::constant!(LISTENER_PVC_NAME: PersistentVolumeClaimName = "li
126120
stackable_operator::constant!(VECTOR_LOG_CONFIG_VOLUME_NAME: VolumeName = "config-mount");
127121
stackable_operator::constant!(VECTOR_LOG_VOLUME_NAME: VolumeName = "log");
128122

129-
// Listener volumes (consumed by the listener-operator PVC and its volume mount below).
130-
pub const LISTENER_VOLUME_NAME: &str = "listener";
123+
// Mount path of the listener volume (consumed by the listener-operator PVC's volume mount below).
131124
pub const LISTENER_VOLUME_DIR: &str = "/stackable/listener";
132125

133126
// Typed name for the HDFS discovery ConfigMap volume, reusing the existing `"hdfs-discovery"`
@@ -157,7 +150,7 @@ pub(crate) fn build_metastore_rolegroup_statefulset(
157150
let merged_config = &rg.config;
158151
let hive_opa_config = cluster.cluster_config.hive_opa_config.as_ref();
159152

160-
let mut container_builder = new_container_builder(&HIVE_CONTAINER_NAME);
153+
let mut container_builder = new_container_builder(&Container::Hive.to_container_name());
161154

162155
container_builder
163156
.add_env_var(
@@ -282,14 +275,17 @@ pub(crate) fn build_metastore_rolegroup_statefulset(
282275
s3_connection,
283276
hive_opa_config,
284277
))
285-
.add_volume_mount(STACKABLE_CONFIG_DIR_NAME, STACKABLE_CONFIG_DIR)
278+
.add_volume_mount(&*STACKABLE_CONFIG_DIR_NAME, STACKABLE_CONFIG_DIR)
286279
.context(AddVolumeMountSnafu)?
287-
.add_volume_mount(STACKABLE_CONFIG_MOUNT_DIR_NAME, STACKABLE_CONFIG_MOUNT_DIR)
280+
.add_volume_mount(
281+
&*STACKABLE_CONFIG_MOUNT_DIR_NAME,
282+
STACKABLE_CONFIG_MOUNT_DIR,
283+
)
288284
.context(AddVolumeMountSnafu)?
289-
.add_volume_mount(STACKABLE_LOG_DIR_NAME, STACKABLE_LOG_DIR)
285+
.add_volume_mount(&*STACKABLE_LOG_DIR_NAME, STACKABLE_LOG_DIR)
290286
.context(AddVolumeMountSnafu)?
291287
.add_volume_mount(
292-
STACKABLE_LOG_CONFIG_MOUNT_DIR_NAME,
288+
&*STACKABLE_LOG_CONFIG_MOUNT_DIR_NAME,
293289
STACKABLE_LOG_CONFIG_MOUNT_DIR,
294290
)
295291
.context(AddVolumeMountSnafu)?
@@ -344,7 +340,7 @@ pub(crate) fn build_metastore_rolegroup_statefulset(
344340
);
345341

346342
container_builder
347-
.add_volume_mount(LISTENER_VOLUME_NAME, LISTENER_VOLUME_DIR)
343+
.add_volume_mount(&*LISTENER_PVC_NAME, LISTENER_VOLUME_DIR)
348344
.context(AddVolumeMountSnafu)?;
349345

350346
pod_builder
@@ -369,7 +365,7 @@ pub(crate) fn build_metastore_rolegroup_statefulset(
369365
})
370366
.context(AddVolumeSnafu)?
371367
.add_empty_dir_volume(
372-
STACKABLE_LOG_DIR_NAME,
368+
&*STACKABLE_LOG_DIR_NAME,
373369
Some(product_logging::framework::calculate_log_volume_size_limit(
374370
&[MAX_HIVE_LOG_FILES_SIZE],
375371
)),
@@ -413,7 +409,7 @@ pub(crate) fn build_metastore_rolegroup_statefulset(
413409
// default, is started first and can provide any dependencies that vector expects
414410
if let Some(vector_log_config) = &rg.config.logging.vector_container {
415411
pod_builder.add_container(vector_container(
416-
&VECTOR_CONTAINER_NAME,
412+
&Container::Vector.to_container_name(),
417413
resolved_product_image,
418414
vector_log_config,
419415
&resource_names,

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ use stackable_operator::{
3535
role_utils::JavaCommonConfig,
3636
types::{
3737
common::Port,
38-
kubernetes::{ConfigMapName, ListenerClassName, SecretClassName},
38+
kubernetes::{
39+
ConfigMapName, ContainerName, ListenerClassName, SecretClassName, VolumeName,
40+
},
3941
},
4042
},
4143
versioned::versioned,
@@ -52,14 +54,16 @@ pub mod security;
5254
pub const FIELD_MANAGER: &str = "hive-operator";
5355
pub const APP_NAME: &str = "hive";
5456

55-
// Directories
57+
// Directory mount paths
5658
pub const STACKABLE_CONFIG_DIR: &str = "/stackable/config";
57-
pub const STACKABLE_CONFIG_DIR_NAME: &str = "config";
5859
pub const STACKABLE_CONFIG_MOUNT_DIR: &str = "/stackable/mount/config";
59-
pub const STACKABLE_CONFIG_MOUNT_DIR_NAME: &str = "config-mount";
60-
pub const STACKABLE_LOG_DIR_NAME: &str = "log";
6160
pub const STACKABLE_LOG_CONFIG_MOUNT_DIR: &str = "/stackable/mount/log-config";
62-
pub const STACKABLE_LOG_CONFIG_MOUNT_DIR_NAME: &str = "log-config-mount";
61+
62+
// Volume names for the directories above
63+
stackable_operator::constant!(pub STACKABLE_CONFIG_DIR_NAME: VolumeName = "config");
64+
stackable_operator::constant!(pub STACKABLE_CONFIG_MOUNT_DIR_NAME: VolumeName = "config-mount");
65+
stackable_operator::constant!(pub STACKABLE_LOG_DIR_NAME: VolumeName = "log");
66+
stackable_operator::constant!(pub STACKABLE_LOG_CONFIG_MOUNT_DIR_NAME: VolumeName = "log-config-mount");
6367

6468
// Default ports
6569
pub const HIVE_PORT_NAME: &str = "hive";
@@ -284,6 +288,14 @@ pub enum Container {
284288
Vector,
285289
}
286290

291+
impl Container {
292+
/// The type-safe container name for this variant (matching its kebab-case serialization).
293+
pub fn to_container_name(&self) -> ContainerName {
294+
ContainerName::from_str(&self.to_string())
295+
.expect("a Container variant name is a valid container name")
296+
}
297+
}
298+
287299
#[derive(Clone, Debug, Default, JsonSchema, PartialEq, Fragment)]
288300
#[fragment_attrs(
289301
derive(

0 commit comments

Comments
 (0)