diff --git a/src/agent/oci/src/lib.rs b/src/agent/oci/src/lib.rs index 94e1c798c9..b51d78436b 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 c7fcee8c89..80d18fefe7 100644 --- a/src/agent/rustjail/src/cgroups/fs/mod.rs +++ b/src/agent/rustjail/src/cgroups/fs/mod.rs @@ -421,13 +421,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 63dc77046f..af9847b28d 100644 --- a/src/agent/rustjail/src/lib.rs +++ b/src/agent/rustjail/src/lib.rs @@ -309,7 +309,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 {