Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get oci_spec in seperate crate #42

Merged
merged 2 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ chrono = "0.4"
once_cell = "1.6.0"
futures = { version = "0.3", features = ["thread-pool"] }
regex = "1.5"
oci_spec = { version = "0.1.0", path = "./oci_spec" }
214 changes: 214 additions & 0 deletions oci_spec/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions oci_spec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "oci_spec"
version = "0.1.0"
edition = "2018"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
nix = "0.19.1"
anyhow = "1.0"
serde_json = "1.0"
caps = "0.5.1"

26 changes: 26 additions & 0 deletions src/spec.rs → oci_spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,26 @@ pub struct LinuxDeviceCgroup {
pub access: String,
}

impl ToString for LinuxDeviceCgroup {
fn to_string(&self) -> String {
let major = self
.major
.map(|mj| mj.to_string())
.unwrap_or_else(|| "*".to_string());
let minor = self
.minor
.map(|mi| mi.to_string())
.unwrap_or_else(|| "*".to_string());
format!(
"{} {}:{} {}",
self.typ.as_str(),
&major,
&minor,
&self.access
)
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LinuxMemory {
pub limit: Option<i64>,
Expand Down Expand Up @@ -409,6 +429,12 @@ pub struct LinuxInterfacePriority {
pub priority: u32,
}

impl ToString for LinuxInterfacePriority {
fn to_string(&self) -> String {
format!("{} {}\n", self.name, self.priority)
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LinuxNetwork {
Expand Down
2 changes: 1 addition & 1 deletion src/capabilities.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
command::Command,
spec::{LinuxCapabilities, LinuxCapabilityType},
};
use caps::*;

use anyhow::Result;
use oci_spec::{LinuxCapabilities, LinuxCapabilityType};

fn to_set(caps: &[LinuxCapabilityType]) -> CapsHashSet {
let mut capabilities = CapsHashSet::new();
Expand Down
4 changes: 2 additions & 2 deletions src/cgroups/blkio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::{

use crate::{
cgroups::Controller,
spec::{LinuxBlockIo, LinuxResources},
};
use oci_spec::{LinuxBlockIo, LinuxResources};

const CGROUP_BLKIO_THROTTLE_READ_BPS: &str = "blkio.throttle.read_bps_device";
const CGROUP_BLKIO_THROTTLE_WRITE_BPS: &str = "blkio.throttle.write_bps_device";
Expand Down Expand Up @@ -91,7 +91,7 @@ mod tests {
use std::path::PathBuf;

use super::*;
use crate::spec::{LinuxBlockIo, LinuxThrottleDevice};
use oci_spec::{LinuxBlockIo, LinuxThrottleDevice};

struct BlockIoBuilder {
block_io: LinuxBlockIo,
Expand Down
2 changes: 1 addition & 1 deletion src/cgroups/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;
use anyhow::Result;
use nix::unistd::Pid;

use crate::spec::LinuxResources;
use oci_spec::LinuxResources;

pub trait Controller {
fn apply(linux_resources: &LinuxResources, cgroup_root: &Path, pid: Pid) -> Result<()>;
Expand Down
22 changes: 1 addition & 21 deletions src/cgroups/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,8 @@ use nix::unistd::Pid;
use crate::{
cgroups::Controller,
rootfs::default_devices,
spec::{LinuxDeviceCgroup, LinuxDeviceType, LinuxResources},
};

impl ToString for LinuxDeviceCgroup {
fn to_string(&self) -> String {
let major = self
.major
.map(|mj| mj.to_string())
.unwrap_or_else(|| "*".to_string());
let minor = self
.minor
.map(|mi| mi.to_string())
.unwrap_or_else(|| "*".to_string());
format!(
"{} {}:{} {}",
self.typ.as_str(),
&major,
&minor,
&self.access
)
}
}
use oci_spec::{LinuxDeviceCgroup, LinuxDeviceType, LinuxResources};

pub struct Devices {}

Expand Down
4 changes: 2 additions & 2 deletions src/cgroups/hugetlb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use regex::Regex;

use crate::{
cgroups::Controller,
spec::{LinuxHugepageLimit, LinuxResources},
};
use oci_spec::{LinuxHugepageLimit, LinuxResources};

pub struct Hugetlb {}

Expand Down Expand Up @@ -79,7 +79,7 @@ mod tests {
use std::path::PathBuf;

use super::*;
use crate::spec::LinuxHugepageLimit;
use oci_spec::LinuxHugepageLimit;

fn set_fixture(temp_dir: &std::path::Path, filename: &str, val: &str) -> anyhow::Result<()> {
std::fs::OpenOptions::new()
Expand Down
Loading