mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-15 22:53:43 +00:00
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 <pmores@redhat.com>
This commit is contained in:
parent
e2156721fd
commit
00bfa3fa02
@ -1079,6 +1079,9 @@ impl Annotation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config.adjust_config()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -131,9 +131,7 @@ impl TomlConfig {
|
||||
pub fn load_from_file<P: AsRef<Path>>(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<TomlConfig> {
|
||||
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)?;
|
||||
|
Loading…
Reference in New Issue
Block a user