Move console to runc-shim

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko 2023-03-16 11:16:24 -07:00
parent 115029bb63
commit 33d37c0c0d
14 changed files with 21 additions and 27 deletions

View File

@ -31,6 +31,7 @@ serde = { version = "1.0.133", features = ["derive"] }
serde_json = "1.0.74" serde_json = "1.0.74"
oci-spec = "0.6.0" oci-spec = "0.6.0"
crossbeam = "0.8.1" crossbeam = "0.8.1"
uuid = { version = "1.0.0", features = ["v4"] }
# Async dependencies # Async dependencies
async-trait = { workspace = true, optional = true } async-trait = { workspace = true, optional = true }

View File

@ -16,14 +16,12 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use containerd_shim::{io_error, util::mkdir, Error, Result};
use log::warn; use log::warn;
use tokio::net::{UnixListener, UnixStream}; use tokio::net::{UnixListener, UnixStream};
use uuid::Uuid; use uuid::Uuid;
use crate::{ use crate::common::xdg_runtime_dir;
util::{mkdir, xdg_runtime_dir},
Error, Result,
};
pub struct ConsoleSocket { pub struct ConsoleSocket {
pub listener: UnixListener, pub listener: UnixListener,

View File

@ -42,6 +42,7 @@ use crate::{
common::{create_runc, has_shared_pid_namespace, ShimExecutor, GROUP_LABELS}, common::{create_runc, has_shared_pid_namespace, ShimExecutor, GROUP_LABELS},
}; };
mod console;
mod container; mod container;
mod runc; mod runc;
mod task; mod task;

View File

@ -29,7 +29,6 @@ use async_trait::async_trait;
use containerd_shim::{ use containerd_shim::{
api::{CreateTaskRequest, ExecProcessRequest, Options, Status}, api::{CreateTaskRequest, ExecProcessRequest, Options, Status},
asynchronous::{ asynchronous::{
console::ConsoleSocket,
monitor::{monitor_subscribe, monitor_unsubscribe, Subscription}, monitor::{monitor_subscribe, monitor_unsubscribe, Subscription},
processes::{ProcessLifecycle, ProcessTemplate}, processes::{ProcessLifecycle, ProcessTemplate},
}, },
@ -54,7 +53,10 @@ use tokio::{
io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, BufReader}, io::{AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, BufReader},
}; };
use super::container::{ContainerFactory, ContainerTemplate, ProcessFactory}; use super::{
console::ConsoleSocket,
container::{ContainerFactory, ContainerTemplate, ProcessFactory},
};
use crate::common::{ use crate::common::{
check_kill_error, create_io, create_runc, get_spec_from_request, receive_socket, CreateConfig, check_kill_error, create_io, create_runc, get_spec_from_request, receive_socket, CreateConfig,
Log, ProcessIO, ShimExecutor, INIT_PID_FILE, LOG_JSON_FILE, Log, ProcessIO, ShimExecutor, INIT_PID_FILE, LOG_JSON_FILE,

View File

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
*/ */
use std::{io::IoSliceMut, ops::Deref, os::unix::io::RawFd, path::Path, sync::Arc}; use std::{env, io::IoSliceMut, ops::Deref, os::unix::io::RawFd, path::Path, sync::Arc};
use containerd_shim::{ use containerd_shim::{
api::{ExecProcessRequest, Options}, api::{ExecProcessRequest, Options},
@ -232,3 +232,10 @@ pub fn has_shared_pid_namespace(spec: &Spec) -> bool {
}, },
} }
} }
/// Returns a temp dir. If the environment variable "XDG_RUNTIME_DIR" is set, return its value.
/// Otherwise if `std::env::temp_dir()` failed, return current dir or return the temp dir depended on OS.
pub(crate) fn xdg_runtime_dir() -> String {
env::var("XDG_RUNTIME_DIR")
.unwrap_or_else(|_| env::temp_dir().to_str().unwrap_or(".").to_string())
}

View File

@ -19,13 +19,11 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use containerd_shim::{io_error, util::mkdir, Error, Result};
use log::warn; use log::warn;
use uuid::Uuid; use uuid::Uuid;
use crate::{ use crate::common::xdg_runtime_dir;
util::{mkdir, xdg_runtime_dir},
Error, Result,
};
pub struct ConsoleSocket { pub struct ConsoleSocket {
pub listener: UnixListener, pub listener: UnixListener,

View File

@ -31,7 +31,6 @@ use log::debug;
use oci_spec::runtime::LinuxResources; use oci_spec::runtime::LinuxResources;
use shim::{ use shim::{
api::*, api::*,
console::ConsoleSocket,
error::{Error, Result}, error::{Error, Result},
io::Stdio, io::Stdio,
io_error, ioctl_set_winsz, other, other_error, io_error, ioctl_set_winsz, other, other_error,
@ -41,6 +40,7 @@ use shim::{
}; };
use time::OffsetDateTime; use time::OffsetDateTime;
use super::console::ConsoleSocket;
use crate::{ use crate::{
common::{receive_socket, ProcessIO}, common::{receive_socket, ProcessIO},
synchronous::io::spawn_copy_for_tty, synchronous::io::spawn_copy_for_tty,

View File

@ -18,6 +18,7 @@ use std::sync::Arc;
use containerd_shim::ExitSignal; use containerd_shim::ExitSignal;
mod console;
mod container; mod container;
mod io; mod io;
mod runc; mod runc;

View File

@ -38,7 +38,6 @@ use oci_spec::runtime::LinuxResources;
use runc::{Command, Spawner}; use runc::{Command, Spawner};
use shim::{ use shim::{
api::*, api::*,
console::ConsoleSocket,
error::{Error, Result}, error::{Error, Result},
io::Stdio, io::Stdio,
monitor::{monitor_subscribe, wait_pid, Topic}, monitor::{monitor_subscribe, wait_pid, Topic},
@ -55,6 +54,7 @@ use shim::{
}; };
use time::OffsetDateTime; use time::OffsetDateTime;
use super::console::ConsoleSocket;
use crate::{ use crate::{
common, common,
common::{ common::{

View File

@ -29,7 +29,6 @@ time = { version = "0.3.7", features = ["serde", "std"] }
serde_json = "1.0.78" serde_json = "1.0.78"
serde_derive = "1.0.136" serde_derive = "1.0.136"
serde = "1.0.136" serde = "1.0.136"
uuid = { version = "1.0.0", features = ["v4"] }
signal-hook = "0.3.13" signal-hook = "0.3.13"
oci-spec = "0.6.0" oci-spec = "0.6.0"
prctl = "1.0.0" prctl = "1.0.0"

View File

@ -58,7 +58,6 @@ use crate::{
Config, StartOpts, SOCKET_FD, TTRPC_ADDRESS, Config, StartOpts, SOCKET_FD, TTRPC_ADDRESS,
}; };
pub mod console;
pub mod monitor; pub mod monitor;
pub mod processes; pub mod processes;
pub mod publisher; pub mod publisher;

View File

@ -101,7 +101,6 @@ macro_rules! cfg_async {
cfg_not_async! { cfg_not_async! {
pub use crate::synchronous::*; pub use crate::synchronous::*;
pub use crate::synchronous::console;
pub use crate::synchronous::publisher; pub use crate::synchronous::publisher;
pub use protos::shim::shim_ttrpc::Task; pub use protos::shim::shim_ttrpc::Task;
pub use protos::ttrpc::TtrpcContext; pub use protos::ttrpc::TtrpcContext;
@ -109,7 +108,6 @@ cfg_not_async! {
cfg_async! { cfg_async! {
pub use crate::asynchronous::*; pub use crate::asynchronous::*;
pub use crate::asynchronous::console;
pub use crate::asynchronous::processes; pub use crate::asynchronous::processes;
pub use crate::asynchronous::publisher; pub use crate::asynchronous::publisher;
pub use protos::shim_async::Task; pub use protos::shim_async::Task;

View File

@ -73,8 +73,6 @@ pub mod monitor;
pub mod publisher; pub mod publisher;
pub mod util; pub mod util;
pub mod console;
/// Helper structure that wraps atomic bool to signal shim server when to shutdown the TTRPC server. /// Helper structure that wraps atomic bool to signal shim server when to shutdown the TTRPC server.
/// ///
/// Shim implementations are responsible for calling [`Self::signal`]. /// Shim implementations are responsible for calling [`Self::signal`].

View File

@ -15,7 +15,6 @@
*/ */
use std::{ use std::{
env,
os::unix::io::RawFd, os::unix::io::RawFd,
time::{SystemTime, UNIX_EPOCH}, time::{SystemTime, UNIX_EPOCH},
}; };
@ -166,13 +165,6 @@ pub fn convert_to_any(obj: Box<dyn MessageDyn>) -> Result<Any> {
Ok(any) Ok(any)
} }
/// Returns a temp dir. If the environment variable "XDG_RUNTIME_DIR" is set, return its value.
/// Otherwise if `std::env::temp_dir()` failed, return current dir or return the temp dir depended on OS.
pub(crate) fn xdg_runtime_dir() -> String {
env::var("XDG_RUNTIME_DIR")
.unwrap_or_else(|_| env::temp_dir().to_str().unwrap_or(".").to_string())
}
pub trait IntoOption pub trait IntoOption
where where
Self: Sized, Self: Sized,