Skip to content

Commit

Permalink
better de/serialization for resourcelimits (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
pretentious7 authored Jan 5, 2024
1 parent 1ab6580 commit 3292e9a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
55 changes: 55 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 plane/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rusqlite = { version = "0.30.0", features = ["bundled", "serde_json"] }
rustls-pemfile = "2.0.0"
rustls-pki-types = "1.0.0"
serde = { version = "1.0.190", features = ["derive"] }
serde_with = "3.4.0"
serde_json = "1.0.107"
sqlx = { version = "0.7.3", features = ["runtime-tokio", "tls-rustls", "postgres", "chrono", "migrate", "json", "ipnetwork"] }
thiserror = "1.0.50"
Expand Down
10 changes: 8 additions & 2 deletions plane/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,12 @@ pub enum PullPolicy {
Never,
}

#[serde_with::serde_as]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct DockerCpuPeriod(std::time::Duration);
#[serde(transparent)]
pub struct DockerCpuPeriod(
#[serde_as(as = "serde_with::DurationMicroSeconds<u64>")] std::time::Duration,
);

impl Default for DockerCpuPeriod {
fn default() -> Self {
Expand All @@ -206,15 +210,17 @@ impl From<&DockerCpuPeriod> for std::time::Duration {
}
}

#[serde_with::serde_as]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
pub struct ResourceLimits {
/// Period of cpu time
/// Period of cpu time (de/serializes as microseconds)
pub cpu_period: Option<DockerCpuPeriod>,

/// Proportion of period used by container
pub cpu_period_percent: Option<u8>,

/// Total cpu time allocated to container
#[serde_as(as = "Option<serde_with::DurationSeconds<u64>>")]
pub cpu_time_limit: Option<std::time::Duration>,

/// Maximum amount of memory container can use (in bytes)
Expand Down

0 comments on commit 3292e9a

Please sign in to comment.