Skip to content

Commit

Permalink
Add get_mut for fields of spec/runtime
Browse files Browse the repository at this point in the history
Fixes #165

Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
  • Loading branch information
Apokleos committed May 24, 2024
1 parent 4cf1c3d commit 54d83eb
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 51 deletions.
25 changes: 18 additions & 7 deletions src/runtime/hooks.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
use crate::error::OciSpecError;
use derive_builder::Builder;
use getset::{CopyGetters, Getters, Setters};
use getset::{CopyGetters, Getters, MutGetters, Setters};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

#[derive(
Builder, Clone, Debug, Default, Deserialize, Eq, Getters, Setters, PartialEq, Serialize,
Builder,
Clone,
Debug,
Default,
Deserialize,
Eq,
MutGetters,
Getters,
Setters,
PartialEq,
Serialize,
)]
#[serde(rename_all = "camelCase")]
#[builder(
Expand All @@ -14,7 +24,7 @@ use std::path::PathBuf;
setter(into, strip_option),
build_fn(error = "OciSpecError")
)]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Hooks specifies a command that is run in the container at a particular
/// event in the lifecycle (setup and teardown) of a container.
pub struct Hooks {
Expand Down Expand Up @@ -75,6 +85,7 @@ pub struct Hooks {
Deserialize,
Eq,
Getters,
MutGetters,
Setters,
PartialEq,
Serialize,
Expand All @@ -88,28 +99,28 @@ pub struct Hooks {
/// Hook specifies a command that is run at a particular event in the
/// lifecycle of a container.
pub struct Hook {
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Path to the binary to be executed. Following similar semantics to
/// [IEEE Std 1003.1-2008 `execv`'s path](https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html). This
/// specification extends the IEEE standard in that path MUST be
/// absolute.
path: PathBuf,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Arguments used for the binary, including the binary name itself.
/// Following the same semantics as [IEEE Std 1003.1-2008
/// `execv`'s argv](https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html).
args: Option<Vec<String>>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Additional `key=value` environment variables. Following the same
/// semantics as [IEEE Std 1003.1-2008's `environ`](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_01).
env: Option<Vec<String>>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get_copy = "pub", set = "pub")]
#[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
/// Timeout is the number of seconds before aborting the hook. If set,
/// timeout MUST be greater than zero.
timeout: Option<i64>,
Expand Down
81 changes: 53 additions & 28 deletions src/runtime/linux.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
use crate::error::{oci_error, OciSpecError};

use derive_builder::Builder;
use getset::{CopyGetters, Getters, Setters};
use getset::{CopyGetters, Getters, MutGetters, Setters};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, path::PathBuf, vec};

#[derive(Builder, Clone, Debug, Deserialize, Eq, Getters, Setters, PartialEq, Serialize)]
#[derive(
Builder, Clone, Debug, Deserialize, Eq, Getters, MutGetters, Setters, PartialEq, Serialize,
)]
#[serde(rename_all = "camelCase")]
#[builder(
default,
pattern = "owned",
setter(into, strip_option),
build_fn(error = "OciSpecError")
)]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Linux contains platform-specific configuration for Linux based
/// containers.
pub struct Linux {
Expand Down Expand Up @@ -240,6 +242,7 @@ impl LinuxDeviceType {
Deserialize,
Eq,
Getters,
MutGetters,
Setters,
PartialEq,
Serialize,
Expand All @@ -254,28 +257,28 @@ impl LinuxDeviceType {
/// controller
pub struct LinuxDeviceCgroup {
#[serde(default)]
#[getset(get_copy = "pub", set = "pub")]
#[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
/// Allow or deny
allow: bool,

#[serde(default, rename = "type", skip_serializing_if = "Option::is_none")]
#[getset(get_copy = "pub", set = "pub")]
#[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
/// Device type, block, char, etc.
typ: Option<LinuxDeviceType>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get_copy = "pub", set = "pub")]
#[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
/// Device's major number
major: Option<i64>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get_copy = "pub", set = "pub")]
#[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
/// Device's minor number
minor: Option<i64>,

/// Cgroup access premissions format, rwm.
#[serde(default)]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
access: Option<String>,
}

Expand Down Expand Up @@ -688,6 +691,7 @@ pub struct LinuxNetwork {
Deserialize,
Eq,
Getters,
MutGetters,
Setters,
PartialEq,
Serialize,
Expand All @@ -702,55 +706,65 @@ pub struct LinuxNetwork {
/// Resource constraints for container
pub struct LinuxResources {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Devices configures the device allowlist.
devices: Option<Vec<LinuxDeviceCgroup>>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Memory restriction configuration.
memory: Option<LinuxMemory>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// CPU resource restriction configuration.
cpu: Option<LinuxCpu>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Task resource restrictions
pids: Option<LinuxPids>,

#[serde(default, skip_serializing_if = "Option::is_none", rename = "blockIO")]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// BlockIO restriction configuration.
block_io: Option<LinuxBlockIo>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Hugetlb limit (in bytes).
hugepage_limits: Option<Vec<LinuxHugepageLimit>>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Network restriction configuration.
network: Option<LinuxNetwork>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Rdma resource restriction configuration. Limits are a set of key
/// value pairs that define RDMA resource limits, where the key
/// is device name and value is resource limits.
rdma: Option<HashMap<String, LinuxRdma>>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Unified resources.
unified: Option<HashMap<String, String>>,
}

#[derive(
Builder, Clone, Copy, CopyGetters, Debug, Default, Deserialize, Eq, PartialEq, Serialize,
Builder,
Clone,
Copy,
CopyGetters,
Debug,
Default,
Deserialize,
Eq,
MutGetters,
PartialEq,
Serialize,
)]
#[serde(rename_all = "camelCase")]
#[builder(
Expand All @@ -759,7 +773,7 @@ pub struct LinuxResources {
setter(into, strip_option),
build_fn(error = "OciSpecError")
)]
#[getset(get_copy = "pub", set = "pub")]
#[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
/// LinuxRdma for Linux cgroup 'rdma' resource management (Linux 4.11).
pub struct LinuxRdma {
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -900,6 +914,7 @@ pub fn get_default_namespaces() -> Vec<LinuxNamespace> {
Deserialize,
Eq,
Getters,
MutGetters,
Setters,
PartialEq,
Serialize,
Expand All @@ -915,37 +930,37 @@ pub fn get_default_namespaces() -> Vec<LinuxNamespace> {
/// file.
pub struct LinuxDevice {
#[serde(default)]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Path to the device.
path: PathBuf,

#[serde(rename = "type")]
#[getset(get_copy = "pub", set = "pub")]
#[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
/// Device type, block, char, etc..
typ: LinuxDeviceType,

#[serde(default)]
#[getset(get_copy = "pub", set = "pub")]
#[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
/// Major is the device's major number.
major: i64,

#[serde(default)]
#[getset(get_copy = "pub", set = "pub")]
#[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
/// Minor is the device's minor number.
minor: i64,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get_copy = "pub", set = "pub")]
#[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
/// FileMode permission bits for the device.
file_mode: Option<u32>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get_copy = "pub", set = "pub")]
#[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
/// UID of the device.
uid: Option<u32>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[getset(get_copy = "pub", set = "pub")]
#[getset(get_mut = "pub", get_copy = "pub", set = "pub")]
/// Gid of the device.
gid: Option<u32>,
}
Expand Down Expand Up @@ -1271,7 +1286,17 @@ pub fn get_default_readonly_paths() -> Vec<String> {
}

#[derive(
Builder, Clone, Debug, Default, Deserialize, Eq, Getters, Setters, PartialEq, Serialize,
Builder,
Clone,
Debug,
Default,
Deserialize,
Eq,
Getters,
MutGetters,
Setters,
PartialEq,
Serialize,
)]
#[serde(rename_all = "camelCase")]
#[builder(
Expand All @@ -1280,7 +1305,7 @@ pub fn get_default_readonly_paths() -> Vec<String> {
setter(into, strip_option),
build_fn(error = "OciSpecError")
)]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// LinuxIntelRdt has container runtime resource constraints for Intel RDT CAT and MBA
/// features and flags enabling Intel RDT CMT and MBM features.
/// Intel RDT features are available in Linux 4.14 and newer kernel versions.
Expand Down
16 changes: 13 additions & 3 deletions src/runtime/miscellaneous.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::OciSpecError;
use derive_builder::Builder;
use getset::{CopyGetters, Getters, Setters};
use getset::{CopyGetters, Getters, MutGetters, Setters};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

Expand Down Expand Up @@ -40,15 +40,25 @@ impl Default for Root {
}

#[derive(
Builder, Clone, Debug, Default, Deserialize, Eq, Getters, Setters, PartialEq, Serialize,
Builder,
Clone,
Debug,
Default,
Deserialize,
Eq,
Getters,
MutGetters,
Setters,
PartialEq,
Serialize,
)]
#[builder(
default,
pattern = "owned",
setter(into, strip_option),
build_fn(error = "OciSpecError")
)]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
/// Mount specifies a mount for a container.
pub struct Mount {
/// Destination is the absolute path where the mount will be placed in
Expand Down
8 changes: 5 additions & 3 deletions src/runtime/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! [OCI runtime spec](https://github.com/opencontainers/runtime-spec) types and definitions.

use derive_builder::Builder;
use getset::{Getters, Setters};
use getset::{Getters, MutGetters, Setters};
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
Expand Down Expand Up @@ -35,15 +35,17 @@ pub use vm::*;
pub use windows::*;

/// Base configuration for the container.
#[derive(Builder, Clone, Debug, Deserialize, Getters, Setters, PartialEq, Eq, Serialize)]
#[derive(
Builder, Clone, Debug, Deserialize, Getters, MutGetters, Setters, PartialEq, Eq, Serialize,
)]
#[serde(rename_all = "camelCase")]
#[builder(
default,
pattern = "owned",
setter(into, strip_option),
build_fn(error = "OciSpecError")
)]
#[getset(get = "pub", set = "pub")]
#[getset(get_mut = "pub", get = "pub", set = "pub")]
pub struct Spec {
#[serde(default, rename = "ociVersion")]
/// MUST be in SemVer v2.0.0 format and specifies the version of the
Expand Down
Loading

0 comments on commit 54d83eb

Please sign in to comment.