k8s_openapi/v1_37/api/resource/v1beta1/
node_allocatable_overhead.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct NodeAllocatableOverhead {
6 pub per_container: Option<crate::apimachinery::pkg::api::resource::Quantity>,
8
9 pub per_pod: Option<crate::apimachinery::pkg::api::resource::Quantity>,
11}
12
13impl crate::DeepMerge for NodeAllocatableOverhead {
14 fn merge_from(&mut self, other: Self) {
15 crate::DeepMerge::merge_from(&mut self.per_container, other.per_container);
16 crate::DeepMerge::merge_from(&mut self.per_pod, other.per_pod);
17 }
18}
19
20impl<'de> crate::serde::Deserialize<'de> for NodeAllocatableOverhead {
21 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
22 #[allow(non_camel_case_types)]
23 enum Field {
24 Key_per_container,
25 Key_per_pod,
26 Other,
27 }
28
29 impl<'de> crate::serde::Deserialize<'de> for Field {
30 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
31 struct Visitor;
32
33 impl crate::serde::de::Visitor<'_> for Visitor {
34 type Value = Field;
35
36 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
37 f.write_str("field identifier")
38 }
39
40 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
41 Ok(match v {
42 "perContainer" => Field::Key_per_container,
43 "perPod" => Field::Key_per_pod,
44 _ => Field::Other,
45 })
46 }
47 }
48
49 deserializer.deserialize_identifier(Visitor)
50 }
51 }
52
53 struct Visitor;
54
55 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
56 type Value = NodeAllocatableOverhead;
57
58 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
59 f.write_str("NodeAllocatableOverhead")
60 }
61
62 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
63 let mut value_per_container: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
64 let mut value_per_pod: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
65
66 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
67 match key {
68 Field::Key_per_container => value_per_container = crate::serde::de::MapAccess::next_value(&mut map)?,
69 Field::Key_per_pod => value_per_pod = crate::serde::de::MapAccess::next_value(&mut map)?,
70 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
71 }
72 }
73
74 Ok(NodeAllocatableOverhead {
75 per_container: value_per_container,
76 per_pod: value_per_pod,
77 })
78 }
79 }
80
81 deserializer.deserialize_struct(
82 "NodeAllocatableOverhead",
83 &[
84 "perContainer",
85 "perPod",
86 ],
87 Visitor,
88 )
89 }
90}
91
92impl crate::serde::Serialize for NodeAllocatableOverhead {
93 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
94 let mut state = serializer.serialize_struct(
95 "NodeAllocatableOverhead",
96 self.per_container.as_ref().map_or(0, |_| 1) +
97 self.per_pod.as_ref().map_or(0, |_| 1),
98 )?;
99 if let Some(value) = &self.per_container {
100 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "perContainer", value)?;
101 }
102 if let Some(value) = &self.per_pod {
103 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "perPod", value)?;
104 }
105 crate::serde::ser::SerializeStruct::end(state)
106 }
107}
108
109#[cfg(feature = "schemars")]
110impl crate::schemars::JsonSchema for NodeAllocatableOverhead {
111 fn schema_name() -> std::borrow::Cow<'static, str> {
112 "io.k8s.api.resource.v1beta1.NodeAllocatableOverhead".into()
113 }
114
115 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
116 crate::schemars::json_schema!({
117 "description": "NodeAllocatableOverhead defines auxiliary resource overheads incurred when allocating a device. Overheads can be specified as a fixed cost per pod referencing the claim, a variable cost per container reference, or both. Kubelet accounts for this overhead by adding it to both the pod-level and container-level cgroups of referencing containers.",
118 "type": "object",
119 "properties": {
120 "perContainer": ({
121 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
122 schema_obj.ensure_object().insert("description".into(), "PerContainer is applied per container reference to the claim. This models overhead scaling linearly with the number of containers actively using the device. When both PerPod and PerContainer are specified, the total overhead allocated for each pod referencing the claim is computed as: Quantity = PerPod + (PerContainer * NumReferences) Kubelet accounts for this overhead in cgroups: - Pod-level cgroup (requests and limits): Kubelet adds PerPod + (PerContainer * NumReferences). - Container-level cgroup (limits only): Kubelet adds PerPod + PerContainer for each referencing container. This allows any single container to access the pod-level overhead, while the parent cgroup caps the total usage to account for PerPod exactly once.".into());
123 schema_obj
124 }),
125 "perPod": ({
126 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
127 schema_obj.ensure_object().insert("description".into(), "PerPod is overhead applied once per pod referencing the claim on this node. This is a flat overhead incurred for every pod referencing the claim.".into());
128 schema_obj
129 }),
130 },
131 })
132 }
133}