Skip to content

Commit b20a39f

Browse files
committed
fix: consolidate hard coded constants
1 parent 7657b43 commit b20a39f

4 files changed

Lines changed: 36 additions & 17 deletions

File tree

rust/operator-binary/src/controller/build/properties/nifi_properties.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::collections::BTreeMap;
55
use snafu::{ResultExt, ensure};
66
use stackable_operator::memory::MemoryQuantity;
77

8-
use super::format_properties;
8+
use super::{ConfigFileName, format_properties};
99
use crate::{
1010
controller::{
1111
ValidatedCluster, ValidatedRoleGroupConfig,
@@ -14,7 +14,13 @@ use crate::{
1414
},
1515
},
1616
crd::{
17-
HTTPS_PORT, constants::NIFI_PYTHON_WORKING_DIRECTORY, storage::NifiRepository, v1alpha1,
17+
HTTPS_PORT,
18+
constants::{
19+
NIFI_CONFIG_DIRECTORY, NIFI_PYTHON_EXTENSIONS_DIRECTORY,
20+
NIFI_PYTHON_FRAMEWORK_DIRECTORY, NIFI_PYTHON_WORKING_DIRECTORY,
21+
},
22+
storage::NifiRepository,
23+
v1alpha1,
1824
},
1925
security::{
2026
authentication::{
@@ -71,7 +77,7 @@ pub fn build(
7177
);
7278
properties.insert(
7379
"nifi.flow.configuration.archive.dir".to_string(),
74-
"/stackable/nifi/conf/archive/".to_string(),
80+
format!("{NIFI_CONFIG_DIRECTORY}/archive/"),
7581
);
7682
properties.insert(
7783
"nifi.flow.configuration.archive.max.time".to_string(),
@@ -110,11 +116,14 @@ pub fn build(
110116

111117
properties.insert(
112118
"nifi.authorizer.configuration.file".to_string(),
113-
"/stackable/nifi/conf/authorizers.xml".to_string(),
119+
format!("{NIFI_CONFIG_DIRECTORY}/{}", ConfigFileName::Authorizers),
114120
);
115121
properties.insert(
116122
"nifi.login.identity.provider.configuration.file".to_string(),
117-
"/stackable/nifi/conf/login-identity-providers.xml".to_string(),
123+
format!(
124+
"{NIFI_CONFIG_DIRECTORY}/{}",
125+
ConfigFileName::LoginIdentityProviders
126+
),
118127
);
119128
properties.insert(
120129
"nifi.templates.directory".to_string(),
@@ -536,7 +545,7 @@ pub fn build(
536545
// Java processes.
537546
properties.insert(
538547
"nifi.python.framework.source.directory".to_string(),
539-
"/stackable/nifi/python/framework/".to_string(),
548+
NIFI_PYTHON_FRAMEWORK_DIRECTORY.to_string(),
540549
);
541550

542551
// The working directory where NiFi should store artifacts;
@@ -552,7 +561,7 @@ pub fn build(
552561
// (docs/modules/nifi/pages/usage_guide/custom-components.adoc), so do not change it!
553562
properties.insert(
554563
"nifi.python.extensions.source.directory.default".to_string(),
555-
"/stackable/nifi/python/extensions/".to_string(),
564+
NIFI_PYTHON_EXTENSIONS_DIRECTORY.to_string(),
556565
);
557566

558567
for (i, git_folder) in git_sync_resources

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ use crate::{
6060

6161
const REPORTING_TASK_CERT_VOLUME_NAME: &str = "tls";
6262
const REPORTING_TASK_CERT_VOLUME_MOUNT: &str = "/stackable/cert";
63+
/// Path (inside the image) of the script that registers the NiFi 1.x reporting task.
64+
const REPORTING_TASK_SCRIPT_PATH: &str = "/stackable/python/create_nifi_reporting_task.py";
6365
stackable_operator::constant!(REPORTING_TASK_CONTAINER_NAME: ContainerName = "reporting-task");
6466

6567
#[derive(Snafu, Debug)]
@@ -256,7 +258,7 @@ fn build_reporting_task_job(
256258
};
257259

258260
let args = [
259-
"/stackable/python/create_nifi_reporting_task.py".to_string(),
261+
REPORTING_TASK_SCRIPT_PATH.to_string(),
260262
format!("-n {nifi_connect_url}"),
261263
user_name_command,
262264
format!("-p \"$(cat {admin_password_file})\""),

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ const LOG_CONFIG_VOLUME_NAME: &str = "log-config";
133133
/// git-sync container, see [`crate::controller::build::git_sync`]).
134134
pub(crate) const LOG_VOLUME_NAME: &str = "log";
135135

136+
/// `emptyDir` for the Python working directory, mounted into the NiFi container at
137+
/// [`NIFI_PYTHON_WORKING_DIRECTORY`].
138+
const PYTHON_WORKING_DIR_VOLUME_NAME: &str = "nifi-python-working-directory";
139+
136140
// Container names. These must match the corresponding (kebab-cased) `crate::crd::Container`
137141
// variants, which key the per-container logging config.
138142
stackable_operator::constant!(PREPARE_CONTAINER_NAME: ContainerName = "prepare");
@@ -471,12 +475,14 @@ pub(crate) async fn build_node_rolegroup_statefulset(
471475
.context(AddVolumeMountSnafu)?;
472476
}
473477

474-
let volume_name = "nifi-python-working-directory".to_string();
475478
pod_builder
476-
.add_empty_dir_volume(&volume_name, None)
479+
.add_empty_dir_volume(PYTHON_WORKING_DIR_VOLUME_NAME, None)
477480
.context(AddVolumeSnafu)?;
478481
container_nifi
479-
.add_volume_mount(&volume_name, NIFI_PYTHON_WORKING_DIRECTORY)
482+
.add_volume_mount(
483+
PYTHON_WORKING_DIR_VOLUME_NAME,
484+
NIFI_PYTHON_WORKING_DIRECTORY,
485+
)
480486
.context(AddVolumeMountSnafu)?;
481487

482488
container_nifi
@@ -553,15 +559,15 @@ pub(crate) async fn build_node_rolegroup_statefulset(
553559
.image_pull_secrets_from_product_image(resolved_product_image)
554560
.add_init_container(container_prepare.build())
555561
.affinity(&merged_config.affinity)
556-
// One volume for the NiFi configuration. A script will later on edit (e.g. nodename)
557-
// and copy the whole content to the <NIFI_HOME>/conf folder.
558-
.add_volume(stackable_operator::k8s_openapi::api::core::v1::Volume {
559-
name: "config".to_string(),
562+
// The rolegroup `ConfigMap` mounted as-is (it also carries `vector.yaml`); read by the
563+
// Vector sidecar via [`VECTOR_LOG_CONFIG_VOLUME_NAME`].
564+
.add_volume(Volume {
565+
name: VECTOR_LOG_CONFIG_VOLUME_NAME.to_string(),
560566
config_map: Some(ConfigMapVolumeSource {
561567
name: resource_names.role_group_config_map().to_string(),
562-
..Default::default()
568+
..ConfigMapVolumeSource::default()
563569
}),
564-
..Default::default()
570+
..Volume::default()
565571
})
566572
.context(AddVolumeSnafu)?
567573
.add_volume(Volume {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
pub const NIFI_CONFIG_DIRECTORY: &str = "/stackable/nifi/conf";
55
pub const NIFI_PYTHON_WORKING_DIRECTORY: &str = "/nifi-python-working-directory";
6+
pub const NIFI_PYTHON_FRAMEWORK_DIRECTORY: &str = "/stackable/nifi/python/framework/";
7+
pub const NIFI_PYTHON_EXTENSIONS_DIRECTORY: &str = "/stackable/nifi/python/extensions/";
68
pub const NIFI_PVC_STORAGE_DIRECTORY: &str = "/stackable/data";
79

810
pub const JVM_SECURITY_PROPERTIES_FILE: &str = "security.properties";

0 commit comments

Comments
 (0)