Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Remove unused engine field #887

Merged
merged 2 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ The most flexible but complex is the `sandbox::Instance` trait:

```rust
pub trait Instance {
/// The WASI engine type
type Engine: Send + Sync + Clone;

/// Create a new instance
fn new(id: String, cfg: &InstanceConfig) -> Self;
/// Start the instance
Expand Down
2 changes: 0 additions & 2 deletions crates/containerd-shim-wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ struct MyInstance {
}
impl Instance for MyInstance {
type Engine = MyEngine;
fn new(id: String, cfg: &InstanceConfig) -> Result<Self, Error> {
Ok(MyInstance { engine: MyEngine })
}
Expand Down
2 changes: 0 additions & 2 deletions crates/containerd-shim-wasm/src/sandbox/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ pub fn shim_main<'a, I>(
config: Option<Config>,
) where
I: 'static + Instance + Sync + Send,
I::Engine: Default,
{
#[cfg(unix)]
zygote::Zygote::init();
Expand Down Expand Up @@ -203,7 +202,6 @@ fn shim_main_inner<'a, I>(
config: Option<Config>,
) where
I: 'static + Instance + Sync + Send,
I::Engine: Default,
{
#[cfg(feature = "opentelemetry")]
{
Expand Down
3 changes: 0 additions & 3 deletions crates/containerd-shim-wasm/src/sandbox/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ pub struct InstanceConfig {
/// This trait requires that any type implementing it is `'static`, similar to `std::any::Any`.
/// This means that the type cannot contain a non-`'static` reference.
pub trait Instance: 'static {
/// The WASI engine type
type Engine: Send + Sync + Clone;

/// Create a new instance
fn new(id: String, cfg: &InstanceConfig) -> Result<Self, Error>
where
Expand Down
2 changes: 0 additions & 2 deletions crates/containerd-shim-wasm/src/sandbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
//! }
//!
//! impl Instance for MyInstance {
//! type Engine = MyEngine;
//!
//! fn new(id: String, cfg: &InstanceConfig) -> Result<Self, Error> {
//! Ok(MyInstance { engine: MyEngine })
//! }
Expand Down
16 changes: 4 additions & 12 deletions crates/containerd-shim-wasm/src/sandbox/shim/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env::current_dir;
use std::fmt::Debug;
use std::marker::PhantomData;
use std::sync::Arc;

use chrono::Utc;
Expand All @@ -16,17 +17,16 @@ use crate::sandbox::shim::local::Local;

/// Cli implements the containerd-shim cli interface using `Local<T>` as the task service.
pub struct Cli<T: Instance + Sync + Send> {
engine: T::Engine,
namespace: String,
containerd_address: String,
exit: Arc<ExitSignal>,
_id: String,
_phantom: PhantomData<T>,
}

impl<I> Debug for Cli<I>
where
I: Instance + Sync + Send,
<I as Instance>::Engine: Default,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
Expand All @@ -40,18 +40,17 @@ where
impl<I> shim::Shim for Cli<I>
where
I: Instance + Sync + Send,
<I as Instance>::Engine: Default,
{
type T = Local<I>;

#[cfg_attr(feature = "tracing", tracing::instrument(level = "Info"))]
fn new(_runtime_id: &str, args: &Flags, _config: &mut shim::Config) -> Self {
Cli {
engine: Default::default(),
namespace: args.namespace.to_string(),
containerd_address: args.address.clone(),
exit: Arc::default(),
_id: args.id.to_string(),
_phantom: PhantomData,
}
}

Expand Down Expand Up @@ -88,14 +87,7 @@ where
fn create_task_service(&self, publisher: RemotePublisher) -> Self::T {
let events = RemoteEventSender::new(&self.namespace, publisher);
let exit = self.exit.clone();
let engine = self.engine.clone();
Local::<I>::new(
engine,
events,
exit,
&self.namespace,
&self.containerd_address,
)
Local::<I>::new(events, exit, &self.namespace, &self.containerd_address)
}

#[cfg_attr(feature = "tracing", tracing::instrument(level = "Info"))]
Expand Down
5 changes: 1 addition & 4 deletions crates/containerd-shim-wasm/src/sandbox/shim/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ type LocalInstances<T> = RwLock<HashMap<String, Arc<InstanceData<T>>>>;
/// Local implements the Task service for a containerd shim.
/// It defers all task operations to the `Instance` implementation.
pub struct Local<T: Instance + Send + Sync, E: EventSender = RemoteEventSender> {
pub engine: T::Engine,
pub(super) instances: LocalInstances<T>,
events: E,
exit: Arc<ExitSignal>,
Expand All @@ -99,10 +98,9 @@ impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
/// Creates a new local task service.
#[cfg_attr(
feature = "tracing",
tracing::instrument(skip(engine, events, exit), level = "Debug")
tracing::instrument(skip(events, exit), level = "Debug")
)]
pub fn new(
engine: T::Engine,
events: E,
exit: Arc<ExitSignal>,
namespace: impl AsRef<str> + std::fmt::Debug,
Expand All @@ -112,7 +110,6 @@ impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
let namespace = namespace.as_ref().to_string();
let containerd_address = containerd_address.as_ref().to_string();
Self {
engine,
instances,
events,
exit,
Expand Down
4 changes: 0 additions & 4 deletions crates/containerd-shim-wasm/src/sandbox/shim/local/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub struct InstanceStub {
}

impl Instance for InstanceStub {
type Engine = ();
fn new(_id: String, _cfg: &InstanceConfig) -> Result<Self, Error> {
Ok(InstanceStub {
exit_code: WaitableCell::new(),
Expand Down Expand Up @@ -106,7 +105,6 @@ fn test_delete_after_create() {

let (tx, _rx) = channel();
let local = Arc::new(Local::<InstanceStub, _>::new(
(),
tx,
Arc::new(ExitSignal::default()),
"test_namespace",
Expand Down Expand Up @@ -137,7 +135,6 @@ fn test_cri_task() -> Result<()> {
let (etx, _erx) = channel();
let exit_signal = Arc::new(ExitSignal::default());
let local = Arc::new(Local::<InstanceStub, _>::new(
(),
etx,
exit_signal,
"test_namespace",
Expand Down Expand Up @@ -307,7 +304,6 @@ fn test_task_lifecycle() -> Result<()> {
let (etx, _erx) = channel(); // TODO: check events
let exit_signal = Arc::new(ExitSignal::default());
let local = Arc::new(Local::<InstanceStub, _>::new(
(),
etx,
exit_signal,
"test_namespace",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ pub struct Instance<E: Engine> {
}

impl<E: Engine + Default> SandboxInstance for Instance<E> {
type Engine = E;

#[cfg_attr(feature = "tracing", tracing::instrument(level = "Info"))]
fn new(id: String, cfg: &InstanceConfig) -> Result<Self, SandboxError> {
// check if container is OCI image with wasm layers and attempt to read the module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use crate::sandbox::{Error as SandboxError, Instance as SandboxInstance, Instanc
pub struct Instance<E: Engine>(PhantomData<E>);

impl<E: Engine> SandboxInstance for Instance<E> {
type Engine = E;

fn new(_id: String, _cfg: &InstanceConfig) -> Result<Self, SandboxError> {
todo!();
}
Expand Down
20 changes: 4 additions & 16 deletions crates/containerd-shim-wasm/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,20 @@ use crate::sandbox::{Instance, InstanceConfig};
pub const TEST_NAMESPACE: &str = "runwasi-test";
pub const SIGKILL: u32 = 9;

pub struct WasiTestBuilder<WasiInstance: Instance>
where
WasiInstance::Engine: Default + Send + Sync + Clone,
{
pub struct WasiTestBuilder<WasiInstance: Instance> {
container_name: String,
start_fn: String,
namespaces: Vec<LinuxNamespace>,
tempdir: tempfile::TempDir,
_phantom: PhantomData<WasiInstance>,
}

pub struct WasiTest<WasiInstance: Instance>
where
WasiInstance::Engine: Default + Send + Sync + Clone,
{
pub struct WasiTest<WasiInstance: Instance> {
instance: WasiInstance,
tempdir: tempfile::TempDir,
}

impl<WasiInstance: Instance> WasiTestBuilder<WasiInstance>
where
WasiInstance::Engine: Default + Send + Sync + Clone,
{
impl<WasiInstance: Instance> WasiTestBuilder<WasiInstance> {
pub fn new() -> Result<Self> {
zygote::Zygote::init();

Expand Down Expand Up @@ -230,10 +221,7 @@ where
}
}

impl<WasiInstance: Instance> WasiTest<WasiInstance>
where
WasiInstance::Engine: Default + Send + Sync + Clone,
{
impl<WasiInstance: Instance> WasiTest<WasiInstance> {
pub fn builder() -> Result<WasiTestBuilder<WasiInstance>> {
WasiTestBuilder::new()
}
Expand Down
Loading