Skip to content

Commit 60558b7

Browse files
committed
Pass all commandline arguments through
Because the second invocation of the shim doesn't have the containerd pipe passed to it, a shim that wants to communicate over the pipe needs to parse the arguments its own. This makes it so the library pass all the arguments, which has already parsed the arguments allowing shims to use the containerd address. Signed-off-by: James Sturtevant <[email protected]>
1 parent d7ee750 commit 60558b7

File tree

8 files changed

+23
-22
lines changed

8 files changed

+23
-22
lines changed

crates/runc-shim/src/asynchronous/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use containerd_shim::{
3131
util::{
3232
convert_to_timestamp, read_options, read_runtime, read_spec, timestamp, write_str_to_file,
3333
},
34-
Config, Context, DeleteResponse, Error, StartOpts,
34+
Config, Context, DeleteResponse, Error, Flags, StartOpts,
3535
};
3636
use log::{debug, error, warn};
3737
use tokio::sync::mpsc::{channel, Receiver, Sender};
@@ -61,13 +61,13 @@ pub(crate) struct Service {
6161
impl Shim for Service {
6262
type T = TaskService<RuncFactory, RuncContainer>;
6363

64-
async fn new(_runtime_id: &str, id: &str, namespace: &str, _config: &mut Config) -> Self {
64+
async fn new(_runtime_id: &str, args: &Flags, _config: &mut Config) -> Self {
6565
let exit = Arc::new(ExitSignal::default());
6666
// TODO: add publisher
6767
Service {
6868
exit,
69-
id: id.to_string(),
70-
namespace: namespace.to_string(),
69+
id: args.id.to_string(),
70+
namespace: args.namespace.to_string(),
7171
}
7272
}
7373

crates/runc-shim/src/synchronous/service.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use shim::{
4040
convert_to_timestamp, read_options, read_runtime, read_spec_from_file, timestamp,
4141
write_address,
4242
},
43-
warn, Config, Context, ExitSignal, Shim, StartOpts,
43+
warn, Config, Context, ExitSignal, Flags, Shim, StartOpts,
4444
};
4545

4646
use crate::{
@@ -56,11 +56,11 @@ use crate::{
5656
impl Shim for Service {
5757
type T = ShimTask<RuncFactory, RuncContainer>;
5858

59-
fn new(_runtime_id: &str, id: &str, namespace: &str, _config: &mut Config) -> Self {
59+
fn new(_runtime_id: &str, args: &Flags, _config: &mut Config) -> Self {
6060
Service {
6161
exit: Arc::new(ExitSignal::default()),
62-
id: id.to_string(),
63-
namespace: namespace.to_string(),
62+
id: args.id.to_string(),
63+
namespace: args.namespace.to_string(),
6464
}
6565
}
6666

crates/shim/examples/skeleton.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mod skeleton {
2323
use containerd_shim as shim;
2424
use log::info;
2525
use shim::{
26-
api, synchronous::publisher::RemotePublisher, Config, DeleteResponse, ExitSignal,
26+
api, synchronous::publisher::RemotePublisher, Config, DeleteResponse, ExitSignal, Flags,
2727
TtrpcContext, TtrpcResult,
2828
};
2929

@@ -35,7 +35,7 @@ mod skeleton {
3535
impl shim::Shim for Service {
3636
type T = Service;
3737

38-
fn new(_runtime_id: &str, _id: &str, _namespace: &str, _config: &mut Config) -> Self {
38+
fn new(_runtime_id: &str, _args: &Flags, _config: &mut Config) -> Self {
3939
Service {
4040
exit: Arc::new(ExitSignal::default()),
4141
}

crates/shim/examples/skeleton_async.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use async_trait::async_trait;
2020
use containerd_shim::{
2121
asynchronous::{run, spawn, ExitSignal, Shim},
2222
publisher::RemotePublisher,
23-
Config, Error, StartOpts, TtrpcResult,
23+
Config, Error, Flags, StartOpts, TtrpcResult,
2424
};
2525
use containerd_shim_protos::{
2626
api, api::DeleteResponse, shim_async::Task, ttrpc::r#async::TtrpcContext,
@@ -36,7 +36,7 @@ struct Service {
3636
impl Shim for Service {
3737
type T = Service;
3838

39-
async fn new(_runtime_id: &str, _id: &str, _namespace: &str, _config: &mut Config) -> Self {
39+
async fn new(_runtime_id: &str, _args: &Flags, _config: &mut Config) -> Self {
4040
Service {
4141
exit: Arc::new(ExitSignal::default()),
4242
}

crates/shim/src/args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::ffi::OsStr;
1919
use crate::error::{Error, Result};
2020

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

crates/shim/src/asynchronous/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use crate::{
5555
error::{Error, Result},
5656
logger, parse_sockaddr, reap, socket_address,
5757
util::{asyncify, read_file_to_str, write_str_to_file},
58-
Config, StartOpts, SOCKET_FD, TTRPC_ADDRESS,
58+
Config, Flags, StartOpts, SOCKET_FD, TTRPC_ADDRESS,
5959
};
6060

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

8282
/// Start shim will be called by containerd when launching new shim instance.
8383
///
@@ -128,7 +128,7 @@ where
128128
reap::set_subreaper()?;
129129
}
130130

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

133133
match flags.action.as_str() {
134134
"start" => {

crates/shim/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub use crate::synchronous::*;
6565
pub mod error;
6666

6767
mod args;
68+
pub use args::Flags;
6869
#[cfg(feature = "async")]
6970
pub mod asynchronous;
7071
pub mod cgroup;

crates/shim/src/synchronous/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ use util::{read_address, write_address};
6262

6363
use crate::{
6464
api::DeleteResponse,
65-
args, logger,
65+
args::{self, Flags},
66+
logger,
6667
protos::{
6768
protobuf::Message,
6869
shim::shim_ttrpc::{create_task, Task},
@@ -159,10 +160,9 @@ pub trait Shim {
159160
///
160161
/// # Arguments
161162
/// - `runtime_id`: identifier of the container runtime.
162-
/// - `id`: identifier of the shim/container, passed in from Containerd.
163-
/// - `namespace`: namespace of the shim/container, passed in from Containerd.
163+
/// - `args`: command line arguments passed to the shim which includes namespace and id
164164
/// - `config`: for the shim to pass back configuration information
165-
fn new(runtime_id: &str, id: &str, namespace: &str, config: &mut Config) -> Self;
165+
fn new(runtime_id: &str, args: &Flags, config: &mut Config) -> Self;
166166

167167
/// Start shim will be called by containerd when launching new shim instance.
168168
///
@@ -213,7 +213,7 @@ where
213213
reap::set_subreaper()?;
214214
}
215215

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

218218
match flags.action.as_str() {
219219
"start" => {

0 commit comments

Comments
 (0)