mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
runtime-rs: make function name more understandable
Change kparams to kernel_params for understandability. Fixes: #5068 Signed-Off-By: Ji-Xinyou <jerryji0414@outlook.com>
This commit is contained in:
parent
426a436780
commit
e23bfd615e
@ -241,14 +241,12 @@ impl BootInfo {
|
|||||||
|
|
||||||
/// Add kernel parameters to bootinfo. It is always added before the original
|
/// Add kernel parameters to bootinfo. It is always added before the original
|
||||||
/// to let the original one takes priority
|
/// to let the original one takes priority
|
||||||
pub fn add_kparams(&mut self, params: Vec<String>) {
|
pub fn add_kernel_params(&mut self, params: Vec<String>) {
|
||||||
let mut p = params;
|
let mut p = params;
|
||||||
if self.kernel_params.is_empty() {
|
if !self.kernel_params.is_empty() {
|
||||||
self.kernel_params = p.join(KERNEL_PARAM_DELIMITER);
|
|
||||||
} else {
|
|
||||||
p.push(self.kernel_params.clone()); // [new_params0, new_params1, ..., original_params]
|
p.push(self.kernel_params.clone()); // [new_params0, new_params1, ..., original_params]
|
||||||
self.kernel_params = p.join(KERNEL_PARAM_DELIMITER);
|
|
||||||
}
|
}
|
||||||
|
self.kernel_params = p.join(KERNEL_PARAM_DELIMITER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Validate guest kernel image annotaion
|
/// Validate guest kernel image annotaion
|
||||||
@ -1083,7 +1081,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_add_kparams() {
|
fn test_add_kernel_params() {
|
||||||
let mut boot_info = BootInfo {
|
let mut boot_info = BootInfo {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@ -1092,7 +1090,7 @@ mod tests {
|
|||||||
String::from("bar"),
|
String::from("bar"),
|
||||||
String::from("baz=faz"),
|
String::from("baz=faz"),
|
||||||
];
|
];
|
||||||
boot_info.add_kparams(params);
|
boot_info.add_kernel_params(params);
|
||||||
|
|
||||||
assert_eq!(boot_info.kernel_params, String::from("foo bar baz=faz"));
|
assert_eq!(boot_info.kernel_params, String::from("foo bar baz=faz"));
|
||||||
|
|
||||||
@ -1101,7 +1099,7 @@ mod tests {
|
|||||||
String::from("a"),
|
String::from("a"),
|
||||||
String::from("b=c"),
|
String::from("b=c"),
|
||||||
];
|
];
|
||||||
boot_info.add_kparams(new_params);
|
boot_info.add_kernel_params(new_params);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
boot_info.kernel_params,
|
boot_info.kernel_params,
|
||||||
|
@ -171,7 +171,7 @@ impl TomlConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get agent-specfic kernel parameters for further Hypervisor config revision
|
/// Get agent-specfic kernel parameters for further Hypervisor config revision
|
||||||
pub fn get_agent_kparams(&self) -> Result<HashMap<String, String>> {
|
pub fn get_agent_kernel_params(&self) -> Result<HashMap<String, String>> {
|
||||||
let mut kv = HashMap::new();
|
let mut kv = HashMap::new();
|
||||||
if let Some(cfg) = self.agent.get(&self.runtime.agent_name) {
|
if let Some(cfg) = self.agent.get(&self.runtime.agent_name) {
|
||||||
if cfg.debug {
|
if cfg.debug {
|
||||||
@ -349,7 +349,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_agent_kparams() {
|
fn test_get_agent_kernel_params() {
|
||||||
let mut config = TomlConfig {
|
let mut config = TomlConfig {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@ -364,7 +364,7 @@ mod tests {
|
|||||||
config.runtime.agent_name = agent_name.to_string();
|
config.runtime.agent_name = agent_name.to_string();
|
||||||
config.agent.insert(agent_name.to_owned(), agent_config);
|
config.agent.insert(agent_name.to_owned(), agent_config);
|
||||||
|
|
||||||
let kv = config.get_agent_kparams().unwrap();
|
let kv = config.get_agent_kernel_params().unwrap();
|
||||||
assert_eq!(kv.get("agent.log").unwrap(), "debug");
|
assert_eq!(kv.get("agent.log").unwrap(), "debug");
|
||||||
assert_eq!(kv.get("agent.trace").unwrap(), "true");
|
assert_eq!(kv.get("agent.trace").unwrap(), "true");
|
||||||
assert_eq!(kv.get("agent.container_pipe_size").unwrap(), "20");
|
assert_eq!(kv.get("agent.container_pipe_size").unwrap(), "20");
|
||||||
|
@ -324,7 +324,7 @@ fn load_config(spec: &oci::Spec) -> Result<TomlConfig> {
|
|||||||
let (mut toml_config, _) =
|
let (mut toml_config, _) =
|
||||||
TomlConfig::load_from_file(&config_path).context("load toml config")?;
|
TomlConfig::load_from_file(&config_path).context("load toml config")?;
|
||||||
annotation.update_config_by_annotation(&mut toml_config)?;
|
annotation.update_config_by_annotation(&mut toml_config)?;
|
||||||
update_agent_kparams(&mut toml_config)?;
|
update_agent_kernel_params(&mut toml_config)?;
|
||||||
|
|
||||||
// validate configuration and return the error
|
// validate configuration and return the error
|
||||||
toml_config.validate()?;
|
toml_config.validate()?;
|
||||||
@ -351,16 +351,16 @@ fn load_config(spec: &oci::Spec) -> Result<TomlConfig> {
|
|||||||
|
|
||||||
// this update the agent-specfic kernel parameters into hypervisor's bootinfo
|
// this update the agent-specfic kernel parameters into hypervisor's bootinfo
|
||||||
// the agent inside the VM will read from file cmdline to get the params and function
|
// the agent inside the VM will read from file cmdline to get the params and function
|
||||||
fn update_agent_kparams(config: &mut TomlConfig) -> Result<()> {
|
fn update_agent_kernel_params(config: &mut TomlConfig) -> Result<()> {
|
||||||
let mut params = vec![];
|
let mut params = vec![];
|
||||||
if let Ok(kv) = config.get_agent_kparams() {
|
if let Ok(kv) = config.get_agent_kernel_params() {
|
||||||
for (k, v) in kv.into_iter() {
|
for (k, v) in kv.into_iter() {
|
||||||
if let Ok(s) = Param::new(k.as_str(), v.as_str()).to_string() {
|
if let Ok(s) = Param::new(k.as_str(), v.as_str()).to_string() {
|
||||||
params.push(s);
|
params.push(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(h) = config.hypervisor.get_mut(&config.runtime.hypervisor_name) {
|
if let Some(h) = config.hypervisor.get_mut(&config.runtime.hypervisor_name) {
|
||||||
h.boot_info.add_kparams(params);
|
h.boot_info.add_kernel_params(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user