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

send delete event while initial process deleted #301

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 11 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:

- run: cargo clippy --all-targets -- -D warnings
- run: cargo clippy --all-targets --all-features -- -D warnings
# the shim has sync code that is not covered when running with --all-features

# the shim has sync code that is not covered when running with --all-features
- run: cargo clippy -p containerd-shim --all-targets -- -D warnings

- run: cargo doc --no-deps --features docs
Expand All @@ -49,10 +49,10 @@ jobs:
- run: ./scripts/install-protobuf.sh
shell: bash
- run: cargo check --examples --tests -p containerd-shim -p containerd-shim-protos -p containerd-client

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

- run: cargo clippy -p containerd-shim -p containerd-shim-protos -- -D warnings
- run: cargo doc --no-deps -p containerd-shim -p containerd-shim-protos -p containerd-client
env:
Expand All @@ -76,8 +76,8 @@ jobs:
mkdir -p /tmp/dummy-xdr
sudo -E $(command -v cargo) test
sudo -E $(command -v cargo) test --all-features
# the shim has sync code that is not covered when running with --all-features

# the shim has sync code that is not covered when running with --all-features
sudo -E $(command -v cargo) test -p containerd-shim
if: ${{ !contains(matrix.os, 'windows') }}
env:
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:
run: |
sudo -E PATH=$PATH make integration
working-directory: src/github.com/containerd/containerd

windows-integration:
name: Windows Integration
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -217,11 +217,11 @@ jobs:
$ErrorActionPreference = "Stop"

get-service containerd
$env:TTRPC_ADDRESS="\\.\pipe\containerd-containerd.ttrpc"
$env:TTRPC_ADDRESS="\\.\pipe\containerd-containerd.ttrpc"

# 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
# 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
$skeleton = get-process skeleton -ErrorAction SilentlyContinue
if ($skeleton) { exit 1 }
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ jobs:
run: |
git tag $TAG
git push origin $TAG

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ edition = "2021"
# Common dependencies for all crates
[workspace.dependencies]
async-trait = "0.1.52"
cgroups-rs = "0.3.4"
crossbeam = "0.8.1"
futures = "0.3.19"
libc = "0.2.112"
log = {version = "0.4.2", features=["kv_unstable"]}
Expand All @@ -37,6 +39,8 @@ prost-build = "0.12"
prost-types = "0.12"
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.26"
Expand Down
2 changes: 1 addition & 1 deletion crates/client/examples/container_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@
"/proc/sysrq-trigger"
]
}
}
}

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

6 changes: 3 additions & 3 deletions crates/runc-shim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ doc = false

[dependencies]
containerd-shim = { path = "../shim", version = "0.7.1", features = ["async"] }
crossbeam = "0.8.1"
crossbeam.workspace = true
libc.workspace = true
log.workspace = true
nix = { workspace = true, features = ["socket", "uio", "term"] }
Expand All @@ -44,5 +44,5 @@ futures.workspace = true
tokio = { workspace = true, features = ["full"] }

[target.'cfg(target_os = "linux")'.dependencies]
cgroups-rs = "0.3.3"
nix = { workspace = true, features = ["event"] }
cgroups-rs.workspace = true
nix = { workspace = true, features = ["event"] }
2 changes: 1 addition & 1 deletion crates/runc-shim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ In addition, we also run 100 pods and collect the total memory overhead.
| :----------------------------------------------------------- | :----------------- | :---------------- |
| containerd-shim-runc-v2 | 11.02MB | 1106.52MB |
| containerd-shim-runc-v2-rs(sync) | 3.45MB | 345.39MB |
| containerd-shim-runc-v2-rs(async, limited to 2 work threads) | 3.90MB | 396.83MB |
| containerd-shim-runc-v2-rs(async, limited to 2 work threads) | 3.90MB | 396.83MB |
2 changes: 1 addition & 1 deletion crates/runc-shim/src/cgroup_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub async fn register_memory_event(
let mut eventfd_file = unsafe { File::from_raw_fd(eventfd.as_raw_fd()) };
loop {
match eventfd_file.read(&mut buf).await {
Ok(bytes_read) if bytes_read == 0 => return,
Ok(0) => return,
Err(_) => return,
_ => (),
}
Expand Down
18 changes: 16 additions & 2 deletions crates/runc-shim/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use std::env;

use containerd_shim::{asynchronous::run, parse};
use tokio::runtime::Builder;

mod cgroup_memory;
mod common;
Expand All @@ -43,8 +44,21 @@ fn parse_version() {
}
}

#[tokio::main]
async fn main() {
fn main() {
let num_threads = std::env::var("RUSTMAXPROCS")
.map(|v| v.parse::<usize>().unwrap_or(2))
.unwrap_or(2);

let rt = Builder::new_multi_thread()
.worker_threads(num_threads)
.enable_all()
.build()
.expect("Failed to build Tokio runtime");

rt.block_on(async_main());
}

async fn async_main() {
parse_version();
run::<Service>("io.containerd.runc.v2-rs", None).await;
}
21 changes: 11 additions & 10 deletions crates/runc-shim/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,21 @@ where
let exec_id_opt = req.exec_id().as_option();
let (pid, exit_status, exited_at) = container.delete(exec_id_opt).await?;
self.factory.cleanup(&self.namespace, container).await?;

let ts = convert_to_timestamp(exited_at);
// if we deleted an init task, send the task delete event
if req.exec_id().is_empty() {
containers.remove(req.id());
self.send_event(TaskDelete {
container_id: id,
pid: pid as u32,
exit_status: exit_status as u32,
exited_at: Some(ts.clone()).into(),
..Default::default()
})
.await;
}

let ts = convert_to_timestamp(exited_at);
self.send_event(TaskDelete {
container_id: id,
pid: pid as u32,
exit_status: exit_status as u32,
exited_at: Some(ts.clone()).into(),
..Default::default()
})
.await;

let mut resp = DeleteResponse::new();
resp.set_exited_at(ts);
resp.set_pid(pid as u32);
Expand Down
4 changes: 2 additions & 2 deletions crates/runc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ oci-spec.workspace = true
os_pipe.workspace = true
path-absolutize = "3.0.11"
prctl.workspace = true
rand = "0.8.4"
rand = "0.8.5"
serde.workspace = true
serde_json.workspace = true
tempfile = "3.6.0"
tempfile.workspace = true
thiserror.workspace = true
time.workspace = true
uuid.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/runc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Crates.io](https://img.shields.io/crates/l/containerd-shim)](https://github.com/containerd/rust-extensions/blob/main/LICENSE)
[![CI](https://github.com/containerd/rust-extensions/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/containerd/rust-extensions/actions/workflows/ci.yml)

A crate for consuming the runc binary in your Rust applications, similar to [go-runc](https://github.com/containerd/go-runc) for Go.
A crate for consuming the runc binary in your Rust applications, similar to [go-runc](https://github.com/containerd/go-runc) for Go.
This crate is based on archived [rust-runc](https://github.com/pwFoo/rust-runc).

## Usage
Expand All @@ -29,7 +29,7 @@ async fn main() {
let opts = runc::options::CreateOpts::new()
.pid_file("/path/to/pid/file")
.no_pivot(true);

client.create("container-id", "path/to/bundle", Some(&opts)).unwrap();
}
```
Expand Down
8 changes: 3 additions & 5 deletions crates/shim-protos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ path = "examples/connect-async.rs"
required-features = ["async"]

[dependencies]
async-trait = { version = "0.1.48", optional = true }
async-trait = { workspace = true, optional = true }
protobuf = "=3.1"
ttrpc = "0.8"

Expand All @@ -58,11 +58,9 @@ ttrpc-codegen = "0.4"
[dev-dependencies]
ctrlc = { version = "3.0", features = ["termination"] }
log.workspace = true
simple_logger = { version = "5.0", default-features = false, features = [
"stderr",
] }
simple_logger = { workspace = true, features = ["stderr"] }
tokio = { workspace = true, features = ["full"] }
crossbeam = "0.8.0" # Used by create_ttrpc_context()
crossbeam.workspace = true # Used by create_ttrpc_context()

[package.metadata.docs.rs]
features = ["docs"]
2 changes: 1 addition & 1 deletion crates/shim-protos/vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Proto files are copy-pasted directly from upstream repos:
+ https://github.com/protocolbuffers/protobuf
+ https://github.com/gogo/protobuf
+ https://github.com/containerd/cgroups
+ https://github.com/microsoft/hcsshim
+ https://github.com/microsoft/hcsshim

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

6 changes: 3 additions & 3 deletions crates/shim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ nix = { workspace = true, features = [
] }
oci-spec.workspace = true
page_size = "0.6.0"
prctl = "1.0.0"
prctl.workspace = true
signal-hook = "0.3.13"
serde.workspace = true
serde_json.workspace = true
Expand All @@ -68,7 +68,7 @@ signal-hook-tokio = { version = "0.3.1", optional = true, features = [
tokio = { workspace = true, features = ["full"], optional = true }

[target.'cfg(target_os = "linux")'.dependencies]
cgroups-rs = "0.3.4"
cgroups-rs.workspace = true

[target.'cfg(unix)'.dependencies]
command-fds = "0.3.0"
Expand All @@ -87,7 +87,7 @@ windows-sys = { version = "0.52.0", features = [
] }

[dev-dependencies]
tempfile = "3.6"
tempfile.workspace = true

[package.metadata.docs.rs]
features = ["docs"]
5 changes: 1 addition & 4 deletions crates/shim/src/asynchronous/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ impl Monitor {
};

self.subscribers.insert(id, subscriber);
self.topic_subs
.entry(topic)
.or_insert_with(Vec::new)
.push(id);
self.topic_subs.entry(topic).or_default().push(id);
Ok(Subscription { id, rx })
}

Expand Down
5 changes: 1 addition & 4 deletions crates/shim/src/synchronous/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ impl Monitor {
topic: topic.clone(),
};
self.subscribers.insert(id, subscriber);
self.topic_subs
.entry(topic)
.or_insert_with(Vec::new)
.push(id);
self.topic_subs.entry(topic).or_default().push(id);
Ok(Subscription { id, rx })
}

Expand Down
3 changes: 1 addition & 2 deletions crates/snapshots/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ tokio = { workspace = true, features = ["sync"] }
tokio-stream = "0.1.8"

[dev-dependencies]
async-stream = "0.3.2"
futures.workspace = true
log.workspace = true
simple_logger = { version = "5.0", default-features = false }
simple_logger.workspace = true

[build-dependencies]
tonic-build.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/snapshots/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ Server::builder()
.serve_with_incoming(incoming)
.await
.expect("Serve failed");
```
```
7 changes: 4 additions & 3 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ignore = [
# * Medium - CVSS Score 4.0 - 6.9
# * High - CVSS Score 7.0 - 8.9
# * Critical - CVSS Score 9.0 - 10.0
#severity-threshold =
#severity-threshold =

# This section is considered when running `cargo deny check licenses`
# More documentation for the licenses section can be found here:
Expand All @@ -72,6 +72,7 @@ unlicensed = "deny"
allow = [
"MIT",
"Apache-2.0",
"BSD-2-Clause",
"BSD-3-Clause",
]
# List of explictly disallowed licenses
Expand Down Expand Up @@ -170,8 +171,8 @@ deny = [
skip = [
#{ name = "ansi_term", version = "=0.11.0" },
]
# Similarly to `skip` allows you to skip certain crates during duplicate
# detection. Unlike skip, it also includes the entire tree of transitive
# Similarly to `skip` allows you to skip certain crates during duplicate
# detection. Unlike skip, it also includes the entire tree of transitive
# dependencies starting at the specified crate, up to a certain depth, which is
# by default infinite
skip-tree = [
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.71"
channel = "1.74"
components = ["rustfmt", "clippy", "llvm-tools"]