use std::fmt;
use bollard::models::HostConfig;
use crate::config;
pub trait Isolation: Send + Sync + fmt::Debug {
fn name(&self) -> &'static str;
fn is_unsafe(&self) -> bool;
fn configure(&self, host_config: &mut HostConfig);
}
#[derive(Debug)]
pub struct Sysbox;
impl Isolation for Sysbox {
fn name(&self) -> &'static str {
"sysbox"
}
fn is_unsafe(&self) -> bool {
false
}
fn configure(&self, host_config: &mut HostConfig) {
host_config.runtime = Some("sysbox-runc".to_owned());
host_config.privileged = Some(false);
}
}
#[derive(Debug)]
pub struct UnsafeDind;
impl Isolation for UnsafeDind {
fn name(&self) -> &'static str {
"unsafe-dind"
}
fn is_unsafe(&self) -> bool {
true
}
fn configure(&self, host_config: &mut HostConfig) {
host_config.runtime = Some("runc".to_owned());
host_config.privileged = Some(true);
}
}
pub fn backend(isolation: config::Isolation) -> &'static dyn Isolation {
match isolation {
config::Isolation::Sysbox => &Sysbox,
config::Isolation::UnsafeDind => &UnsafeDind,
}
}
#[cfg(test)]
mod tests;