From 6181570ccca0ab13c4ab8541aa482122d6f506f1 Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Tue, 22 Dec 2020 00:03:27 +0800 Subject: [PATCH 1/3] oci: fix a typo in "addtionalGids" There's a typo in "addtionalGids", which should be "additionalGids". Fixes: #1211 Signed-off-by: Liu Jiang --- src/agent/oci/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/agent/oci/src/lib.rs b/src/agent/oci/src/lib.rs index 0c4794f6e..94e1c798c 100644 --- a/src/agent/oci/src/lib.rs +++ b/src/agent/oci/src/lib.rs @@ -142,7 +142,7 @@ pub struct User { pub gid: u32, #[serde( default, - rename = "addtionalGids", + rename = "additionalGids", skip_serializing_if = "Vec::is_empty" )] pub additional_gids: Vec, @@ -1223,8 +1223,7 @@ mod tests { uid: 1, gid: 1, // incompatible with oci - // additional_gids: vec![5, 6], - additional_gids: vec![], + additional_gids: vec![5, 6], username: "".to_string(), }, args: vec!["sh".to_string()], From 406a91ffdd7875bb0b41ed48f7f0d6d5dce41ac2 Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Sat, 30 May 2020 23:09:53 +0800 Subject: [PATCH 2/3] agent: consume ttrpc crate from crates.io The ttrpc v0.3.0 has been published to crates.io, so consume from crates.io. Fixes: #1213 Signed-off-by: Liu Jiang --- src/agent/Cargo.lock | 3 ++- src/agent/Cargo.toml | 2 +- src/agent/protocols/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/agent/Cargo.lock b/src/agent/Cargo.lock index efe2c26fc..6e3c77de3 100644 --- a/src/agent/Cargo.lock +++ b/src/agent/Cargo.lock @@ -1198,7 +1198,8 @@ dependencies = [ [[package]] name = "ttrpc" version = "0.3.0" -source = "git+https://github.com/containerd/ttrpc-rust.git?branch=0.3.0#ba1efe3bbb8f8af4895b7623ed1d11561e70e566" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa9da24c351f0feef5e66c0b28c18373a7ef3e1bfdfd5852170de494f9bf870" dependencies = [ "byteorder", "libc", diff --git a/src/agent/Cargo.toml b/src/agent/Cargo.toml index f5e7e6e12..72d092aec 100644 --- a/src/agent/Cargo.toml +++ b/src/agent/Cargo.toml @@ -11,7 +11,7 @@ rustjail = { path = "rustjail" } protocols = { path = "protocols" } netlink = { path = "netlink", features = ["with-log", "with-agent-handler"] } lazy_static = "1.3.0" -ttrpc = { git = "https://github.com/containerd/ttrpc-rust.git", branch="0.3.0" } +ttrpc = "0.3.0" protobuf = "=2.14.0" libc = "0.2.58" nix = "0.17.0" diff --git a/src/agent/protocols/Cargo.toml b/src/agent/protocols/Cargo.toml index 7b383a217..59ab72427 100644 --- a/src/agent/protocols/Cargo.toml +++ b/src/agent/protocols/Cargo.toml @@ -5,7 +5,7 @@ authors = ["The Kata Containers community "] edition = "2018" [dependencies] -ttrpc = { git = "https://github.com/containerd/ttrpc-rust.git", branch="0.3.0" } +ttrpc = "0.3.0" protobuf = "=2.14.0" futures = "0.1.27" From 9321e1b21b3046554d7b695ab3af83873809acc0 Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Tue, 22 Dec 2020 11:16:15 +0800 Subject: [PATCH 3/3] oci: fix two incompatible issues with OCI spec The first incompatible issue is caused by a typo, "swapiness" should be "swappiness". The second incompatible issue is caused by a serde format. The struct LinuxBlockIODevice is introduced for convenience, but it also changes serialized data, so "#[serde(flatten)]" should be used for compatibility with OCI spec. Fixes: #1211 Signed-off-by: Liu Jiang --- src/agent/oci/src/lib.rs | 52 ++++++------------------ src/agent/rustjail/src/cgroups/fs/mod.rs | 8 ++-- src/agent/rustjail/src/lib.rs | 2 +- 3 files changed, 18 insertions(+), 44 deletions(-) diff --git a/src/agent/oci/src/lib.rs b/src/agent/oci/src/lib.rs index 94e1c798c..b51d78436 100644 --- a/src/agent/oci/src/lib.rs +++ b/src/agent/oci/src/lib.rs @@ -302,6 +302,7 @@ pub struct LinuxBlockIODevice { #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] pub struct LinuxWeightDevice { + #[serde(flatten)] pub blk: LinuxBlockIODevice, #[serde(default, skip_serializing_if = "Option::is_none")] pub weight: Option, @@ -315,6 +316,7 @@ pub struct LinuxWeightDevice { #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] pub struct LinuxThrottleDevice { + #[serde(flatten)] pub blk: LinuxBlockIODevice, #[serde(default)] pub rate: u64, @@ -375,7 +377,7 @@ pub struct LinuxMemory { #[serde(default, skip_serializing_if = "Option::is_none", rename = "kernelTCP")] pub kernel_tcp: Option, #[serde(default, skip_serializing_if = "Option::is_none")] - pub swapiness: Option, + pub swappiness: Option, #[serde( default, skip_serializing_if = "Option::is_none", @@ -833,7 +835,7 @@ mod tests { } #[test] - fn test_deserialize_sepc() { + fn test_deserialize_spec() { let data = r#"{ "ociVersion": "1.0.1", "process": { @@ -1118,36 +1120,28 @@ mod tests { "leafWeight": 10, "weightDevice": [ { - "blk": { - "major": 8, - "minor": 0 - }, + "major": 8, + "minor": 0, "weight": 500, "leafWeight": 300 }, { - "blk":{ - "major": 8, - "minor": 16 - }, + "major": 8, + "minor": 16, "weight": 500 } ], "throttleReadBpsDevice": [ { - "blk":{ - "major": 8, - "minor": 0 - }, + "major": 8, + "minor": 0, "rate": 600 } ], "throttleWriteIOPSDevice": [ { - "blk":{ - "major": 8, - "minor": 16 - }, + "major": 8, + "minor": 16, "rate": 300 } ] @@ -1436,8 +1430,7 @@ mod tests { swap: Some(536870912), kernel: Some(-1), kernel_tcp: Some(-1), - // incompatible with oci - swapiness: None, + swappiness: Some(0), disable_oom_killer: Some(false), }), cpu: Some(crate::LinuxCPU { @@ -1590,25 +1583,6 @@ mod tests { vm: None, }; - // warning : incompatible with oci : https://github.com/opencontainers/runtime-spec/blob/master/config.md - // 1. User use addtionalGids while oci use additionalGids - // 2. LinuxMemory use swapiness while oci use swappiness - // 3. LinuxWeightDevice with blk - // { - // "blk": { - // "major": 8, - // "minor": 0 - // }, - // "weight": 500, - // "leafWeight": 300 - // } - // oci without blk - // { - // "major": 8, - // "minor": 0, - // "weight": 500, - // "leafWeight": 300 - // } let current: crate::Spec = serde_json::from_str(data).unwrap(); assert_eq!(expected, current); } diff --git a/src/agent/rustjail/src/cgroups/fs/mod.rs b/src/agent/rustjail/src/cgroups/fs/mod.rs index 5702abacf..bff3e7830 100644 --- a/src/agent/rustjail/src/cgroups/fs/mod.rs +++ b/src/agent/rustjail/src/cgroups/fs/mod.rs @@ -423,13 +423,13 @@ fn set_memory_resources(cg: &cgroups::Cgroup, memory: &LinuxMemory, update: bool } } - if let Some(swapiness) = memory.swapiness { - if swapiness >= 0 && swapiness <= 100 { - mem_controller.set_swappiness(swapiness as u64)?; + if let Some(swappiness) = memory.swappiness { + if swappiness >= 0 && swappiness <= 100 { + mem_controller.set_swappiness(swappiness as u64)?; } else { return Err(anyhow!( "invalid value:{}. valid memory swappiness range is 0-100", - swapiness + swappiness )); } } diff --git a/src/agent/rustjail/src/lib.rs b/src/agent/rustjail/src/lib.rs index 50f82c646..e88dde40c 100644 --- a/src/agent/rustjail/src/lib.rs +++ b/src/agent/rustjail/src/lib.rs @@ -310,7 +310,7 @@ pub fn resources_grpc_to_oci(res: &grpcLinuxResources) -> ociLinuxResources { swap: Some(mem.Swap), kernel: Some(mem.Kernel), kernel_tcp: Some(mem.KernelTCP), - swapiness: Some(mem.Swappiness as i64), + swappiness: Some(mem.Swappiness as i64), disable_oom_killer: Some(mem.DisableOOMKiller), }) } else {