From 00bfa3fa0220ff4d665bc1df9da72090b6ab4e94 Mon Sep 17 00:00:00 2001 From: Pavel Mores Date: Mon, 2 Dec 2024 12:00:34 +0100 Subject: [PATCH] runtime-rs: re-adjust config after modifying it with annotations Configuration information is adjusted after loading from file but so far, there has been no similar check for configuration coming from annotations. This commit introduces re-adjusting config after annotations have been processed. A small refactor was necessary as a prerequisite which introduces function TomlConfig::adjust_config() to make it easier to invoke the adjustment for a whole TomlConfig instance. This function is analogous to the existing validate() function. The immediate motivation for this change is to make sure that 0 in "default_vcpus" annotation will be properly adjusted to 1 as is the case if 0 is loaded from a config file. This is required to match the golang runtime behaviour. Signed-off-by: Pavel Mores --- src/libs/kata-types/src/annotations/mod.rs | 3 +++ src/libs/kata-types/src/config/mod.rs | 17 +++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libs/kata-types/src/annotations/mod.rs b/src/libs/kata-types/src/annotations/mod.rs index 1a6d3713a7..b794b6d8b3 100644 --- a/src/libs/kata-types/src/annotations/mod.rs +++ b/src/libs/kata-types/src/annotations/mod.rs @@ -1079,6 +1079,9 @@ impl Annotation { } } } + + config.adjust_config()?; + Ok(()) } } diff --git a/src/libs/kata-types/src/config/mod.rs b/src/libs/kata-types/src/config/mod.rs index d893c212aa..b5eb8010e6 100644 --- a/src/libs/kata-types/src/config/mod.rs +++ b/src/libs/kata-types/src/config/mod.rs @@ -131,9 +131,7 @@ impl TomlConfig { pub fn load_from_file>(config_file: P) -> Result<(TomlConfig, PathBuf)> { let mut result = Self::load_raw_from_file(config_file); if let Ok((ref mut config, _)) = result { - Hypervisor::adjust_config(config)?; - Runtime::adjust_config(config)?; - Agent::adjust_config(config)?; + config.adjust_config()?; info!(sl!(), "get kata config: {:?}", config); } @@ -175,13 +173,20 @@ impl TomlConfig { /// drop-in config file fragments in config.d/. pub fn load(content: &str) -> Result { let mut config: TomlConfig = toml::from_str(content)?; - Hypervisor::adjust_config(&mut config)?; - Runtime::adjust_config(&mut config)?; - Agent::adjust_config(&mut config)?; + config.adjust_config()?; info!(sl!(), "get kata config: {:?}", config); Ok(config) } + /// Adjust Kata configuration information. + pub fn adjust_config(&mut self) -> Result<()> { + Hypervisor::adjust_config(self)?; + Runtime::adjust_config(self)?; + Agent::adjust_config(self)?; + + Ok(()) + } + /// Validate Kata configuration information. pub fn validate(&self) -> Result<()> { Hypervisor::validate(self)?;