Skip to content
Merged
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
8 changes: 4 additions & 4 deletions crates/runc-shim/src/asynchronous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use containerd_shim::{
util::{
convert_to_timestamp, read_options, read_runtime, read_spec, timestamp, write_str_to_file,
},
Config, Context, DeleteResponse, Error, StartOpts,
Config, Context, DeleteResponse, Error, Flags, StartOpts,
};
use log::{debug, error, warn};
use tokio::sync::mpsc::{channel, Receiver, Sender};
Expand Down Expand Up @@ -61,13 +61,13 @@ pub(crate) struct Service {
impl Shim for Service {
type T = TaskService<RuncFactory, RuncContainer>;

async fn new(_runtime_id: &str, id: &str, namespace: &str, _config: &mut Config) -> Self {
async fn new(_runtime_id: &str, args: &Flags, _config: &mut Config) -> Self {
let exit = Arc::new(ExitSignal::default());
// TODO: add publisher
Service {
exit,
id: id.to_string(),
namespace: namespace.to_string(),
id: args.id.to_string(),
namespace: args.namespace.to_string(),
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/runc-shim/src/synchronous/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use shim::{
convert_to_timestamp, read_options, read_runtime, read_spec_from_file, timestamp,
write_address,
},
warn, Config, Context, ExitSignal, Shim, StartOpts,
warn, Config, Context, ExitSignal, Flags, Shim, StartOpts,
};

use crate::{
Expand All @@ -56,11 +56,11 @@ use crate::{
impl Shim for Service {
type T = ShimTask<RuncFactory, RuncContainer>;

fn new(_runtime_id: &str, id: &str, namespace: &str, _config: &mut Config) -> Self {
fn new(_runtime_id: &str, args: &Flags, _config: &mut Config) -> Self {
Service {
exit: Arc::new(ExitSignal::default()),
id: id.to_string(),
namespace: namespace.to_string(),
id: args.id.to_string(),
namespace: args.namespace.to_string(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/shim/examples/skeleton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod skeleton {
use containerd_shim as shim;
use log::info;
use shim::{
api, synchronous::publisher::RemotePublisher, Config, DeleteResponse, ExitSignal,
api, synchronous::publisher::RemotePublisher, Config, DeleteResponse, ExitSignal, Flags,
TtrpcContext, TtrpcResult,
};

Expand All @@ -35,7 +35,7 @@ mod skeleton {
impl shim::Shim for Service {
type T = Service;

fn new(_runtime_id: &str, _id: &str, _namespace: &str, _config: &mut Config) -> Self {
fn new(_runtime_id: &str, _args: &Flags, _config: &mut Config) -> Self {
Service {
exit: Arc::new(ExitSignal::default()),
}
Expand Down
4 changes: 2 additions & 2 deletions crates/shim/examples/skeleton_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use async_trait::async_trait;
use containerd_shim::{
asynchronous::{run, spawn, ExitSignal, Shim},
publisher::RemotePublisher,
Config, Error, StartOpts, TtrpcResult,
Config, Error, Flags, StartOpts, TtrpcResult,
};
use containerd_shim_protos::{
api, api::DeleteResponse, shim_async::Task, ttrpc::r#async::TtrpcContext,
Expand All @@ -36,7 +36,7 @@ struct Service {
impl Shim for Service {
type T = Service;

async fn new(_runtime_id: &str, _id: &str, _namespace: &str, _config: &mut Config) -> Self {
async fn new(_runtime_id: &str, _args: &Flags, _config: &mut Config) -> Self {
Service {
exit: Arc::new(ExitSignal::default()),
}
Expand Down
4 changes: 2 additions & 2 deletions crates/shim/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::ffi::OsStr;
use crate::error::{Error, Result};

/// Flags to be passed from containerd daemon to a shim binary.
/// Reflects https://github.com/containerd/containerd/blob/master/runtime/v2/shim/shim.go#L100
/// Reflects <https://github.com/containerd/containerd/blob/master/runtime/v2/shim/shim.go#L100>
#[derive(Debug, Default)]
pub struct Flags {
/// Enable debug output in logs.
Expand All @@ -37,7 +37,7 @@ pub struct Flags {
/// Path to publish binary (used for publishing events).
pub publish_binary: String,
/// Shim action (start / delete).
/// See https://github.com/containerd/containerd/blob/master/runtime/v2/shim/shim.go#L191
/// See <https://github.com/containerd/containerd/blob/master/runtime/v2/shim/shim.go#L191>
pub action: String,
}

Expand Down
6 changes: 3 additions & 3 deletions crates/shim/src/asynchronous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use crate::{
error::{Error, Result},
logger, parse_sockaddr, reap, socket_address,
util::{asyncify, read_file_to_str, write_str_to_file},
Config, StartOpts, SOCKET_FD, TTRPC_ADDRESS,
Config, Flags, StartOpts, SOCKET_FD, TTRPC_ADDRESS,
};

pub mod monitor;
Expand All @@ -77,7 +77,7 @@ pub trait Shim {
/// - `id`: identifier of the shim/container, passed in from Containerd.
/// - `namespace`: namespace of the shim/container, passed in from Containerd.
/// - `config`: for the shim to pass back configuration information
async fn new(runtime_id: &str, id: &str, namespace: &str, config: &mut Config) -> Self;
async fn new(runtime_id: &str, args: &Flags, config: &mut Config) -> Self;

/// Start shim will be called by containerd when launching new shim instance.
///
Expand Down Expand Up @@ -128,7 +128,7 @@ where
reap::set_subreaper()?;
}

let mut shim = T::new(runtime_id, &flags.id, &flags.namespace, &mut config).await;
let mut shim = T::new(runtime_id, &flags, &mut config).await;

match flags.action.as_str() {
"start" => {
Expand Down
1 change: 1 addition & 0 deletions crates/shim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub use crate::synchronous::*;
pub mod error;

mod args;
pub use args::Flags;
#[cfg(feature = "async")]
pub mod asynchronous;
pub mod cgroup;
Expand Down
10 changes: 5 additions & 5 deletions crates/shim/src/synchronous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ use util::{read_address, write_address};

use crate::{
api::DeleteResponse,
args, logger,
args::{self, Flags},
logger,
protos::{
protobuf::Message,
shim::shim_ttrpc::{create_task, Task},
Expand Down Expand Up @@ -159,10 +160,9 @@ pub trait Shim {
///
/// # Arguments
/// - `runtime_id`: identifier of the container runtime.
/// - `id`: identifier of the shim/container, passed in from Containerd.
/// - `namespace`: namespace of the shim/container, passed in from Containerd.
/// - `args`: command line arguments passed to the shim which includes namespace and id
/// - `config`: for the shim to pass back configuration information
fn new(runtime_id: &str, id: &str, namespace: &str, config: &mut Config) -> Self;
fn new(runtime_id: &str, args: &Flags, config: &mut Config) -> Self;

/// Start shim will be called by containerd when launching new shim instance.
///
Expand Down Expand Up @@ -213,7 +213,7 @@ where
reap::set_subreaper()?;
}

let mut shim = T::new(runtime_id, &flags.id, &flags.namespace, &mut config);
let mut shim = T::new(runtime_id, &flags, &mut config);

match flags.action.as_str() {
"start" => {
Expand Down