From 22926d3a12ae798c5382fa39795f813989dcbaab Mon Sep 17 00:00:00 2001 From: yummyMax Date: Tue, 29 Oct 2024 14:51:41 +0800 Subject: [PATCH] change socket path Some containerd test use shim.SocketAddress directly. So for Goshim-compatible socket path Signed-off-by: yummyMax --- .github/workflows/ci.yml | 2 +- crates/shim/Cargo.toml | 1 + crates/shim/README.md | 6 +++--- crates/shim/src/lib.rs | 15 +++++++-------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38b0d050..2103c5b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -222,7 +222,7 @@ jobs: # run the example cargo run -p containerd-shim --example skeleton -- -namespace default -id 1234 -address "\\.\pipe\containerd-containerd" -publish-binary ./bin/containerd start ps skeleton - cargo run -p containerd-shim-protos --example shim-proto-connect \\.\pipe\containerd-shim-17630016127144989388-pipe + cargo run -p containerd-shim-protos --example shim-proto-connect \\.\pipe\containerd-shim-bc764c65e177434fcefe8257dc440be8b8acf7c96156320d965938f7e9ae1a35-pipe $skeleton = get-process skeleton -ErrorAction SilentlyContinue if ($skeleton) { exit 1 } - name: Run client diff --git a/crates/shim/Cargo.toml b/crates/shim/Cargo.toml index 620f3ab2..468f8edf 100644 --- a/crates/shim/Cargo.toml +++ b/crates/shim/Cargo.toml @@ -37,6 +37,7 @@ path = "examples/windows_log_reader.rs" containerd-shim-protos = { path = "../shim-protos", version = "0.7.2" } go-flag = "0.1.0" lazy_static = "1.4.0" +sha2 = "0.10.2" libc.workspace = true log = { workspace = true, features = ["std", "kv_unstable" ] } nix = { workspace = true, features = [ diff --git a/crates/shim/README.md b/crates/shim/README.md index b9dee26a..a17f9b79 100644 --- a/crates/shim/README.md +++ b/crates/shim/README.md @@ -175,7 +175,7 @@ $ cat log $env:TTRPC_ADDRESS="\\.\pipe\containerd-containerd.ttrpc" $ cargo run --example skeleton -- -namespace default -id 1234 -address "\\.\pipe\containerd-containerd" start -\\.\pipe\containerd-shim-17630016127144989388-pipe +\\.\pipe\containerd-shim-bc764c65e177434fcefe8257dc440be8b8acf7c96156320d965938f7e9ae1a35-pipe # (Optional) Run the log collector in a separate command window # note: log reader won't work if containerd is connected to the named pipe, this works when running manually to help debug locally @@ -183,8 +183,8 @@ $ cargo run --example windows-log-reader \\.\pipe\containerd-shim-default-1234-l Reading logs from: \\.\pipe\containerd-shim-default-1234-log -$ cargo run --example shim-proto-connect \\.\pipe\containerd-shim-17630016127144989388-pipe -Connecting to \\.\pipe\containerd-shim-17630016127144989388-pipe... +$ cargo run --example shim-proto-connect \\.\pipe\containerd-shim-bc764c65e177434fcefe8257dc440be8b8acf7c96156320d965938f7e9ae1a35-pipe +Connecting to \\.\pipe\containerd-shim-bc764c65e177434fcefe8257dc440be8b8acf7c96156320d965938f7e9ae1a35-pipe... Sending `Connect` request... Connect response: version: "example" Sending `Shutdown` request... diff --git a/crates/shim/src/lib.rs b/crates/shim/src/lib.rs index d428fd82..ae30f4f3 100644 --- a/crates/shim/src/lib.rs +++ b/crates/shim/src/lib.rs @@ -16,7 +16,7 @@ #![cfg_attr(feature = "docs", doc = include_str!("../README.md"))] -use std::{collections::hash_map::DefaultHasher, fs::File, hash::Hasher, path::PathBuf}; +use std::{fs::File, path::PathBuf}; #[cfg(unix)] use std::{ os::unix::{io::RawFd, net::UnixListener}, @@ -30,6 +30,7 @@ pub use protos::{ shim::shim::DeleteResponse, ttrpc::{context::Context, Result as TtrpcResult}, }; +use sha2::{Digest, Sha256}; #[cfg(unix)] ioctl_write_ptr_bad!(ioctl_set_winsz, libc::TIOCSWINSZ, libc::winsize); @@ -173,17 +174,15 @@ pub fn socket_address(socket_path: &str, namespace: &str, id: &str) -> String { .join(id) .display() .to_string(); - let hash = { - let mut hasher = DefaultHasher::new(); - hasher.write(path.as_bytes()); - hasher.finish() + let mut hasher = Sha256::new(); + hasher.update(path); + hasher.finalize() }; - if cfg!(unix) { - format!("unix://{}/{:x}.sock", SOCKET_ROOT, hash) + format!("unix://{}/s/{:x}", SOCKET_ROOT, hash) } else if cfg!(windows) { - format!(r"\\.\pipe\containerd-shim-{}-pipe", hash) + format!(r"\\.\pipe\containerd-shim-{:x}-pipe", hash) } else { panic!("unsupported platform") }