From 17c10c315ced8ca1a79c5a3f0fe0f6c6d78f5cf3 Mon Sep 17 00:00:00 2001 From: maltesander Date: Mon, 3 May 2021 19:04:53 +0200 Subject: [PATCH 1/6] Render {{packageroot}} from the volume mount path in order to overwrite config data in the package (for nifi operator testing) --- src/provider/states/pod/creating_config.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/provider/states/pod/creating_config.rs b/src/provider/states/pod/creating_config.rs index 1c3e6fe..fa8b269 100644 --- a/src/provider/states/pod/creating_config.rs +++ b/src/provider/states/pod/creating_config.rs @@ -364,11 +364,16 @@ impl State for CreatingConfig { ); }; - // Write the config files - let config_dir = pod_state.get_service_config_directory(); for (target_path, volume) in volume_mounts { + let joined_target_path = if target_path.starts_with("{{packageroot}}") { + pod_state + .get_service_package_directory() + .join(target_path.replace("{{packageroot}}/", "")) + } else { + pod_state.get_service_config_directory().join(&target_path) + }; + let volume = volume.clone(); - let joined_target_path = config_dir.join(&target_path); debug!("Applying config map {} to {}", volume, target_path); if let Some(volume_content) = config_map_data.get(&volume) { From 49d2263d8c3b3b75019279420a08aae4a10664fc Mon Sep 17 00:00:00 2001 From: maltesander Date: Fri, 14 May 2021 11:21:50 +0200 Subject: [PATCH 2/6] Added comments. --- src/provider/states/pod/creating_config.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/provider/states/pod/creating_config.rs b/src/provider/states/pod/creating_config.rs index fa8b269..46f24d1 100644 --- a/src/provider/states/pod/creating_config.rs +++ b/src/provider/states/pod/creating_config.rs @@ -365,6 +365,9 @@ impl State for CreatingConfig { }; for (target_path, volume) in volume_mounts { + // This is a hack for the NiFi operator. We need the volume mounts for NiFi to point to + // the package root, not the config root. Therefore we replace a path that starts with + // {{packageroot}} with the actual package root (default is config root). let joined_target_path = if target_path.starts_with("{{packageroot}}") { pod_state .get_service_package_directory() @@ -372,6 +375,7 @@ impl State for CreatingConfig { } else { pod_state.get_service_config_directory().join(&target_path) }; + // end hack let volume = volume.clone(); From 1dddfa634c2c60454bdec1119b7548b922b7a554 Mon Sep 17 00:00:00 2001 From: maltesander Date: Mon, 17 May 2021 18:41:18 +0200 Subject: [PATCH 3/6] Adapted to PR review. --- src/provider/states/pod/creating_config.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/provider/states/pod/creating_config.rs b/src/provider/states/pod/creating_config.rs index 46f24d1..18801ad 100644 --- a/src/provider/states/pod/creating_config.rs +++ b/src/provider/states/pod/creating_config.rs @@ -366,15 +366,11 @@ impl State for CreatingConfig { for (target_path, volume) in volume_mounts { // This is a hack for the NiFi operator. We need the volume mounts for NiFi to point to - // the package root, not the config root. Therefore we replace a path that starts with - // {{packageroot}} with the actual package root (default is config root). - let joined_target_path = if target_path.starts_with("{{packageroot}}") { - pod_state - .get_service_package_directory() - .join(target_path.replace("{{packageroot}}/", "")) - } else { - pod_state.get_service_config_directory().join(&target_path) - }; + // the package root, not the config root. + // TODO: remove if a better solution for NiFi is implemented. + let joined_target_path = pod_state.get_service_package_directory().join( + CreatingConfig::render_config_template(&template_data, &target_path).unwrap(), + ); // end hack let volume = volume.clone(); From 220922289d71fa194f4cca3bd3cb56fa6581f897 Mon Sep 17 00:00:00 2001 From: maltesander Date: Tue, 18 May 2021 14:50:12 +0200 Subject: [PATCH 4/6] Now works with NiFi and other operators. --- src/provider/states/pod/creating_config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/provider/states/pod/creating_config.rs b/src/provider/states/pod/creating_config.rs index 18801ad..36036fd 100644 --- a/src/provider/states/pod/creating_config.rs +++ b/src/provider/states/pod/creating_config.rs @@ -368,8 +368,8 @@ impl State for CreatingConfig { // This is a hack for the NiFi operator. We need the volume mounts for NiFi to point to // the package root, not the config root. // TODO: remove if a better solution for NiFi is implemented. - let joined_target_path = pod_state.get_service_package_directory().join( - CreatingConfig::render_config_template(&template_data, &target_path).unwrap(), + let joined_target_path = pod_state.get_service_config_directory().join( + &CreatingConfig::render_config_template(&template_data, &target_path).unwrap(), ); // end hack From 00dc2779da483f250b7bcb549aa859bffdd12777 Mon Sep 17 00:00:00 2001 From: maltesander Date: Thu, 20 May 2021 11:06:17 +0200 Subject: [PATCH 5/6] Added test for config/package hack. --- src/provider/states/pod/creating_config.rs | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/provider/states/pod/creating_config.rs b/src/provider/states/pod/creating_config.rs index 36036fd..275355f 100644 --- a/src/provider/states/pod/creating_config.rs +++ b/src/provider/states/pod/creating_config.rs @@ -411,8 +411,10 @@ impl State for CreatingConfig { #[cfg(test)] mod tests { use super::*; + use rstest::rstest; use std::collections::BTreeMap; use std::path::PathBuf; + use std::str::FromStr; #[test] fn test_render_template() { @@ -445,4 +447,25 @@ mod tests { let legal_path_string = CreatingConfig::pathbuf_to_string("testfield", legal_path).unwrap(); assert_eq!(input_path_string, legal_path_string); } + + #[rstest] + #[case("{{packageroot}}/test", "/opt/stackable/packages/test")] + #[case("/test", "/test")] + #[case("test", "/etc/stackable/config/test")] + fn test_create_config_path(#[case] input: &str, #[case] expected_output: &str) { + let mut template_data: BTreeMap = BTreeMap::new(); + + template_data.insert( + "packageroot".to_string(), + "/opt/stackable/packages".to_string(), + ); + + let config_dir = PathBuf::from_str("/etc/stackable/config").unwrap(); + + let output = config_dir + .join(&CreatingConfig::render_config_template(&template_data, input).unwrap()); + + let output = output.to_string_lossy(); + assert_eq!(output, expected_output); + } } From c1dad332ebf71972cdb7b95cfdafe801379b5ef8 Mon Sep 17 00:00:00 2001 From: maltesander Date: Thu, 20 May 2021 11:12:14 +0200 Subject: [PATCH 6/6] Added comment for test. --- src/provider/states/pod/creating_config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/provider/states/pod/creating_config.rs b/src/provider/states/pod/creating_config.rs index 275355f..85e4ea0 100644 --- a/src/provider/states/pod/creating_config.rs +++ b/src/provider/states/pod/creating_config.rs @@ -448,6 +448,7 @@ mod tests { assert_eq!(input_path_string, legal_path_string); } + // This only tests the render template function, not the actual code that generates the directory that is used #[rstest] #[case("{{packageroot}}/test", "/opt/stackable/packages/test")] #[case("/test", "/test")]