diff --git a/src/cli/container/podman.rs b/src/cli/container/podman.rs index 5f421ef..0f45a1a 100644 --- a/src/cli/container/podman.rs +++ b/src/cli/container/podman.rs @@ -388,12 +388,6 @@ pub struct PodmanArgs { #[arg(long, value_name = "NAME")] subuidname: Option, - /// Configure namespaced kernel parameters at runtime - /// - /// Can be specified multiple times - #[arg(long, value_name = "NAME=VALUE")] - sysctl: Vec, - /// Run container in systemd mode /// /// Default is true @@ -532,7 +526,6 @@ impl Default for PodmanArgs { stop_timeout: None, subgidname: None, subuidname: None, - sysctl: Vec::new(), systemd: None, timeout: None, tls_verify: None, @@ -623,7 +616,6 @@ impl PodmanArgs { + self.stop_timeout.iter().len() + self.subgidname.iter().len() + self.subuidname.iter().len() - + self.sysctl.len() + self.systemd.iter().len() + self.timeout.iter().len() + self.tls_verify.iter().len() @@ -874,8 +866,6 @@ impl Display for PodmanArgs { extend_args(&mut args, "--subuidname", &self.subuidname); - extend_args(&mut args, "--sysctl", &self.sysctl); - extend_args(&mut args, "--systemd", &self.systemd); let timeout = self.timeout.map(|timeout| timeout.to_string()); @@ -960,19 +950,6 @@ impl TryFrom<&mut docker_compose_types::Service> for PodmanArgs { .map(|(key, value)| format!("{key}={value}")) .collect(); - let sysctl = match mem::take(&mut value.sysctls) { - docker_compose_types::SysCtls::List(vec) => vec, - docker_compose_types::SysCtls::Map(map) => map - .into_iter() - .map(|(key, value)| { - let value = value - .as_ref() - .map_or_else(|| String::from("null"), ToString::to_string); - format!("{key}={value}") - }) - .collect(), - }; - Ok(Self { hostname: value.hostname.take(), privileged: value.privileged, @@ -989,7 +966,6 @@ impl TryFrom<&mut docker_compose_types::Service> for PodmanArgs { log_opt, add_host: mem::take(&mut value.extra_hosts), tty: value.tty, - sysctl, ..Self::default() }) } diff --git a/src/cli/container/quadlet.rs b/src/cli/container/quadlet.rs index 533b4a6..cc5c3fc 100644 --- a/src/cli/container/quadlet.rs +++ b/src/cli/container/quadlet.rs @@ -237,6 +237,14 @@ pub struct QuadletOptions { #[arg(long, value_name = "SECRET[,OPT=OPT,...]")] secret: Vec, + /// Configures namespaced kernel parameters for the container. + /// + /// Converts to "Sysctl=NAME=VALUE" + /// + /// Can be specified multiple times + #[arg(long, value_name = "NAME=VALUE")] + sysctl: Vec, + /// Create a tmpfs mount /// /// Converts to "Tmpfs=FS" or, if FS == /tmp, "VolatileTmp=true" @@ -348,6 +356,7 @@ impl From for crate::quadlet::Container { read_only: value.read_only, run_init: value.init, secret: value.secret, + sysctl: value.sysctl, tmpfs, timezone: value.tz, user, @@ -370,6 +379,7 @@ impl TryFrom for QuadletOptions { impl TryFrom<&mut ComposeService> for QuadletOptions { type Error = color_eyre::Report; + #[allow(clippy::too_many_lines)] fn try_from(value: &mut ComposeService) -> Result { let service = &mut value.service; @@ -420,6 +430,20 @@ impl TryFrom<&mut ComposeService> for QuadletOptions { .collect(), }; + let sysctl = match mem::take(&mut service.sysctls) { + docker_compose_types::SysCtls::List(vec) => vec, + docker_compose_types::SysCtls::Map(map) => map + .into_iter() + .map(|(key, value)| { + if let Some(value) = value { + format!("{key}={value}") + } else { + key + "=null" + } + }) + .collect(), + }; + let mut tmpfs = service .tmpfs .take() @@ -461,6 +485,7 @@ impl TryFrom<&mut ComposeService> for QuadletOptions { health_retries, health_start_period, health_timeout, + sysctl, tmpfs, mount, user: service.user.take(), diff --git a/src/quadlet/container.rs b/src/quadlet/container.rs index 6f9875e..3c97f4d 100644 --- a/src/quadlet/container.rs +++ b/src/quadlet/container.rs @@ -51,6 +51,7 @@ pub struct Container { pub security_label_level: Option, pub security_label_type: Option, pub secret: Vec, + pub sysctl: Vec, pub tmpfs: Vec, pub timezone: Option, pub user: Option, @@ -222,6 +223,10 @@ impl Display for Container { writeln!(f, "Secret={secret}")?; } + if !self.sysctl.is_empty() { + writeln_escape_spaces(f, "Sysctl", &self.sysctl)?; + } + for tmpfs in &self.tmpfs { writeln!(f, "Tmpfs={tmpfs}")?; }