Skip to content

Commit

Permalink
Merge pull request #671 from Mossaka/deprecate-daemon
Browse files Browse the repository at this point in the history
deprecate: remove 'shared' mode
  • Loading branch information
Mossaka authored Sep 16, 2024
2 parents 137f494 + 92421f0 commit 8ca3cd2
Show file tree
Hide file tree
Showing 12 changed files with 5 additions and 480 deletions.
5 changes: 0 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 2 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ on the CNCF slack.

## Usage

runwasi is intended to be consumed as a library to be linked to from your own wasm host implementation.
runwasi is intended to be consumed as a library to be linked to from your own wasm host implementation. It creates one shim process per container or k8s pod.

There are two modes of operation supported:

1. "Normal" mode where there is 1 shim process per container or k8s pod.
2. "Shared" mode where there is a single manager service running all shims in process.

In either case you need to implement a trait to teach runwasi how to use your wasm host.
You need to implement a trait to teach runwasi how to use your wasm host.

There are two ways to do this:
* implementing the `sandbox::Instance` trait
Expand Down Expand Up @@ -119,45 +114,6 @@ I encourage you to checkout how that is implemented.

The shim binary just needs to be installed into `$PATH` (as seen by the containerd process) with a binary name like `containerd-shim-myshim-v1`.

For the shared mode:

```rust
use containerd_shim_wasm::sandbox::{Local, ManagerService, Instance};
use containerd_shim_wasm::services::sandbox_ttrpc::{create_manager, Manager};
use std::sync::Arc;
use ttrpc::{self, Server};
/// ...

struct MyInstance {
/// ...
}

impl Instance for MyInstance {
// ...
}

fn main() {
let s: ManagerService<Local<MyInstance>> =
ManagerService::new(Engine::new(Config::new().interruptable(true)).unwrap());
let s = Arc::new(Box::new(s) as Box<dyn Manager + Send + Sync>);
let service = create_manager(s);

let mut server = Server::new()
.bind("unix:///run/io.containerd.myshim.v1/manager.sock")
.unwrap()
.register_service(service);

server.start().unwrap();
let (_tx, rx) = std::sync::mpsc::channel::<()>();
rx.recv().unwrap();
}
```

This will be the host daemon that you startup and manage on your own.
You can use the provided `containerd-shim-myshim-v1` binary as the shim to specify in containerd.

Shared mode requires precise control over real threads and as such should not be used with an async runtime.

Check out these projects that build on top of runwasi:
- [spinkube/containerd-shim-spin](https://github.com/spinkube/containerd-shim-spin)
- [deislabs/containerd-wasm-shims](https://github.com/deislabs/containerd-wasm-shims)
Expand All @@ -174,24 +130,6 @@ And make sure the shim binary must be in $PATH (that is the $PATH that container
This shim runs one per pod.

- **containerd-shim-[ wasmedge | wasmtime | wasmer ]d-v1**

A cli used to connect containerd to the `containerd-[ wasmedge | wasmtime | wasmer ]d` sandbox daemon.
When containerd requests for a container to be created, it fires up this shim binary which will connect to the `containerd-[ wasmedge | wasmtime | wasmer ]d` service running on the host.
The service will return a path to a unix socket which this shim binary will write back to containerd which containerd will use to connect to for shim requests.
This binary does not serve requests, it is only responsible for sending requests to the `containerd-[ wasmedge | wasmtime | wasmer ]d` daemon to create or destroy sandboxes.

- **containerd-[ wasmedge | wasmtime | wasmer ]d**

This is a sandbox manager that enables running 1 wasm host for the entire node instead of one per pod (or container).
When a container is created, a request is sent to this service to create a sandbox.
The "sandbox" is a containerd task service that runs in a new thread on its own unix socket, which we return back to containerd to connect to.

The Wasmedge / Wasmtime / Wasmer engine is shared between all sandboxes in the service.

To use this shim, specify `io.containerd.[ wasmedge | wasmtime | wasmer ]d.v1` as the runtime to use.
You will need to make sure the `containerd-[ wasmedge | wasmtime | wasmer ]d` daemon has already been started.

## Contributing

To begin contributing, learn to build and test the project or to add a new shim please read our [CONTRIBUTING.md](./CONTRIBUTING.md)
Expand Down
5 changes: 0 additions & 5 deletions crates/containerd-shim-wasm-test-modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ license.workspace = true

[dependencies]
anyhow = { workspace = true }
env_logger = { workspace = true }
libc = { workspace = true }
log = { workspace = true }
oci-spec = { workspace = true }
serde_json = { workspace = true }
tempfile = { workspace = true }

[build-dependencies]
anyhow = { workspace = true }
Expand Down
35 changes: 0 additions & 35 deletions crates/containerd-shim-wasm/build.rs

This file was deleted.

41 changes: 0 additions & 41 deletions crates/containerd-shim-wasm/protos/sandbox.proto

This file was deleted.

1 change: 0 additions & 1 deletion crates/containerd-shim-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

pub mod container;
pub mod sandbox;
pub mod services;

#[cfg_attr(unix, path = "sys/unix/mod.rs")]
#[cfg_attr(windows, path = "sys/windows/mod.rs")]
Expand Down
40 changes: 2 additions & 38 deletions crates/containerd-shim-wasm/src/sandbox/cli.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
use std::path::PathBuf;
use std::sync::mpsc::channel;
use std::sync::Arc;

use containerd_shim::{parse, run, Config};
use ttrpc::Server;

use crate::sandbox::manager::Shim;
use crate::sandbox::shim::Local;
#[cfg(feature = "opentelemetry")]
use crate::sandbox::shim::{otel_traces_enabled, OTLPConfig};
use crate::sandbox::{Instance, ManagerService, ShimCli};
use crate::services::sandbox_ttrpc::{create_manager, Manager};
use crate::sandbox::{Instance, ShimCli};

pub mod r#impl {
pub use git_version::git_version;
Expand Down Expand Up @@ -115,37 +109,7 @@ fn shim_main_inner<'a, I>(
let shim_version = shim_version.into().unwrap_or("v1");

let lower_name = name.to_lowercase();
let shim_cli = format!("containerd-shim-{lower_name}-{shim_version}");
let shim_client = format!("containerd-shim-{lower_name}d-{shim_version}");
let shim_daemon = format!("containerd-{lower_name}d");
let shim_id = format!("io.containerd.{lower_name}.{shim_version}");

match argv0.to_lowercase() {
s if s == shim_cli => {
run::<ShimCli<I>>(&shim_id, config);
}
s if s == shim_client => {
run::<Shim>(&shim_client, config);
}
s if s == shim_daemon => {
log::info!("starting up!");
let s: ManagerService<Local<I>> = Default::default();
let s = Arc::new(Box::new(s) as Box<dyn Manager + Send + Sync>);
let service = create_manager(s);

let mut server = Server::new()
.bind("unix:///run/io.containerd.wasmwasi.v1/manager.sock")
.expect("failed to bind to socket")
.register_service(service);

server.start().expect("failed to start daemon");
log::info!("server started!");
let (_tx, rx) = channel::<()>();
rx.recv().unwrap();
}
_ => {
eprintln!("error: unrecognized binary name, expected one of {shim_cli}, {shim_client}, or {shim_daemon}.");
std::process::exit(1);
}
}
run::<ShimCli<I>>(&shim_id, config);
}
Loading

0 comments on commit 8ca3cd2

Please sign in to comment.