From 1c5b80aa9cee44d95d5b2bcaee656a3068b854a0 Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Sat, 2 Sep 2023 01:33:03 +0100 Subject: [PATCH] make it os agnostic Signed-off-by: Jorge Prendes --- crates/containerd-shim-wasm/src/lib.rs | 1 - .../src/sys/common/container/instance.rs | 26 ++++++++++ .../sys/{windows => common}/container/mod.rs | 0 .../containerd-shim-wasm/src/sys/unix/mod.rs | 2 + .../src/sys/windows/container/instance.rs | 51 ------------------- .../src/sys/windows/mod.rs | 1 + .../instance_linux.rs => instance.rs} | 0 .../src/instance/instance_windows.rs | 40 --------------- crates/containerd-shim-wasmedge/src/lib.rs | 2 - .../instance_linux.rs => instance.rs} | 0 .../src/instance/instance_windows.rs | 38 -------------- crates/containerd-shim-wasmtime/src/lib.rs | 2 - 12 files changed, 29 insertions(+), 134 deletions(-) create mode 100644 crates/containerd-shim-wasm/src/sys/common/container/instance.rs rename crates/containerd-shim-wasm/src/sys/{windows => common}/container/mod.rs (100%) delete mode 100644 crates/containerd-shim-wasm/src/sys/windows/container/instance.rs rename crates/containerd-shim-wasmedge/src/{instance/instance_linux.rs => instance.rs} (100%) delete mode 100644 crates/containerd-shim-wasmedge/src/instance/instance_windows.rs rename crates/containerd-shim-wasmtime/src/{instance/instance_linux.rs => instance.rs} (100%) delete mode 100644 crates/containerd-shim-wasmtime/src/instance/instance_windows.rs diff --git a/crates/containerd-shim-wasm/src/lib.rs b/crates/containerd-shim-wasm/src/lib.rs index 654d5778b..02398752e 100644 --- a/crates/containerd-shim-wasm/src/lib.rs +++ b/crates/containerd-shim-wasm/src/lib.rs @@ -9,5 +9,4 @@ pub mod services; #[cfg_attr(windows, path = "sys/windows/mod.rs")] pub(crate) mod sys; -#[cfg(all(feature = "libcontainer", not(target_os = "windows")))] pub mod container; diff --git a/crates/containerd-shim-wasm/src/sys/common/container/instance.rs b/crates/containerd-shim-wasm/src/sys/common/container/instance.rs new file mode 100644 index 000000000..0e5b6530b --- /dev/null +++ b/crates/containerd-shim-wasm/src/sys/common/container/instance.rs @@ -0,0 +1,26 @@ +use crate::container::engine::Engine; +use crate::sandbox::instance::Wait; +use crate::sandbox::{Error as SandboxError, Instance as SandboxInstance, InstanceConfig}; + +pub struct Instance { + engine: std::marker::PhantomData, +} + +impl SandboxInstance for Instance { + type Engine = E; + fn new(_id: String, _cfg: Option<&InstanceConfig>) -> Self { + todo!(); + } + fn start(&self) -> Result { + todo!(); + } + fn kill(&self, _signal: u32) -> Result<(), SandboxError> { + todo!(); + } + fn delete(&self) -> Result<(), SandboxError> { + todo!(); + } + fn wait(&self, _waiter: &Wait) -> Result<(), SandboxError> { + todo!(); + } +} diff --git a/crates/containerd-shim-wasm/src/sys/windows/container/mod.rs b/crates/containerd-shim-wasm/src/sys/common/container/mod.rs similarity index 100% rename from crates/containerd-shim-wasm/src/sys/windows/container/mod.rs rename to crates/containerd-shim-wasm/src/sys/common/container/mod.rs diff --git a/crates/containerd-shim-wasm/src/sys/unix/mod.rs b/crates/containerd-shim-wasm/src/sys/unix/mod.rs index b95b67c3c..21c252ef3 100644 --- a/crates/containerd-shim-wasm/src/sys/unix/mod.rs +++ b/crates/containerd-shim-wasm/src/sys/unix/mod.rs @@ -1,3 +1,5 @@ +#[cfg_attr(feature = "libcontainer", path = "./container/mod.rs")] +#[cfg_attr(not(feature = "libcontainer"), path = "../common/container/mod.rs")] pub mod container; pub mod metrics; pub mod networking; diff --git a/crates/containerd-shim-wasm/src/sys/windows/container/instance.rs b/crates/containerd-shim-wasm/src/sys/windows/container/instance.rs deleted file mode 100644 index f25134a0f..000000000 --- a/crates/containerd-shim-wasm/src/sys/windows/container/instance.rs +++ /dev/null @@ -1,51 +0,0 @@ -use crate::container::engine::Engine; -use crate::sandbox::instance::{ExitCode, Wait}; -use crate::sandbox::instance_utils::{determine_rootdir, get_instance_root, instance_exists}; -use crate::sandbox::{Error as SandboxError, Instance as SandboxInstance, InstanceConfig, Stdio}; - -static DEFAULT_CONTAINER_ROOT_DIR: &str = "/run/containerd"; - -pub struct Instance { - engine: E, - exit_code: ExitCode, - stdio: Stdio, - bundle: PathBuf, - rootdir: PathBuf, - id: String, -} - -impl SandboxInstance for Instance { - type Engine = E; - - fn new(id: String, cfg: Option<&InstanceConfig>) -> Self { - todo!(); - } - - /// Start the instance - /// The returned value should be a unique ID (such as a PID) for the instance. - /// Nothing internally should be using this ID, but it is returned to containerd where a user may want to use it. - fn start(&self) -> Result { - todo!(); - } - - /// Send a signal to the instance - fn kill(&self, signal: u32) -> Result<(), SandboxError> { - todo!(); - } - - /// Delete any reference to the instance - /// This is called after the instance has exited. - fn delete(&self) -> Result<(), SandboxError> { - todo!(); - } - - /// Set up waiting for the instance to exit - /// The Wait struct is used to send the exit code and time back to the - /// caller. The recipient is expected to call function - /// set_up_exit_code_wait() implemented by Wait to set up exit code - /// processing. Note that the "wait" function doesn't block, but - /// it sets up the waiting channel. - fn wait(&self, waiter: &Wait) -> Result<(), SandboxError> { - todo!(); - } -} diff --git a/crates/containerd-shim-wasm/src/sys/windows/mod.rs b/crates/containerd-shim-wasm/src/sys/windows/mod.rs index b95b67c3c..fbde25445 100644 --- a/crates/containerd-shim-wasm/src/sys/windows/mod.rs +++ b/crates/containerd-shim-wasm/src/sys/windows/mod.rs @@ -1,3 +1,4 @@ +#[path = "../common/container/mod.rs"] pub mod container; pub mod metrics; pub mod networking; diff --git a/crates/containerd-shim-wasmedge/src/instance/instance_linux.rs b/crates/containerd-shim-wasmedge/src/instance.rs similarity index 100% rename from crates/containerd-shim-wasmedge/src/instance/instance_linux.rs rename to crates/containerd-shim-wasmedge/src/instance.rs diff --git a/crates/containerd-shim-wasmedge/src/instance/instance_windows.rs b/crates/containerd-shim-wasmedge/src/instance/instance_windows.rs deleted file mode 100644 index f58d9dae8..000000000 --- a/crates/containerd-shim-wasmedge/src/instance/instance_windows.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::path::PathBuf; - -use containerd_shim_wasm::sandbox::error::Error; -use containerd_shim_wasm::sandbox::instance::{ExitCode, Wait}; -use containerd_shim_wasm::sandbox::{Instance, InstanceConfig, Stdio}; - -pub struct WasmEdgeInstance { - id: String, - - exit_code: ExitCode, - - stdio: Stdio, - bundle: String, - - rootdir: PathBuf, -} - -impl Instance for WasmEdgeInstance { - type Engine = (); - - fn new(id: String, cfg: Option<&InstanceConfig>) -> Self { - todo!() - } - - fn start(&self) -> std::result::Result { - todo!() - } - - fn kill(&self, signal: u32) -> std::result::Result<(), Error> { - todo!() - } - - fn delete(&self) -> std::result::Result<(), Error> { - todo!() - } - - fn wait(&self, waiter: &Wait) -> std::result::Result<(), Error> { - todo!() - } -} diff --git a/crates/containerd-shim-wasmedge/src/lib.rs b/crates/containerd-shim-wasmedge/src/lib.rs index 1e03f1030..a1f1f33be 100644 --- a/crates/containerd-shim-wasmedge/src/lib.rs +++ b/crates/containerd-shim-wasmedge/src/lib.rs @@ -2,8 +2,6 @@ use std::env; use containerd_shim::parse; -#[cfg_attr(unix, path = "instance/instance_linux.rs")] -#[cfg_attr(windows, path = "instance/instance_windows.rs")] pub mod instance; pub use instance::WasmEdgeInstance; diff --git a/crates/containerd-shim-wasmtime/src/instance/instance_linux.rs b/crates/containerd-shim-wasmtime/src/instance.rs similarity index 100% rename from crates/containerd-shim-wasmtime/src/instance/instance_linux.rs rename to crates/containerd-shim-wasmtime/src/instance.rs diff --git a/crates/containerd-shim-wasmtime/src/instance/instance_windows.rs b/crates/containerd-shim-wasmtime/src/instance/instance_windows.rs deleted file mode 100644 index 0e5cb3673..000000000 --- a/crates/containerd-shim-wasmtime/src/instance/instance_windows.rs +++ /dev/null @@ -1,38 +0,0 @@ -use std::path::PathBuf; - -use containerd_shim_wasm::sandbox::error::Error; -use containerd_shim_wasm::sandbox::instance::{ExitCode, Wait}; -use containerd_shim_wasm::sandbox::{Instance, InstanceConfig, Stdio}; - -pub struct WasmtimeInstance { - id: String, - exit_code: ExitCode, - engine: wasmtime::Engine, - stdio: Stdio, - bundle: String, - rootdir: PathBuf, -} - -impl Instance for WasmtimeInstance { - type Engine = wasmtime::Engine; - - fn new(id: String, cfg: Option<&InstanceConfig>) -> Self { - todo!() - } - - fn start(&self) -> std::result::Result { - todo!() - } - - fn kill(&self, signal: u32) -> std::result::Result<(), Error> { - todo!() - } - - fn delete(&self) -> std::result::Result<(), Error> { - todo!() - } - - fn wait(&self, waiter: &Wait) -> std::result::Result<(), Error> { - todo!() - } -} diff --git a/crates/containerd-shim-wasmtime/src/lib.rs b/crates/containerd-shim-wasmtime/src/lib.rs index 852c68806..c63c3abc0 100644 --- a/crates/containerd-shim-wasmtime/src/lib.rs +++ b/crates/containerd-shim-wasmtime/src/lib.rs @@ -2,8 +2,6 @@ use std::env; use containerd_shim::parse; -#[cfg_attr(unix, path = "instance/instance_linux.rs")] -#[cfg_attr(windows, path = "instance/instance_windows.rs")] pub mod instance; pub use instance::WasmtimeInstance;