Skip to content

Commit 80ee5af

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 5c96c0f commit 80ee5af

File tree

8 files changed

+23
-22
lines changed

8 files changed

+23
-22
lines changed

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub use crate::synchronous::*;
5757
pub mod error;
5858

5959
mod args;
60+
pub use args::Flags;
6061
#[cfg(feature = "async")]
6162
pub mod asynchronous;
6263
pub mod cgroup;

crates/shim/src/synchronous/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ use util::{read_address, write_address};
5858

5959
use crate::{
6060
api::DeleteResponse,
61-
args, logger, parse_sockaddr,
61+
args::{self, Flags},
62+
logger, parse_sockaddr,
6263
protos::{
6364
protobuf::Message,
6465
shim::shim_ttrpc::{create_task, Task},
@@ -111,10 +112,9 @@ pub trait Shim {
111112
///
112113
/// # Arguments
113114
/// - `runtime_id`: identifier of the container runtime.
114-
/// - `id`: identifier of the shim/container, passed in from Containerd.
115-
/// - `namespace`: namespace of the shim/container, passed in from Containerd.
115+
/// - `args`: command line arguments passed to the shim which includes namespace and id
116116
/// - `config`: for the shim to pass back configuration information
117-
fn new(runtime_id: &str, id: &str, namespace: &str, config: &mut Config) -> Self;
117+
fn new(runtime_id: &str, args: &Flags, config: &mut Config) -> Self;
118118

119119
/// Start shim will be called by containerd when launching new shim instance.
120120
///
@@ -165,7 +165,7 @@ where
165165
reap::set_subreaper()?;
166166
}
167167

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

170170
match flags.action.as_str() {
171171
"start" => {

0 commit comments

Comments
 (0)