runtime-rs: service and runtime framework

1. service: Responsible for processing services, such as task service, image service
2. Responsible for implementing different runtimes, such as Virt-container,
Linux-container, Wasm-container

Fixes: #3785
Signed-off-by: Quanwei Zhou <quanweiZhou@linux.alibaba.com>
This commit is contained in:
Quanwei Zhou
2021-12-03 18:53:48 +08:00
committed by Fupan Li
parent 4296e3069f
commit bdfee005fa
37 changed files with 1713 additions and 83 deletions

View File

@@ -19,7 +19,7 @@ containerd-shim-protos = { version = "0.2.0", features = ["async"]}
go-flag = "0.1.0"
libc = "0.2.108"
log = "0.4.14"
nix = "0.16.0"
nix = "0.23.1"
protobuf = "2.23.0"
sha2 = "=0.9.3"
slog = {version = "2.7.0", features = ["std", "release_max_level_trace", "max_level_trace"]}
@@ -34,11 +34,13 @@ kata-types = { path = "../../../libs/kata-types"}
kata-sys-util = { path = "../../../libs/kata-sys-util"}
logging = { path = "../../../libs/logging"}
oci = { path = "../../../libs/oci" }
service = { path = "../service" }
[build-dependencies]
vergen = { version = "6", default-features = false, features = ["build", "git", "rustc"] }
[dev-dependencies]
tempfile = "3.2.0"
rand = "0.8.4"
serial_test = "0.5.1"
tests_utils = { path = "../../tests/utils"}

View File

@@ -51,8 +51,8 @@ impl Args {
))));
}
validate::verify_cid(&self.id).context("verify cid")?;
validate::verify_cid(&self.namespace).context("verify namespace")?;
validate::verify_id(&self.id).context("verify container id")?;
validate::verify_id(&self.namespace).context("verify namespace")?;
// Ensure `address` is a valid path.
let path = PathBuf::from(self.address.clone())

View File

@@ -7,11 +7,7 @@
#[macro_use]
extern crate slog;
macro_rules! sl {
() => {
slog_scope::logger().new(slog::o!("subsystem" => "shim"))
};
}
logging::logger_with_subsystem!(sl, "shim");
mod args;
pub use args::Args;

View File

@@ -31,7 +31,7 @@ impl ShimExecutor {
}
pub(crate) fn load_oci_spec(&self, path: &Path) -> Result<oci::Spec> {
let spec_file = path.join("config.json");
let spec_file = path.join(oci::OCI_SPEC_CONFIG_FILE_NAME);
oci::Spec::load(spec_file.to_str().unwrap_or_default()).context("load spec")
}

View File

@@ -5,7 +5,7 @@
//
use anyhow::{Context, Result};
use containerd_shim_protos::shim::shim::DeleteResponse;
use containerd_shim_protos::api;
use protobuf::Message;
use crate::{shim::ShimExecutor, Error};
@@ -19,8 +19,8 @@ impl ShimExecutor {
Ok(())
}
fn do_cleanup(&self) -> Result<DeleteResponse> {
let mut rsp = DeleteResponse::new();
fn do_cleanup(&self) -> Result<api::DeleteResponse> {
let mut rsp = api::DeleteResponse::new();
rsp.set_exit_status(128 + libc::SIGKILL as u32);
let mut exited_time = protobuf::well_known_types::Timestamp::new();
let seconds = std::time::SystemTime::now()
@@ -30,42 +30,7 @@ impl ShimExecutor {
exited_time.set_seconds(seconds);
rsp.set_exited_at(exited_time);
// TODO: implement cleanup
service::ServiceManager::cleanup(&self.args.id).context("cleanup")?;
Ok(rsp)
}
}
#[cfg(test)]
mod tests {
use serial_test::serial;
use tests_utils::gen_id;
use super::*;
use crate::Args;
#[test]
#[serial]
fn test_shim_delete() {
let dir = tempfile::tempdir().unwrap();
let bundle_path = dir.path();
std::env::set_current_dir(bundle_path).unwrap();
let id = gen_id(16);
let namespace = gen_id(16);
let args = Args {
id,
namespace,
address: "containerd_socket".into(),
publish_binary: "containerd".into(),
socket: "socket".into(),
bundle: bundle_path.to_str().unwrap().into(),
debug: false,
};
let executor = ShimExecutor::new(args);
let resp = executor.do_cleanup().unwrap();
assert_eq!(resp.exit_status, 128 + libc::SIGKILL as u32);
assert!(resp.exited_at.as_ref().unwrap().seconds > 0);
}
}

View File

@@ -38,8 +38,11 @@ impl ShimExecutor {
info!(sl!(), "start to run");
self.args.validate(false).context("validata")?;
let _server_fd = get_server_fd().context("get server fd")?;
// TODO: implement run
let server_fd = get_server_fd().context("get server fd")?;
let mut service_manager = service::ServiceManager::new(&self.args.id, server_fd)
.await
.context("new runtime server")?;
service_manager.run().await.context("run")?;
Ok(())
}