Skip to content

Commit

Permalink
runtime-rs: report error on missing or empty fields in configuration
Browse files Browse the repository at this point in the history
Removed the setting of default values for runtime fields. Added explicit checks for missing or empty fields, reporting errors with clear messages.

Fixes: #8838

Signed-off-by: yaoyinnan <35447132+yaoyinnan@users.noreply.github.com>
  • Loading branch information
yaoyinnan committed Jan 26, 2024
1 parent e11c520 commit 49e6953
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/libs/kata-types/src/annotations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ use std::u32;

use serde::Deserialize;

use crate::config::default::DEFAULT_AGENT_TYPE_NAME;
use crate::config::default::DEFAULT_HYPERVISOR;
use crate::config::default::DEFAULT_RUNTIME_NAME;
use crate::config::hypervisor::{get_hypervisor_plugin, HugePageType};

use crate::config::TomlConfig;
Expand Down Expand Up @@ -463,13 +460,22 @@ impl Annotation {

// set default values for runtime.name, runtime.hypervisor_name and runtime.agent
if config.runtime.name.is_empty() {
config.runtime.name = DEFAULT_RUNTIME_NAME.to_string()
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"Runtime name is missing in the configuration",
));
}
if config.runtime.hypervisor_name.is_empty() {
config.runtime.hypervisor_name = DEFAULT_HYPERVISOR.to_string()
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"Hypervisor name is missing in the configuration",
));
}
if config.runtime.agent_name.is_empty() {
config.runtime.agent_name = DEFAULT_AGENT_TYPE_NAME.to_string()
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"Agent name is missing in the configuration",
));
}

let hypervisor_name = &config.runtime.hypervisor_name;
Expand Down

0 comments on commit 49e6953

Please sign in to comment.