Skip to content

Commit c836f13

Browse files
jsturtevantmxpv
authored andcommitted
Add support for windows to containerd client
Adds support to containerd client and enables running the examples Signed-off-by: James Sturtevant <[email protected]>
1 parent c696ce4 commit c836f13

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ jobs:
4646
steps:
4747
- uses: actions/checkout@v4
4848
- run: ./scripts/install-protobuf.sh
49-
- run: cargo check --examples --tests -p containerd-shim -p containerd-shim-protos
49+
- run: cargo check --examples --tests -p containerd-shim -p containerd-shim-protos -p containerd-client
5050

5151
- run: rustup toolchain install nightly --component rustfmt
52-
- run: cargo +nightly fmt -p containerd-shim -p containerd-shim-protos -- --check --files-with-diff
52+
- run: cargo +nightly fmt -p containerd-shim -p containerd-shim-protos -p containerd-client -- --check --files-with-diff
5353

5454
- run: cargo clippy -p containerd-shim -p containerd-shim-protos -- -D warnings
55-
- run: cargo doc --no-deps -p containerd-shim -p containerd-shim-protos
55+
- run: cargo doc --no-deps -p containerd-shim -p containerd-shim-protos -p containerd-client
5656
env:
5757
RUSTDOCFLAGS: -Dwarnings
5858

@@ -80,7 +80,7 @@ jobs:
8080
env:
8181
# runc::tests::test_exec needs $XDG_RUNTIME_DIR to be set
8282
XDG_RUNTIME_DIR: /tmp/dummy-xdr
83-
- run: cargo test -p containerd-shim -p containerd-shim-protos
83+
- run: cargo test -p containerd-shim -p containerd-shim-protos -p containerd-client
8484
if: ${{ contains(matrix.os, 'windows') }}
8585

8686
# Collect build timings
@@ -219,6 +219,12 @@ jobs:
219219
cargo run -p containerd-shim-protos --example shim-proto-connect \\.\pipe\containerd-shim-17630016127144989388-pipe
220220
$skeleton = get-process skeleton -ErrorAction SilentlyContinue
221221
if ($skeleton) { exit 1 }
222+
- name: Run client
223+
run: |
224+
$ErrorActionPreference = "Stop"
225+
226+
get-service containerd
227+
cargo run -p containerd-client --example version
222228
223229
# Currently Github actions UI supports no masks to mark matrix jobs as required to pass status checks.
224230
# This means that every time version of Go, containerd, or OS is changed, a corresponding job should

crates/client/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ tower = { workspace = true, optional = true }
3232
[build-dependencies]
3333
tonic-build.workspace = true
3434

35+
[dev-dependencies]
36+
tokio = { workspace = true, features = ["rt", "macros"]}
37+
3538
[features]
3639
connect = ["tokio", "tower"]
3740
docs = []

crates/client/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ This crate implements a GRPC client to query containerd APIs.
99

1010
## Example
1111

12+
Run with `cargo run --example version`
13+
1214
```rust
1315
use containerd_client::{connect, services::v1::version_client::VersionClient};
1416

crates/client/examples/version.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ use containerd_client::Client;
1919
/// Make sure you run containerd before running this example.
2020
#[tokio::main(flavor = "current_thread")]
2121
async fn main() {
22-
let client = Client::from_path("/var/run/containerd/containerd.sock")
23-
.await
24-
.expect("Connect failed");
22+
#[cfg(unix)]
23+
let path = "/var/run/containerd/containerd.sock";
24+
25+
#[cfg(windows)]
26+
let path = r"\\.\pipe\containerd-containerd";
27+
28+
let client = Client::from_path(path).await.expect("Connect failed");
2529

2630
let resp = client
2731
.version()

crates/client/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ pub mod events {
8282
pub async fn connect(
8383
path: impl AsRef<std::path::Path>,
8484
) -> Result<tonic::transport::Channel, tonic::transport::Error> {
85-
use tokio::net::UnixStream;
8685
use tonic::transport::Endpoint;
8786

8887
let path = path.as_ref().to_path_buf();
@@ -91,7 +90,18 @@ pub async fn connect(
9190
let channel = Endpoint::try_from("https://[::]")
9291
.unwrap()
9392
.connect_with_connector(tower::service_fn(move |_| {
94-
UnixStream::connect(path.clone())
93+
#[cfg(unix)]
94+
{
95+
tokio::net::UnixStream::connect(path.clone())
96+
}
97+
98+
#[cfg(windows)]
99+
{
100+
let client = tokio::net::windows::named_pipe::ClientOptions::new()
101+
.open(path.clone())
102+
.map_err(|e| std::io::Error::from(e));
103+
async move { client }
104+
}
95105
}))
96106
.await?;
97107

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
22
channel = "1.71"
3-
components = ["rustfmt", "clippy", "llvm-tools-preview"]
3+
components = ["rustfmt", "clippy", "llvm-tools"]

0 commit comments

Comments
 (0)