mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 07:48:55 +00:00
runtime-rs: plug drop-in decoding into config-loading code
To plug drop-in support into existing config-loading code in a robust way, more specifically to create a single point where this needs to be handled, load_from_file() and load_raw_from_file() were refactored. Seeing as the original implemenations of both functions were identical apart from adjust_config() calls in load_from_file(), load_from_file() was reimplemented in terms of load_raw_from_file(). Fixes #4771 Signed-off-by: Pavel Mores <pmores@redhat.com>
This commit is contained in:
parent
87b97b6994
commit
57bd3f42d3
@ -3,6 +3,8 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
|
pub use drop_in_directory_handling::load;
|
||||||
|
|
||||||
mod toml_tree_ops {
|
mod toml_tree_ops {
|
||||||
// The following pair of functions implement toml::Value tree merging, with
|
// The following pair of functions implement toml::Value tree merging, with
|
||||||
// the second argument being merged into the first one and consumed in the
|
// the second argument being merged into the first one and consumed in the
|
||||||
|
@ -19,6 +19,7 @@ use crate::{eother, sl};
|
|||||||
pub mod default;
|
pub mod default;
|
||||||
|
|
||||||
mod agent;
|
mod agent;
|
||||||
|
mod drop_in;
|
||||||
pub mod hypervisor;
|
pub mod hypervisor;
|
||||||
|
|
||||||
pub use self::agent::Agent;
|
pub use self::agent::Agent;
|
||||||
@ -94,21 +95,15 @@ impl TomlConfig {
|
|||||||
/// If `config_file` is valid, it will used, otherwise a built-in default path list will be
|
/// If `config_file` is valid, it will used, otherwise a built-in default path list will be
|
||||||
/// scanned.
|
/// scanned.
|
||||||
pub fn load_from_file<P: AsRef<Path>>(config_file: P) -> Result<(TomlConfig, PathBuf)> {
|
pub fn load_from_file<P: AsRef<Path>>(config_file: P) -> Result<(TomlConfig, PathBuf)> {
|
||||||
let file_path = if !config_file.as_ref().as_os_str().is_empty() {
|
let mut result = Self::load_raw_from_file(config_file);
|
||||||
fs::canonicalize(config_file)?
|
if let Ok((ref mut config, _)) = result {
|
||||||
} else {
|
Hypervisor::adjust_config(config)?;
|
||||||
Self::get_default_config_file()?
|
Runtime::adjust_config(config)?;
|
||||||
};
|
Agent::adjust_config(config)?;
|
||||||
|
info!(sl!(), "get kata config: {:?}", config);
|
||||||
|
}
|
||||||
|
|
||||||
info!(
|
result
|
||||||
sl!(),
|
|
||||||
"load configuration from: {}",
|
|
||||||
file_path.to_string_lossy()
|
|
||||||
);
|
|
||||||
let content = fs::read_to_string(&file_path)?;
|
|
||||||
let config = Self::load(&content)?;
|
|
||||||
|
|
||||||
Ok((config, file_path))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load raw Kata configuration information from configuration files.
|
/// Load raw Kata configuration information from configuration files.
|
||||||
@ -127,13 +122,15 @@ impl TomlConfig {
|
|||||||
"load configuration from: {}",
|
"load configuration from: {}",
|
||||||
file_path.to_string_lossy()
|
file_path.to_string_lossy()
|
||||||
);
|
);
|
||||||
let content = fs::read_to_string(&file_path)?;
|
let config = drop_in::load(&file_path)?;
|
||||||
let config: TomlConfig = toml::from_str(&content)?;
|
|
||||||
|
|
||||||
Ok((config, file_path))
|
Ok((config, file_path))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load Kata configuration information from string.
|
/// Load Kata configuration information from string.
|
||||||
|
///
|
||||||
|
/// This function only works with `configuration.toml` and does not handle
|
||||||
|
/// drop-in config file fragments in config.d/.
|
||||||
pub fn load(content: &str) -> Result<TomlConfig> {
|
pub fn load(content: &str) -> Result<TomlConfig> {
|
||||||
let mut config: TomlConfig = toml::from_str(content)?;
|
let mut config: TomlConfig = toml::from_str(content)?;
|
||||||
Hypervisor::adjust_config(&mut config)?;
|
Hypervisor::adjust_config(&mut config)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user