Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit eb68eb0

Browse files
authored
Volume mount package root hack for nifi (#159)
* Render {{packageroot}} from the volume mount path in order to overwrite config data in the package (for nifi operator testing) * Added comments. * Adapted to PR review. * Now works with NiFi and other operators. * Added test for config/package hack. * Added comment for test.
1 parent 1af94ce commit eb68eb0

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/provider/states/pod/creating_config.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,16 @@ impl State<PodState> for CreatingConfig {
364364
);
365365
};
366366

367-
// Write the config files
368-
let config_dir = pod_state.get_service_config_directory();
369367
for (target_path, volume) in volume_mounts {
368+
// This is a hack for the NiFi operator. We need the volume mounts for NiFi to point to
369+
// the package root, not the config root.
370+
// TODO: remove if a better solution for NiFi is implemented.
371+
let joined_target_path = pod_state.get_service_config_directory().join(
372+
&CreatingConfig::render_config_template(&template_data, &target_path).unwrap(),
373+
);
374+
// end hack
375+
370376
let volume = volume.clone();
371-
let joined_target_path = config_dir.join(&target_path);
372377

373378
debug!("Applying config map {} to {}", volume, target_path);
374379
if let Some(volume_content) = config_map_data.get(&volume) {
@@ -406,8 +411,10 @@ impl State<PodState> for CreatingConfig {
406411
#[cfg(test)]
407412
mod tests {
408413
use super::*;
414+
use rstest::rstest;
409415
use std::collections::BTreeMap;
410416
use std::path::PathBuf;
417+
use std::str::FromStr;
411418

412419
#[test]
413420
fn test_render_template() {
@@ -440,4 +447,26 @@ mod tests {
440447
let legal_path_string = CreatingConfig::pathbuf_to_string("testfield", legal_path).unwrap();
441448
assert_eq!(input_path_string, legal_path_string);
442449
}
450+
451+
// This only tests the render template function, not the actual code that generates the directory that is used
452+
#[rstest]
453+
#[case("{{packageroot}}/test", "/opt/stackable/packages/test")]
454+
#[case("/test", "/test")]
455+
#[case("test", "/etc/stackable/config/test")]
456+
fn test_create_config_path(#[case] input: &str, #[case] expected_output: &str) {
457+
let mut template_data: BTreeMap<String, String> = BTreeMap::new();
458+
459+
template_data.insert(
460+
"packageroot".to_string(),
461+
"/opt/stackable/packages".to_string(),
462+
);
463+
464+
let config_dir = PathBuf::from_str("/etc/stackable/config").unwrap();
465+
466+
let output = config_dir
467+
.join(&CreatingConfig::render_config_template(&template_data, input).unwrap());
468+
469+
let output = output.to_string_lossy();
470+
assert_eq!(output, expected_output);
471+
}
443472
}

0 commit comments

Comments
 (0)