Skip to content

Commit d70d8f2

Browse files
committed
fix: move hardcoded values to constants
1 parent 39fcb0d commit d70d8f2

2 files changed

Lines changed: 63 additions & 36 deletions

File tree

rust/operator-binary/src/authentication/password/file.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use stackable_operator::{
1818
};
1919

2020
use crate::{
21-
authentication::password::PASSWORD_AUTHENTICATOR_NAME, trino_controller::STACKABLE_LOG_DIR,
21+
authentication::password::PASSWORD_AUTHENTICATOR_NAME,
22+
controller::build::resource::statefulset::LOG_VOLUME_NAME, trino_controller::STACKABLE_LOG_DIR,
2223
};
2324

2425
// mounts
@@ -189,7 +190,7 @@ wait_for_termination $!
189190
.add_volume_mounts(volume_mounts)
190191
.context(AddVolumeMountsSnafu)?
191192
// fixed
192-
.add_volume_mount("log", STACKABLE_LOG_DIR)
193+
.add_volume_mount(&*LOG_VOLUME_NAME, STACKABLE_LOG_DIR)
193194
.context(AddVolumeMountsSnafu)?
194195
.resources(
195196
ResourceRequirementsBuilder::new()

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

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,21 @@ use crate::{
6262
};
6363

6464
stackable_operator::constant!(VECTOR_CONTAINER_NAME: ContainerName = "vector");
65-
// The Vector agent reads its `vector.yaml` from the rolegroup ConfigMap (mounted as the "config"
66-
// volume) and writes its state under the shared "log" volume.
67-
stackable_operator::constant!(VECTOR_LOG_CONFIG_VOLUME_NAME: VolumeName = "config");
68-
stackable_operator::constant!(VECTOR_LOG_VOLUME_NAME: VolumeName = "log");
65+
66+
// Typed names for the Pod's volumes, so each volume definition and its matching volume mounts
67+
// stay in sync. The Vector agent reads its `vector.yaml` from the rolegroup ConfigMap (mounted as
68+
// the `config` volume) and writes its state under the shared `log` volume.
69+
stackable_operator::constant!(CONFIG_VOLUME_NAME: VolumeName = "config");
70+
stackable_operator::constant!(RW_CONFIG_VOLUME_NAME: VolumeName = "rwconfig");
71+
stackable_operator::constant!(CATALOG_VOLUME_NAME: VolumeName = "catalog");
72+
stackable_operator::constant!(LOG_CONFIG_VOLUME_NAME: VolumeName = "log-config");
73+
// `log` is also mounted by the password-file-updater container built in the authentication module.
74+
stackable_operator::constant!(pub LOG_VOLUME_NAME: VolumeName = "log");
75+
stackable_operator::constant!(SERVER_TLS_MOUNT_VOLUME_NAME: VolumeName = "server-tls-mount");
76+
stackable_operator::constant!(SERVER_TLS_VOLUME_NAME: VolumeName = "server-tls");
77+
stackable_operator::constant!(CLIENT_TLS_VOLUME_NAME: VolumeName = "client-tls");
78+
stackable_operator::constant!(INTERNAL_TLS_MOUNT_VOLUME_NAME: VolumeName = "internal-tls-mount");
79+
stackable_operator::constant!(INTERNAL_TLS_VOLUME_NAME: VolumeName = "internal-tls");
6980

7081
#[derive(Snafu, Debug)]
7182
pub enum Error {
@@ -279,11 +290,11 @@ pub fn build_rolegroup_statefulset(
279290
"-c".to_string(),
280291
])
281292
.args(vec![prepare_args.join("\n")])
282-
.add_volume_mount("rwconfig", RW_CONFIG_DIR_NAME)
293+
.add_volume_mount(&*RW_CONFIG_VOLUME_NAME, RW_CONFIG_DIR_NAME)
283294
.context(AddVolumeMountSnafu)?
284-
.add_volume_mount("log-config", STACKABLE_LOG_CONFIG_DIR)
295+
.add_volume_mount(&*LOG_CONFIG_VOLUME_NAME, STACKABLE_LOG_CONFIG_DIR)
285296
.context(AddVolumeMountSnafu)?
286-
.add_volume_mount("log", STACKABLE_LOG_DIR)
297+
.add_volume_mount(&*LOG_VOLUME_NAME, STACKABLE_LOG_DIR)
287298
.context(AddVolumeMountSnafu)?
288299
.resources(
289300
ResourceRequirementsBuilder::new()
@@ -326,13 +337,16 @@ pub fn build_rolegroup_statefulset(
326337
command::container_trino_args(trino_authentication_config, catalogs).join("\n"),
327338
])
328339
.add_env_vars(env)
329-
.add_volume_mount("config", CONFIG_DIR_NAME)
340+
.add_volume_mount(&*CONFIG_VOLUME_NAME, CONFIG_DIR_NAME)
330341
.context(AddVolumeMountSnafu)?
331-
.add_volume_mount("rwconfig", RW_CONFIG_DIR_NAME)
342+
.add_volume_mount(&*RW_CONFIG_VOLUME_NAME, RW_CONFIG_DIR_NAME)
332343
.context(AddVolumeMountSnafu)?
333-
.add_volume_mount("catalog", format!("{}/catalog", CONFIG_DIR_NAME))
344+
.add_volume_mount(
345+
&*CATALOG_VOLUME_NAME,
346+
format!("{}/catalog", CONFIG_DIR_NAME),
347+
)
334348
.context(AddVolumeMountSnafu)?
335-
.add_volume_mount("log", STACKABLE_LOG_DIR)
349+
.add_volume_mount(&*LOG_VOLUME_NAME, STACKABLE_LOG_DIR)
336350
.context(AddVolumeMountSnafu)?
337351
.add_container_ports(container_ports(cluster))
338352
.resources(merged_config.resources.clone().into())
@@ -356,7 +370,7 @@ pub fn build_rolegroup_statefulset(
356370
};
357371
pod_builder
358372
.add_volume(Volume {
359-
name: "log-config".to_string(),
373+
name: LOG_CONFIG_VOLUME_NAME.to_string(),
360374
config_map: Some(ConfigMapVolumeSource {
361375
name: log_config_volume_config_map,
362376
..ConfigMapVolumeSource::default()
@@ -371,8 +385,8 @@ pub fn build_rolegroup_statefulset(
371385
resolved_product_image,
372386
vector_log_config,
373387
&resource_names,
374-
&VECTOR_LOG_CONFIG_VOLUME_NAME,
375-
&VECTOR_LOG_VOLUME_NAME,
388+
&CONFIG_VOLUME_NAME,
389+
&LOG_VOLUME_NAME,
376390
EnvVarSet::new(),
377391
));
378392
}
@@ -392,18 +406,18 @@ pub fn build_rolegroup_statefulset(
392406
.affinity(&merged_config.affinity)
393407
.add_init_container(container_prepare)
394408
.add_volume(Volume {
395-
name: "config".to_string(),
409+
name: CONFIG_VOLUME_NAME.to_string(),
396410
config_map: Some(ConfigMapVolumeSource {
397411
name: config_map_name.clone(),
398412
..ConfigMapVolumeSource::default()
399413
}),
400414
..Volume::default()
401415
})
402416
.context(AddVolumeSnafu)?
403-
.add_empty_dir_volume("rwconfig", None)
417+
.add_empty_dir_volume(&*RW_CONFIG_VOLUME_NAME, None)
404418
.context(AddVolumeSnafu)?
405419
.add_volume(Volume {
406-
name: "catalog".to_string(),
420+
name: CATALOG_VOLUME_NAME.to_string(),
407421
config_map: Some(ConfigMapVolumeSource {
408422
name: format!("{config_map_name}-catalog"),
409423
..ConfigMapVolumeSource::default()
@@ -412,7 +426,7 @@ pub fn build_rolegroup_statefulset(
412426
})
413427
.context(AddVolumeSnafu)?
414428
.add_empty_dir_volume(
415-
"log",
429+
&*LOG_VOLUME_NAME,
416430
Some(product_logging::framework::calculate_log_volume_size_limit(
417431
&[MAX_TRINO_LOG_FILES_SIZE, MAX_PREPARE_LOG_FILE_SIZE],
418432
)),
@@ -588,7 +602,7 @@ fn finished_starting_probe(cluster: &ValidatedCluster) -> ExecAction {
588602
}
589603

590604
fn create_tls_volume(
591-
volume_name: &str,
605+
volume_name: impl Into<String>,
592606
tls_secret_class: &str,
593607
requested_secret_lifetime: &Duration,
594608
listener_scope: Option<String>,
@@ -632,14 +646,20 @@ fn tls_volume_mounts(
632646

633647
if let Some(server_tls) = cluster.get_server_tls() {
634648
cb_prepare
635-
.add_volume_mount("server-tls-mount", STACKABLE_MOUNT_SERVER_TLS_DIR)
649+
.add_volume_mount(
650+
&*SERVER_TLS_MOUNT_VOLUME_NAME,
651+
STACKABLE_MOUNT_SERVER_TLS_DIR,
652+
)
636653
.context(AddVolumeMountSnafu)?;
637654
cb_trino
638-
.add_volume_mount("server-tls-mount", STACKABLE_MOUNT_SERVER_TLS_DIR)
655+
.add_volume_mount(
656+
&*SERVER_TLS_MOUNT_VOLUME_NAME,
657+
STACKABLE_MOUNT_SERVER_TLS_DIR,
658+
)
639659
.context(AddVolumeMountSnafu)?;
640660
pod_builder
641661
.add_volume(create_tls_volume(
642-
"server-tls-mount",
662+
&*SERVER_TLS_MOUNT_VOLUME_NAME,
643663
server_tls,
644664
requested_secret_lifetime,
645665
// add listener
@@ -649,49 +669,55 @@ fn tls_volume_mounts(
649669
}
650670

651671
cb_prepare
652-
.add_volume_mount("server-tls", STACKABLE_SERVER_TLS_DIR)
672+
.add_volume_mount(&*SERVER_TLS_VOLUME_NAME, STACKABLE_SERVER_TLS_DIR)
653673
.context(AddVolumeMountSnafu)?;
654674
cb_trino
655-
.add_volume_mount("server-tls", STACKABLE_SERVER_TLS_DIR)
675+
.add_volume_mount(&*SERVER_TLS_VOLUME_NAME, STACKABLE_SERVER_TLS_DIR)
656676
.context(AddVolumeMountSnafu)?;
657677
pod_builder
658-
.add_empty_dir_volume("server-tls", None)
678+
.add_empty_dir_volume(&*SERVER_TLS_VOLUME_NAME, None)
659679
.context(AddVolumeSnafu)?;
660680

661681
cb_prepare
662-
.add_volume_mount("client-tls", STACKABLE_CLIENT_TLS_DIR)
682+
.add_volume_mount(&*CLIENT_TLS_VOLUME_NAME, STACKABLE_CLIENT_TLS_DIR)
663683
.context(AddVolumeMountSnafu)?;
664684
cb_trino
665-
.add_volume_mount("client-tls", STACKABLE_CLIENT_TLS_DIR)
685+
.add_volume_mount(&*CLIENT_TLS_VOLUME_NAME, STACKABLE_CLIENT_TLS_DIR)
666686
.context(AddVolumeMountSnafu)?;
667687
pod_builder
668-
.add_empty_dir_volume("client-tls", None)
688+
.add_empty_dir_volume(&*CLIENT_TLS_VOLUME_NAME, None)
669689
.context(AddVolumeSnafu)?;
670690

671691
if let Some(internal_tls) = cluster.get_internal_tls() {
672692
cb_prepare
673-
.add_volume_mount("internal-tls-mount", STACKABLE_MOUNT_INTERNAL_TLS_DIR)
693+
.add_volume_mount(
694+
&*INTERNAL_TLS_MOUNT_VOLUME_NAME,
695+
STACKABLE_MOUNT_INTERNAL_TLS_DIR,
696+
)
674697
.context(AddVolumeMountSnafu)?;
675698
cb_trino
676-
.add_volume_mount("internal-tls-mount", STACKABLE_MOUNT_INTERNAL_TLS_DIR)
699+
.add_volume_mount(
700+
&*INTERNAL_TLS_MOUNT_VOLUME_NAME,
701+
STACKABLE_MOUNT_INTERNAL_TLS_DIR,
702+
)
677703
.context(AddVolumeMountSnafu)?;
678704
pod_builder
679705
.add_volume(create_tls_volume(
680-
"internal-tls-mount",
706+
&*INTERNAL_TLS_MOUNT_VOLUME_NAME,
681707
internal_tls,
682708
requested_secret_lifetime,
683709
None,
684710
)?)
685711
.context(AddVolumeSnafu)?;
686712

687713
cb_prepare
688-
.add_volume_mount("internal-tls", STACKABLE_INTERNAL_TLS_DIR)
714+
.add_volume_mount(&*INTERNAL_TLS_VOLUME_NAME, STACKABLE_INTERNAL_TLS_DIR)
689715
.context(AddVolumeMountSnafu)?;
690716
cb_trino
691-
.add_volume_mount("internal-tls", STACKABLE_INTERNAL_TLS_DIR)
717+
.add_volume_mount(&*INTERNAL_TLS_VOLUME_NAME, STACKABLE_INTERNAL_TLS_DIR)
692718
.context(AddVolumeMountSnafu)?;
693719
pod_builder
694-
.add_empty_dir_volume("internal-tls", None)
720+
.add_empty_dir_volume(&*INTERNAL_TLS_VOLUME_NAME, None)
695721
.context(AddVolumeSnafu)?;
696722
}
697723

0 commit comments

Comments
 (0)