Skip to content

Commit 1a96afe

Browse files
committed
fix: cleanup constants
1 parent 976e914 commit 1a96afe

4 files changed

Lines changed: 40 additions & 17 deletions

File tree

rust/operator-binary/src/controller/build/git_sync.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use snafu::{ResultExt, Snafu};
44
use stackable_operator::{crd::git_sync, k8s_openapi::api::core::v1::EnvVar};
55

66
use crate::{
7-
controller::{ValidatedCluster, ValidatedRoleGroupConfig},
7+
controller::{
8+
ValidatedCluster, ValidatedRoleGroupConfig, build::resource::statefulset::LOG_VOLUME_NAME,
9+
},
810
crd::Container,
9-
nifi_controller::LOG_VOLUME_NAME,
1011
};
1112

1213
#[derive(Snafu, Debug)]

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

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ use crate::{
6767
storage::{NifiRepository, PERSISTENT_REPOSITORIES},
6868
v1alpha1,
6969
},
70-
nifi_controller::LOG_VOLUME_NAME,
7170
security::{
7271
authentication::{
7372
NifiAuthenticationConfig, STACKABLE_SERVER_TLS_DIR, STACKABLE_TLS_STORE_PASSWORD,
@@ -134,6 +133,26 @@ type Result<T, E = Error> = std::result::Result<T, E>;
134133

135134
const USERDATA_MOUNTPOINT: &str = "/stackable/userdata";
136135

136+
/// Volume providing the rendered NiFi config (the `conf` ConfigMap), mounted into the prepare
137+
/// container which templates it into [`ACTIVE_CONFIG_VOLUME_NAME`].
138+
const CONFIG_VOLUME_NAME: &str = "conf";
139+
const CONFIG_VOLUME_MOUNT: &str = "/conf";
140+
141+
/// `emptyDir` holding the live config templated by the prepare container and shared with the NiFi
142+
/// container.
143+
const ACTIVE_CONFIG_VOLUME_NAME: &str = "activeconf";
144+
145+
/// Volume holding the generated sensitive-properties key.
146+
const SENSITIVE_PROPERTY_VOLUME_NAME: &str = "sensitiveproperty";
147+
const SENSITIVE_PROPERTY_VOLUME_MOUNT: &str = "/stackable/sensitiveproperty";
148+
149+
/// Volume providing the log config (logback/log4j) ConfigMap.
150+
const LOG_CONFIG_VOLUME_NAME: &str = "log-config";
151+
152+
/// Volume the NiFi logs are written to and shared with the Vector sidecar (also used by the
153+
/// git-sync container, see [`crate::controller::build::git_sync`]).
154+
pub(crate) const LOG_VOLUME_NAME: &str = "log";
155+
137156
/// The rolegroup [`StatefulSet`] runs the rolegroup, as configured by the administrator.
138157
///
139158
/// The [`Pod`](`stackable_operator::k8s_openapi::api::core::v1::Pod`)s are accessible through the
@@ -325,13 +344,16 @@ pub(crate) async fn build_node_rolegroup_statefulset(
325344
.map(NifiRepository::volume_mount),
326345
)
327346
.context(AddVolumeMountSnafu)?
328-
.add_volume_mount("conf", "/conf")
347+
.add_volume_mount(CONFIG_VOLUME_NAME, CONFIG_VOLUME_MOUNT)
329348
.context(AddVolumeMountSnafu)?
330349
.add_volume_mount(KEYSTORE_VOLUME_NAME, KEYSTORE_NIFI_CONTAINER_MOUNT)
331350
.context(AddVolumeMountSnafu)?
332-
.add_volume_mount("activeconf", NIFI_CONFIG_DIRECTORY)
351+
.add_volume_mount(ACTIVE_CONFIG_VOLUME_NAME, NIFI_CONFIG_DIRECTORY)
333352
.context(AddVolumeMountSnafu)?
334-
.add_volume_mount("sensitiveproperty", "/stackable/sensitiveproperty")
353+
.add_volume_mount(
354+
SENSITIVE_PROPERTY_VOLUME_NAME,
355+
SENSITIVE_PROPERTY_VOLUME_MOUNT,
356+
)
335357
.context(AddVolumeMountSnafu)?
336358
.add_volume_mount(LOG_VOLUME_NAME, STACKABLE_LOG_DIR)
337359
.context(AddVolumeMountSnafu)?
@@ -392,9 +414,9 @@ pub(crate) async fn build_node_rolegroup_statefulset(
392414
.map(NifiRepository::volume_mount),
393415
)
394416
.context(AddVolumeMountSnafu)?
395-
.add_volume_mount("activeconf", NIFI_CONFIG_DIRECTORY)
417+
.add_volume_mount(ACTIVE_CONFIG_VOLUME_NAME, NIFI_CONFIG_DIRECTORY)
396418
.context(AddVolumeMountSnafu)?
397-
.add_volume_mount("log-config", STACKABLE_LOG_CONFIG_DIR)
419+
.add_volume_mount(LOG_CONFIG_VOLUME_NAME, STACKABLE_LOG_CONFIG_DIR)
398420
.context(AddVolumeMountSnafu)?
399421
.add_volume_mount(LOG_VOLUME_NAME, STACKABLE_LOG_DIR)
400422
.context(AddVolumeMountSnafu)?
@@ -499,7 +521,7 @@ pub(crate) async fn build_node_rolegroup_statefulset(
499521
{
500522
pod_builder
501523
.add_volume(Volume {
502-
name: "log-config".to_string(),
524+
name: LOG_CONFIG_VOLUME_NAME.to_string(),
503525
config_map: Some(ConfigMapVolumeSource {
504526
name: config_map.clone(),
505527
..ConfigMapVolumeSource::default()
@@ -510,7 +532,7 @@ pub(crate) async fn build_node_rolegroup_statefulset(
510532
} else {
511533
pod_builder
512534
.add_volume(Volume {
513-
name: "log-config".to_string(),
535+
name: LOG_CONFIG_VOLUME_NAME.to_string(),
514536
config_map: Some(ConfigMapVolumeSource {
515537
name: resource_names.role_group_config_map().to_string(),
516538
..ConfigMapVolumeSource::default()
@@ -575,7 +597,7 @@ pub(crate) async fn build_node_rolegroup_statefulset(
575597
})
576598
.context(AddVolumeSnafu)?
577599
.add_volume(Volume {
578-
name: "conf".to_string(),
600+
name: CONFIG_VOLUME_NAME.to_string(),
579601
config_map: Some(ConfigMapVolumeSource {
580602
name: resource_names.role_group_config_map().to_string(),
581603
..ConfigMapVolumeSource::default()
@@ -625,7 +647,7 @@ pub(crate) async fn build_node_rolegroup_statefulset(
625647

626648
pod_builder
627649
.add_volume(Volume {
628-
name: "sensitiveproperty".to_string(),
650+
name: SENSITIVE_PROPERTY_VOLUME_NAME.to_string(),
629651
secret: Some(SecretVolumeSource {
630652
secret_name: Some(sensitive_key_secret.to_string()),
631653
..SecretVolumeSource::default()
@@ -638,7 +660,7 @@ pub(crate) async fn build_node_rolegroup_statefulset(
638660
medium: None,
639661
size_limit: None,
640662
}),
641-
name: "activeconf".to_string(),
663+
name: ACTIVE_CONFIG_VOLUME_NAME.to_string(),
642664
..Volume::default()
643665
})
644666
.context(AddVolumeSnafu)?

rust/operator-binary/src/controller/validate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ use crate::{
3131
},
3232
};
3333

34+
/// The base name of the NiFi product image, used to resolve the fully-qualified image reference.
35+
const CONTAINER_IMAGE_BASE_NAME: &str = "nifi";
36+
3437
#[derive(Snafu, Debug, EnumDiscriminants)]
3538
#[strum_discriminants(derive(IntoStaticStr))]
3639
#[allow(clippy::enum_variant_names)]
@@ -83,7 +86,7 @@ pub fn validate(
8386
.spec
8487
.image
8588
.resolve(
86-
crate::nifi_controller::CONTAINER_IMAGE_BASE_NAME,
89+
CONTAINER_IMAGE_BASE_NAME,
8790
&operator_environment.image_repository,
8891
crate::built_info::PKG_VERSION,
8992
)

rust/operator-binary/src/nifi_controller.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ use crate::{
5151
pub const NIFI_CONTROLLER_NAME: &str = "nificluster";
5252
pub const NIFI_FULL_CONTROLLER_NAME: &str = concatcp!(NIFI_CONTROLLER_NAME, '.', OPERATOR_NAME);
5353

54-
pub(crate) const CONTAINER_IMAGE_BASE_NAME: &str = "nifi";
55-
pub(crate) const LOG_VOLUME_NAME: &str = "log";
56-
5754
pub struct Ctx {
5855
pub client: Client,
5956
pub operator_environment: OperatorEnvironmentOptions,

0 commit comments

Comments
 (0)