1
0
Fork 0
mirror of https://github.com/containers/youki synced 2024-05-25 17:06:09 +02:00

Remove user_ns param completely

Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com>
This commit is contained in:
Yashodhan Joshi 2024-03-04 15:32:47 +05:30
parent 70950f9d32
commit b90b124c62
5 changed files with 10 additions and 24 deletions

View File

@ -47,7 +47,7 @@ pub struct YoukiConfig {
}
impl<'a> YoukiConfig {
pub fn from_spec(spec: &'a Spec, container_id: &str, new_user_ns: bool) -> Result<Self> {
pub fn from_spec(spec: &'a Spec, container_id: &str) -> Result<Self> {
Ok(YoukiConfig {
hooks: spec.hooks().clone(),
cgroup_path: utils::get_cgroup_path(
@ -56,7 +56,6 @@ impl<'a> YoukiConfig {
.ok_or(ConfigError::MissingLinux)?
.cgroups_path(),
container_id,
new_user_ns,
),
})
}
@ -106,7 +105,7 @@ mod tests {
fn test_config_from_spec() -> Result<()> {
let container_id = "sample";
let spec = Spec::default();
let config = YoukiConfig::from_spec(&spec, container_id, false)?;
let config = YoukiConfig::from_spec(&spec, container_id)?;
assert_eq!(&config.hooks, spec.hooks());
dbg!(&config.cgroup_path);
assert_eq!(
@ -121,7 +120,7 @@ mod tests {
let container_id = "sample";
let tmp = tempfile::tempdir().expect("create temp dir");
let spec = Spec::default();
let config = YoukiConfig::from_spec(&spec, container_id, false)?;
let config = YoukiConfig::from_spec(&spec, container_id)?;
config.save(&tmp)?;
let act = YoukiConfig::load(&tmp)?;
assert_eq!(act, config);

View File

@ -68,11 +68,7 @@ impl ContainerBuilderImpl {
fn run_container(&mut self) -> Result<Pid, LibcontainerError> {
let linux = self.spec.linux().as_ref().ok_or(MissingSpecError::Linux)?;
let cgroups_path = utils::get_cgroup_path(
linux.cgroups_path(),
&self.container_id,
self.user_ns_config.is_some(),
);
let cgroups_path = utils::get_cgroup_path(linux.cgroups_path(), &self.container_id);
let cgroup_config = libcgroups::common::CgroupConfig {
cgroup_path: cgroups_path,
systemd_cgroup: self.use_systemd || self.user_ns_config.is_some(),
@ -186,11 +182,7 @@ impl ContainerBuilderImpl {
fn cleanup_container(&self) -> Result<(), LibcontainerError> {
let linux = self.spec.linux().as_ref().ok_or(MissingSpecError::Linux)?;
let cgroups_path = utils::get_cgroup_path(
linux.cgroups_path(),
&self.container_id,
self.user_ns_config.is_some(),
);
let cgroups_path = utils::get_cgroup_path(linux.cgroups_path(), &self.container_id);
let cmanager =
libcgroups::common::create_cgroup_manager(libcgroups::common::CgroupConfig {
cgroup_path: cgroups_path,

View File

@ -332,8 +332,7 @@ mod tests {
let tmp_dir = tempfile::tempdir().unwrap();
use oci_spec::runtime::Spec;
let spec = Spec::default();
let config =
YoukiConfig::from_spec(&spec, "123", false).context("convert spec to config")?;
let config = YoukiConfig::from_spec(&spec, "123").context("convert spec to config")?;
config.save(tmp_dir.path()).context("save config")?;
let container = Container {

View File

@ -88,7 +88,7 @@ impl InitContainerBuilder {
let user_ns_config = UserNamespaceConfig::new(&spec)?;
let config = YoukiConfig::from_spec(&spec, container.id(), user_ns_config.is_some())?;
let config = YoukiConfig::from_spec(&spec, container.id())?;
config.save(&container_dir).map_err(|err| {
tracing::error!(?container_dir, "failed to save config: {}", err);
err

View File

@ -147,11 +147,7 @@ pub fn get_user_home(uid: u32) -> Option<PathBuf> {
}
/// If None, it will generate a default path for cgroups.
pub fn get_cgroup_path(
cgroups_path: &Option<PathBuf>,
container_id: &str,
new_user_ns: bool,
) -> PathBuf {
pub fn get_cgroup_path(cgroups_path: &Option<PathBuf>, container_id: &str) -> PathBuf {
match cgroups_path {
Some(cpath) => cpath.clone(),
None => PathBuf::from(format!(":youki:{container_id}")),
@ -320,11 +316,11 @@ mod tests {
fn test_get_cgroup_path() {
let cid = "sample_container_id";
assert_eq!(
get_cgroup_path(&None, cid, false),
get_cgroup_path(&None, cid),
PathBuf::from(":youki:sample_container_id")
);
assert_eq!(
get_cgroup_path(&Some(PathBuf::from("/youki")), cid, false),
get_cgroup_path(&Some(PathBuf::from("/youki")), cid),
PathBuf::from("/youki")
);
}