Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions src/provider/states/pod/creating_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,16 @@ impl State<PodState> for CreatingConfig {
);
};

// Write the config files
let config_dir = pod_state.get_service_config_directory();
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could make this a little bit less hacky by actually using the template renderer instead of string substitution here.
The current implementation would miss {{ packageroot }} for example, which is still a valid Handlebars reference.

Something along these lines should have a similar effect:

 let joined_target_path = pod_state.get_service_package_directory().join(
                CreatingConfig::render_config_template(&template_data, &target_path).unwrap(),
            );

{{packageroot}}/tmp" should be rendered to for example "/opt/stackable/packages/kafka-2.6.0/tmp"

Since PathBuf::join() resolves absolute paths absolutely this would lead to
"/opt/stackable/servicedirectory".join("/opt/stackable/packages/kafka-2.6.0/tmp") -> "/opt/stackable/packages/kafka-2.6.0/tmp"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thank you, that looks much better :)

// 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_config_directory().join(
&CreatingConfig::render_config_template(&template_data, &target_path).unwrap(),
);
// end hack

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) {
Expand Down Expand Up @@ -406,8 +411,10 @@ impl State<PodState> 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() {
Expand Down Expand Up @@ -440,4 +447,26 @@ mod tests {
let legal_path_string = CreatingConfig::pathbuf_to_string("testfield", legal_path).unwrap();
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")]
#[case("test", "/etc/stackable/config/test")]
fn test_create_config_path(#[case] input: &str, #[case] expected_output: &str) {
let mut template_data: BTreeMap<String, String> = 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);
}
}