runtime-rs: add oci hook support

According to the runtime OCI Spec, there can be some hook
operations in the lifecycle of the container. In these hook
operations, the runtime can execute some commands. There are different
points in time in the container lifecycle  and different hook types
can be executed.

In this commit, we are now supporting 4 types of hooks(same in
runtime-go): Prestart hook, CreateRuntime hook, Poststart hook and
Poststop hook.

Fixes: #5787

Signed-off-by: Yushuo <y-shuo@linux.alibaba.com>
This commit is contained in:
Yushuo
2022-11-18 19:25:09 +08:00
parent ecac3a9e10
commit 875f2db528
22 changed files with 192 additions and 8 deletions

View File

@@ -166,6 +166,9 @@ message Hooks {
// Poststop is a list of hooks to be run after the container process exits.
repeated Hook Poststop = 3 [(gogoproto.nullable) = false];
// Createruntime is a list of hooks to be run during the creation of runtime(sandbox).
repeated Hook CreateRuntime = 4 [(gogoproto.nullable) = false];
}
message Hook {

View File

@@ -294,6 +294,7 @@ impl From<oci::Hooks> for crate::oci::Hooks {
fn from(from: Hooks) -> Self {
crate::oci::Hooks {
Prestart: from_vec(from.prestart),
CreateRuntime: from_vec(from.create_runtime),
Poststart: from_vec(from.poststart),
Poststop: from_vec(from.poststop),
unknown_fields: Default::default(),
@@ -974,6 +975,10 @@ impl From<crate::oci::Hooks> for oci::Hooks {
for hook in from.take_Prestart().to_vec() {
prestart.push(hook.into())
}
let mut create_runtime = Vec::new();
for hook in from.take_CreateRuntime().to_vec() {
create_runtime.push(hook.into())
}
let mut poststart = Vec::new();
for hook in from.take_Poststart().to_vec() {
poststart.push(hook.into());
@@ -984,6 +989,7 @@ impl From<crate::oci::Hooks> for oci::Hooks {
}
oci::Hooks {
prestart,
create_runtime,
poststart,
poststop,
}