Skip to content

Commit

Permalink
Merge pull request #85 from containers/podman-v5.1.0
Browse files Browse the repository at this point in the history
Podman v5.1.0
  • Loading branch information
k9withabone authored Jun 2, 2024
2 parents 1e61995 + 7de3547 commit 70c87c4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/cli/container/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl From<compose_spec::Service> for Service {
environment,
expose,
annotations,
group_add,
healthcheck,
hostname,
init,
Expand Down Expand Up @@ -193,7 +194,6 @@ impl From<compose_spec::Service> for Service {
cgroup_parent,
device_cgroup_rules,
extra_hosts,
group_add,
ipc,
uts,
log_options,
Expand Down Expand Up @@ -319,6 +319,7 @@ pub struct Quadlet {
pub environment: ListOrMap,
pub expose: IndexSet<Expose>,
pub annotations: ListOrMap,
pub group_add: IndexSet<UserOrGroup>,
pub healthcheck: Option<Healthcheck>,
pub hostname: Option<Hostname>,
pub init: bool,
Expand Down Expand Up @@ -356,7 +357,6 @@ pub struct PodmanArgs {
pub cgroup_parent: Option<String>,
pub device_cgroup_rules: IndexSet<CgroupRule>,
pub extra_hosts: IndexMap<Hostname, IpAddr>,
pub group_add: IndexSet<UserOrGroup>,
pub ipc: Option<Ipc>,
pub uts: Option<Uts>,
pub log_options: IndexMap<MapKey, Option<StringOrNumber>>,
Expand Down
8 changes: 0 additions & 8 deletions src/cli/container/podman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,6 @@ pub struct PodmanArgs {
#[arg(long, value_name = "ENTRY")]
gpus: Vec<String>,

/// Assign additional groups to the primary user running within the container process
///
/// Can be specified multiple times
#[arg(long, value_name = "GROUP")]
group_add: Vec<String>,

/// Customize the entry that is written to the /etc/group file within the container
#[arg(long, value_name = "ENTRY")]
group_entry: Option<String>,
Expand Down Expand Up @@ -458,7 +452,6 @@ impl TryFrom<compose::PodmanArgs> for PodmanArgs {
cgroup_parent,
device_cgroup_rules,
extra_hosts,
group_add,
ipc,
uts,
log_options,
Expand Down Expand Up @@ -526,7 +519,6 @@ impl TryFrom<compose::PodmanArgs> for PodmanArgs {
.into_iter()
.map(|(host, ip)| format!("{host}:{ip}"))
.collect(),
group_add: group_add.into_iter().map(Into::into).collect(),
ipc: ipc
.map(validate_ipc)
.transpose()
Expand Down
12 changes: 12 additions & 0 deletions src/cli/container/quadlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ pub struct QuadletOptions {
#[arg(long, value_name = "[FLAGS]CONTAINER_GID:FROM_GID[:AMOUNT]")]
gidmap: Vec<String>,

/// Assign additional groups to the primary user running within the container process
///
/// Converts to "GroupAdd=GROUP"
///
/// Can be specified multiple times
#[arg(long, value_name = "GROUP")]
group_add: Vec<String>,

/// Set or alter a healthcheck command for the container
///
/// Converts to "HealthCmd=COMMAND"
Expand Down Expand Up @@ -465,6 +473,7 @@ impl From<QuadletOptions> for crate::quadlet::Container {
env_host: environment_host,
expose: expose_host_port,
gidmap: gid_map,
group_add,
health_cmd,
health_interval,
health_on_failure,
Expand Down Expand Up @@ -535,6 +544,7 @@ impl From<QuadletOptions> for crate::quadlet::Container {
expose_host_port,
gid_map,
group,
group_add,
health_cmd,
health_interval,
health_on_failure,
Expand Down Expand Up @@ -598,6 +608,7 @@ impl TryFrom<compose::Quadlet> for QuadletOptions {
environment,
expose,
annotations,
group_add,
healthcheck,
hostname,
init,
Expand Down Expand Up @@ -681,6 +692,7 @@ impl TryFrom<compose::Quadlet> for QuadletOptions {
env: environment.into_list().into_iter().collect(),
expose: expose.iter().map(ToString::to_string).collect(),
annotation: annotations.into_list().into_iter().collect(),
group_add: group_add.into_iter().map(Into::into).collect(),
health_cmd,
health_interval,
health_timeout,
Expand Down
9 changes: 7 additions & 2 deletions src/quadlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,17 @@ pub enum PodmanVersion {
V4_8,

/// Podman v5.0
#[value(name = "5.0", aliases = ["latest", "5.0.0", "5.0.1", "5.0.2", "5.0.3"])]
#[value(name = "5.0", aliases = ["5.0.0", "5.0.1", "5.0.2", "5.0.3"])]
V5_0,

/// Podman v5.1
#[value(name = "5.1", aliases = ["latest", "5.1.0"])]
V5_1,
}

impl PodmanVersion {
/// Latest supported version of Podman with regards to Quadlet.
pub const LATEST: Self = Self::V5_0;
pub const LATEST: Self = Self::V5_1;

/// Podman version as a static string slice.
pub const fn as_str(self) -> &'static str {
Expand All @@ -330,6 +334,7 @@ impl PodmanVersion {
Self::V4_7 => "4.7",
Self::V4_8 => "4.8",
Self::V5_0 => "5.0",
Self::V5_1 => "5.1",
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/quadlet/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ pub struct Container {
/// The (numeric) GID to run as inside the container.
pub group: Option<String>,

/// Assign additional groups to the primary user running within the container process.
pub group_add: Vec<String>,

/// Set or alter a healthcheck command for a container.
pub health_cmd: Option<String>,

Expand Down Expand Up @@ -305,6 +308,10 @@ impl Display for Container {

impl Downgrade for Container {
fn downgrade(&mut self, version: PodmanVersion) -> Result<(), DowngradeError> {
if version < PodmanVersion::V5_1 {
self.remove_v5_1_options();
}

if version < PodmanVersion::V5_0 {
if self.notify.is_healthy() {
if version < PodmanVersion::V4_7 {
Expand Down Expand Up @@ -359,6 +366,14 @@ macro_rules! extract {
}

impl Container {
/// Remove Quadlet options added in Podman v5.1.0
fn remove_v5_1_options(&mut self) {
let options = extract!(self, OptionsV5_1 { group_add });

self.push_args(options)
.expect("OptionsV5_1 serializable as args");
}

/// Remove Quadlet options added in Podman v5.0.0
fn remove_v5_0_options(&mut self) {
let options = extract!(
Expand Down Expand Up @@ -502,6 +517,13 @@ impl Container {
}
}

/// Container Quadlet options added in Podman v5.1.0
#[derive(Serialize, Debug)]
#[serde(rename_all = "kebab-case")]
struct OptionsV5_1 {
group_add: Vec<String>,
}

/// Container Quadlet options added in Podman v5.0.0
#[derive(Serialize, Debug)]
#[serde(rename_all = "kebab-case")]
Expand Down
10 changes: 8 additions & 2 deletions src/quadlet/container/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ pub struct Image {
skip_serializing_if = "Not::not"
)]
pub read_write: bool,

/// Mount only a specific path within the image, instead of the whole image.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub subpath: Option<PathBuf>,
}

/// Volume type [`Mount`].
Expand Down Expand Up @@ -512,14 +516,16 @@ mod tests {

#[test]
fn image() {
let string = "type=image,source=fedora,destination=/fedora-image,readwrite=true";
let string =
"type=image,source=fedora,destination=/fedora-image,readwrite=true,subpath=path";
let mount: Mount = string.parse().unwrap();
assert_eq!(
mount,
Mount::Image(Image {
source: "fedora".into(),
destination: "/fedora-image".into(),
read_write: true
read_write: true,
subpath: Some("path".into()),
}),
);
assert_eq!(mount.to_string(), string);
Expand Down

0 comments on commit 70c87c4

Please sign in to comment.