Skip to content

Commit

Permalink
Merge branch 'main' into dev2
Browse files Browse the repository at this point in the history
Signed-off-by: jokemanfire <[email protected]>
  • Loading branch information
jokemanfire authored Oct 12, 2024
2 parents 272de15 + 7794b07 commit d1c0e06
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 55 deletions.
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ nix = "0.29"
oci-spec = "0.6"
os_pipe = "1.1"
prctl = "1.0.0"
prost = "0.12"
prost-build = "0.12"
prost-types = "0.12"
prost = "0.13"
prost-build = "0.13"
prost-types = "0.13"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
simple_logger = { version = "5.0", default-features = false }
tempfile = "3.6"
thiserror = "1.0"
time = { version = "0.3.29", features = ["serde", "std", "formatting"] }
tokio = "1.40"
tonic = "0.11"
tonic-build = "0.11"
tower = "0.4"
tonic = "0.12"
tonic-build = "0.12"
tower = "0.5"

uuid = { version = "1.0", features = ["v4"] }
3 changes: 2 additions & 1 deletion crates/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "containerd-client"
version = "0.5.0"
version = "0.6.0"
authors = [
"Maksym Pavlenko <[email protected]>",
"The containerd Authors",
Expand All @@ -23,6 +23,7 @@ name = "version"
path = "examples/version.rs"

[dependencies]
hyper-util = "0.1.6" # https://github.com/hyperium/hyper/issues/3110
prost.workspace = true
prost-types.workspace = true
tokio = { workspace = true, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/client/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn main() {

tonic_build::configure()
.build_server(false)
.compile_with_config(config, PROTO_FILES, &["vendor/"])
.compile_protos_with_config(config, PROTO_FILES, &["vendor/"])
.expect("Failed to generate GRPC bindings");

for module in FIXUP_MODULES {
Expand Down
34 changes: 20 additions & 14 deletions crates/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,29 @@ pub async fn connect(

let path = path.as_ref().to_path_buf();

// Taken from https://github.com/hyperium/tonic/blob/eeb3268f71ae5d1107c937392389db63d8f721fb/examples/src/uds/client.rs#L19
// Taken from https://github.com/hyperium/tonic/blob/71fca362d7ffbb230547f23b3f2fb75c414063a8/examples/src/uds/client.rs#L21-L28
// There will ignore this uri because uds do not use it
// and make connection with UnixStream::connect.
let channel = Endpoint::try_from("http://[::]")
.unwrap()
let channel = Endpoint::try_from("http://[::]")?
.connect_with_connector(tower::service_fn(move |_| {
#[cfg(unix)]
{
tokio::net::UnixStream::connect(path.clone())
}

#[cfg(windows)]
{
let client = tokio::net::windows::named_pipe::ClientOptions::new()
.open(path.clone())
.map_err(|e| std::io::Error::from(e));
async move { client }
let path = path.clone();

async move {
#[cfg(unix)]
{
Ok::<_, std::io::Error>(hyper_util::rt::TokioIo::new(
tokio::net::UnixStream::connect(path).await?,
))
}

#[cfg(windows)]
{
let client = tokio::net::windows::named_pipe::ClientOptions::new()
.open(&path)
.map_err(|e| std::io::Error::from(e))?;

Ok::<_, std::io::Error>(hyper_util::rt::TokioIo::new(client))
}
}
}))
.await?;
Expand Down
1 change: 1 addition & 0 deletions crates/runc/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub async fn write_value_to_temp_file<T: Serialize>(value: &T) -> Result<String,
let filename = format!("{}/runc-process-{}", xdg_runtime_dir(), Uuid::new_v4());
let mut f = tokio::fs::OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&filename)
.await
Expand Down
10 changes: 6 additions & 4 deletions crates/shim-protos/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "containerd-shim-protos"
version = "0.7.0"
version = "0.7.2"
authors = [
"Maksym Pavlenko <[email protected]>",
"The containerd Authors",
Expand Down Expand Up @@ -49,11 +49,13 @@ required-features = ["async"]

[dependencies]
async-trait = { workspace = true, optional = true }
protobuf = "=3.5"
ttrpc = "0.8"
# protobuf 3.5 introduces a breaking change: https://github.com/containerd/rust-extensions/issues/295
# pinning to <3.5.0 until we can update the generated code
protobuf = ">= 3.0, <3.5.0"
ttrpc = "0.8.2"

[build-dependencies]
ttrpc-codegen = "0.4"
ttrpc-codegen = "0.4.2"

[dev-dependencies]
ctrlc = { version = "3.0", features = ["termination"] }
Expand Down
4 changes: 1 addition & 3 deletions crates/shim-protos/examples/ttrpc-server-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ impl Task for FakeServer {
async fn main() {
simple_logger::SimpleLogger::new().init().unwrap();

let t = Box::new(FakeServer::new()) as Box<dyn Task + Send + Sync>;
let t = Arc::new(t);
let tservice = create_task(t);
let tservice = create_task(Arc::new(FakeServer::new()));

let mut server = Server::new()
.bind("unix:///tmp/shim-proto-ttrpc-001")
Expand Down
4 changes: 1 addition & 3 deletions crates/shim-protos/examples/ttrpc-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ impl Task for FakeServer {
fn main() {
simple_logger::SimpleLogger::new().init().unwrap();

let t = Box::new(FakeServer::new()) as Box<dyn Task + Send + Sync>;
let t = Arc::new(t);
let tservice = create_task(t);
let tservice = create_task(Arc::new(FakeServer::new()));

let mut server = Server::new()
.bind("unix:///tmp/shim-proto-ttrpc-001")
Expand Down
10 changes: 3 additions & 7 deletions crates/shim-protos/tests/ttrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ fn create_ttrpc_context() -> (

#[test]
fn test_task_method_num() {
let server = Arc::new(Box::new(FakeServer::new()) as Box<dyn Task + Send + Sync>);
let task = create_task(server.clone());

let task = create_task(Arc::new(FakeServer::new()));
assert_eq!(task.len(), 17);
}

Expand All @@ -98,8 +96,7 @@ fn test_create_task() {
request.set_timeout_nano(10000);
request.set_metadata(ttrpc::context::to_pb(ctx.metadata.clone()));

let server = Arc::new(Box::new(FakeServer::new()) as Box<dyn Task + Send + Sync>);
let task = create_task(server.clone());
let task = create_task(Arc::new(FakeServer::new()));
let create = task.get("/containerd.task.v2.Task/Create").unwrap();
create.handler(ctx, request).unwrap();

Expand Down Expand Up @@ -140,8 +137,7 @@ fn test_delete_task() {
request.set_timeout_nano(10000);
request.set_metadata(ttrpc::context::to_pb(ctx.metadata.clone()));

let server = Arc::new(Box::new(FakeServer::new()) as Box<dyn Task + Send + Sync>);
let task = create_task(server.clone());
let task = create_task(Arc::new(FakeServer::new()));
let delete = task.get("/containerd.task.v2.Task/Delete").unwrap();
delete.handler(ctx, request).unwrap();

Expand Down
4 changes: 2 additions & 2 deletions crates/shim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "containerd-shim"
version = "0.7.1"
version = "0.7.4"
authors = [
"Maksym Pavlenko <[email protected]>",
"The containerd Authors",
Expand Down Expand Up @@ -34,7 +34,7 @@ name = "windows-log-reader"
path = "examples/windows_log_reader.rs"

[dependencies]
containerd-shim-protos = { path = "../shim-protos", version = "0.7.0" }
containerd-shim-protos = { path = "../shim-protos", version = "0.7.2" }
go-flag = "0.1.0"
lazy_static = "1.4.0"
libc.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/shim/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn parse<S: AsRef<OsStr>>(args: &[S]) -> Result<Flags> {
})
.map_err(|e| Error::InvalidArgument(e.to_string()))?;

if let Some(action) = args.get(0) {
if let Some(action) = args.first() {
flags.action = action.into();
}

Expand Down
2 changes: 1 addition & 1 deletion crates/shim/src/asynchronous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ where

let publisher = RemotePublisher::new(&ttrpc_address).await?;
let task = shim.create_task_service(publisher).await;
let task_service = create_task(Arc::new(Box::new(task)));
let task_service = create_task(Arc::new(task));
let mut server = Server::new().register_service(task_service);
server = server.add_listener(SOCKET_FD)?;
server = server.set_domain_unix();
Expand Down
3 changes: 1 addition & 2 deletions crates/shim/src/asynchronous/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ mod tests {
let barrier2 = barrier.clone();
let server_thread = tokio::spawn(async move {
let listener = UnixListener::bind(&path1).unwrap();
let t = Arc::new(Box::new(server) as Box<dyn Events + Send + Sync>);
let service = create_events(t);
let service = create_events(Arc::new(server));
let mut server = Server::new()
.set_domain_unix()
.add_listener(listener.as_raw_fd())
Expand Down
2 changes: 0 additions & 2 deletions crates/shim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,12 @@ macro_rules! cfg_async {
}

cfg_not_async! {
pub use crate::synchronous::*;
pub use crate::synchronous::publisher;
pub use protos::shim::shim_ttrpc::Task;
pub use protos::ttrpc::TtrpcContext;
}

cfg_async! {
pub use crate::asynchronous::*;
pub use crate::asynchronous::publisher;
pub use protos::shim_async::Task;
pub use protos::ttrpc::r#async::TtrpcContext;
Expand Down
2 changes: 1 addition & 1 deletion crates/shim/src/synchronous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ where

let publisher = publisher::RemotePublisher::new(&ttrpc_address)?;
let task = shim.create_task_service(publisher);
let task_service = create_task(Arc::new(Box::new(task)));
let task_service = create_task(Arc::new(task));
let mut server = create_server(flags)?;
server = server.register_service(task_service);
server.start()?;
Expand Down
6 changes: 2 additions & 4 deletions crates/shim/src/synchronous/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ mod tests {
use std::os::unix::{io::AsRawFd, net::UnixListener};
let listener = UnixListener::bind(server_address).unwrap();
listener.set_nonblocking(true).unwrap();
let t = Arc::new(Box::new(FakeServer {}) as Box<dyn Events + Send + Sync>);
let service = client::create_events(t);
let service = client::create_events(Arc::new(FakeServer {}));
let server = Server::new()
.add_listener(listener.as_raw_fd())
.unwrap()
Expand All @@ -200,8 +199,7 @@ mod tests {

#[cfg(windows)]
{
let t = Arc::new(Box::new(FakeServer {}) as Box<dyn Events + Send + Sync>);
let service = client::create_events(t);
let service = client::create_events(Arc::new(FakeServer {}));

Server::new()
.bind(server_address)
Expand Down
1 change: 1 addition & 0 deletions crates/shim/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
#[cfg(windows)]
pub(crate) mod windows;
#[cfg(windows)]
#[allow(unused_imports)]
pub use crate::sys::windows::NamedPipeLogger;
2 changes: 1 addition & 1 deletion crates/shim/src/sys/windows/named_pipe_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl log::Log for NamedPipeLogger {
.current_connection
.lock()
.unwrap()
.write(message.as_bytes())
.write_all(message.as_bytes())
{
Ok(_) => {}
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {
Expand Down
2 changes: 1 addition & 1 deletion crates/snapshots/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const FIXUP_MODULES: &[&str] = &["containerd.services.snapshots.v1"];
fn main() {
tonic_build::configure()
.build_server(true)
.compile(PROTO_FILES, &["vendor/"])
.compile_protos(PROTO_FILES, &["vendor/"])
.expect("Failed to generate GRPC bindings");

for module in FIXUP_MODULES {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.74"
channel = "1.77"
components = ["rustfmt", "clippy", "llvm-tools"]

0 comments on commit d1c0e06

Please sign in to comment.