mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-01 13:14:33 +00:00
fix: oci hook
1. when do the deserialization for the oci hook, we should use camel case for createRuntime 2. we should pass the dir of bundle path instead of the path of config.json Fixes:#4693 Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
This commit is contained in:
parent
ee5dda012b
commit
3bfaafbf44
@ -192,11 +192,23 @@ pub struct Hook {
|
|||||||
pub struct Hooks {
|
pub struct Hooks {
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
pub prestart: Vec<Hook>,
|
pub prestart: Vec<Hook>,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(
|
||||||
|
rename = "createRuntime",
|
||||||
|
default,
|
||||||
|
skip_serializing_if = "Vec::is_empty"
|
||||||
|
)]
|
||||||
pub create_runtime: Vec<Hook>,
|
pub create_runtime: Vec<Hook>,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(
|
||||||
|
rename = "createContainer",
|
||||||
|
default,
|
||||||
|
skip_serializing_if = "Vec::is_empty"
|
||||||
|
)]
|
||||||
pub create_container: Vec<Hook>,
|
pub create_container: Vec<Hook>,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(
|
||||||
|
rename = "startContainer",
|
||||||
|
default,
|
||||||
|
skip_serializing_if = "Vec::is_empty"
|
||||||
|
)]
|
||||||
pub start_container: Vec<Hook>,
|
pub start_container: Vec<Hook>,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
pub poststart: Vec<Hook>,
|
pub poststart: Vec<Hook>,
|
||||||
@ -837,6 +849,8 @@ pub struct State {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::vec;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1027,6 +1041,11 @@ mod tests {
|
|||||||
"path": "/usr/bin/setup-network"
|
"path": "/usr/bin/setup-network"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"createRuntime": [
|
||||||
|
{
|
||||||
|
"path": "/usr/local/bin/nerdctl"
|
||||||
|
}
|
||||||
|
],
|
||||||
"poststart": [
|
"poststart": [
|
||||||
{
|
{
|
||||||
"path": "/usr/bin/notify-start",
|
"path": "/usr/bin/notify-start",
|
||||||
@ -1395,6 +1414,12 @@ mod tests {
|
|||||||
timeout: None,
|
timeout: None,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
create_runtime: vec![crate::Hook {
|
||||||
|
path: "/usr/local/bin/nerdctl".to_string(),
|
||||||
|
args: vec![],
|
||||||
|
env: vec![],
|
||||||
|
timeout: None,
|
||||||
|
}],
|
||||||
poststart: vec![crate::Hook {
|
poststart: vec![crate::Hook {
|
||||||
path: "/usr/bin/notify-start".to_string(),
|
path: "/usr/bin/notify-start".to_string(),
|
||||||
args: vec![],
|
args: vec![],
|
||||||
|
@ -236,7 +236,7 @@ impl RuntimeHandlerManager {
|
|||||||
id: container_config.container_id.to_string(),
|
id: container_config.container_id.to_string(),
|
||||||
status: oci::ContainerState::Creating,
|
status: oci::ContainerState::Creating,
|
||||||
pid: 0,
|
pid: 0,
|
||||||
bundle: bundler_path,
|
bundle: container_config.bundle.clone(),
|
||||||
annotations: spec.annotations.clone(),
|
annotations: spec.annotations.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -188,9 +188,9 @@ impl Sandbox for VirtSandbox {
|
|||||||
info!(sl!(), "start vm");
|
info!(sl!(), "start vm");
|
||||||
|
|
||||||
// execute pre-start hook functions, including Prestart Hooks and CreateRuntime Hooks
|
// execute pre-start hook functions, including Prestart Hooks and CreateRuntime Hooks
|
||||||
let (prestart_hooks, create_runtime_hooks) = match spec.hooks.as_ref() {
|
let (prestart_hooks, create_runtime_hooks, _has_oci_hook) = match spec.hooks.as_ref() {
|
||||||
Some(hooks) => (hooks.prestart.clone(), hooks.create_runtime.clone()),
|
Some(hooks) => (hooks.prestart.clone(), hooks.create_runtime.clone(), true),
|
||||||
None => (Vec::new(), Vec::new()),
|
None => (Vec::new(), Vec::new(), false),
|
||||||
};
|
};
|
||||||
self.execute_oci_hook_functions(&prestart_hooks, &create_runtime_hooks, state)
|
self.execute_oci_hook_functions(&prestart_hooks, &create_runtime_hooks, state)
|
||||||
.await?;
|
.await?;
|
||||||
|
Loading…
Reference in New Issue
Block a user