Skip to main content

k8s_openapi/v1_37/api/resource/v1beta2/
node_allocatable_mapping.rs

1// Generated from definition io.k8s.api.resource.v1beta2.NodeAllocatableMapping
2
3/// NodeAllocatableMapping defines how a DRA allocation directly translates into a node allocatable resource quantity. The mapping can be derived from either the count of allocated devices (via deviceMultiplier) or the specific capacity consumed (via capacityKey and capacityMultiplier). These options are mutually exclusive. Kubelet adds this mapped resource quantity from claim to both requests and limits at the pod-level cgroup, and to limits at the container-level cgroup for each container referencing the claim.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct NodeAllocatableMapping {
6    /// CapacityKey references a capacity name defined as a key in the `spec.devices\[*\].capacity` map. When this field is set, the value associated with this key in the `status.allocation.devices.results\[*\].consumedCapacity` map (for a specific claim allocation) determines the base quantity for the node allocatable resource. `capacityMultiplier` must also be set and is multiplied with the base quantity. For example, if `spec.devices\[*\].capacity` has an entry "dra.example.com/memory": "128Gi", and this field is set to "dra.example.com/memory", then for a claim allocation that consumes { "dra.example.com/memory": "4Gi" } the base quantity for the node allocatable resource mapping will be "4Gi". The final node allocatable resource amount is `consumedCapacity\[capacityKey\]` * `capacityMultiplier`.
7    pub capacity_key: Option<std::string::String>,
8
9    /// CapacityMultiplier is used as a multiplier for the allocated capacity consumed. It is only valid if `capacityKey` is set. The final node allocatable resource amount is `consumedCapacity\[capacityKey\]` * `capacityMultiplier`. For example, if a Device's capacity "dra.example.com/cores" is consumed, and each "core" provides 2 "cpu"s, the mapping would be: {ResourceName: "cpu", capacityKey: "dra.example.com/cores", capacityMultiplier: "2"}. If a claim consumes 8 "dra.example.com/cores", the CPU footprint is 8 * 2 = 16.
10    pub capacity_multiplier: Option<crate::apimachinery::pkg::api::resource::Quantity>,
11
12    /// DeviceMultiplier is used as a multiplier for the allocated device count in the claim. The final node allocatable resource amount is `deviceCount` * `deviceMultiplier`. For example, a DRA driver representing each cache complex (CCX) as a device would have {ResourceName: "cpu", deviceMultiplier: "8"} in its `nodeAllocatableResources`. If 2 devices (CCX) are allocated to the claim, 2 * 8 = 16 CPUs would be considered as allocated. It is only valid when `capacityKey` and `capacityMultiplier` are not set.
13    pub device_multiplier: Option<crate::apimachinery::pkg::api::resource::Quantity>,
14}
15
16impl crate::DeepMerge for NodeAllocatableMapping {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.capacity_key, other.capacity_key);
19        crate::DeepMerge::merge_from(&mut self.capacity_multiplier, other.capacity_multiplier);
20        crate::DeepMerge::merge_from(&mut self.device_multiplier, other.device_multiplier);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for NodeAllocatableMapping {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26        #[allow(non_camel_case_types)]
27        enum Field {
28            Key_capacity_key,
29            Key_capacity_multiplier,
30            Key_device_multiplier,
31            Other,
32        }
33
34        impl<'de> crate::serde::Deserialize<'de> for Field {
35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36                struct Visitor;
37
38                impl crate::serde::de::Visitor<'_> for Visitor {
39                    type Value = Field;
40
41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42                        f.write_str("field identifier")
43                    }
44
45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46                        Ok(match v {
47                            "capacityKey" => Field::Key_capacity_key,
48                            "capacityMultiplier" => Field::Key_capacity_multiplier,
49                            "deviceMultiplier" => Field::Key_device_multiplier,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = NodeAllocatableMapping;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("NodeAllocatableMapping")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_capacity_key: Option<std::string::String> = None;
70                let mut value_capacity_multiplier: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
71                let mut value_device_multiplier: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_capacity_key => value_capacity_key = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_capacity_multiplier => value_capacity_multiplier = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_device_multiplier => value_device_multiplier = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79                    }
80                }
81
82                Ok(NodeAllocatableMapping {
83                    capacity_key: value_capacity_key,
84                    capacity_multiplier: value_capacity_multiplier,
85                    device_multiplier: value_device_multiplier,
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "NodeAllocatableMapping",
92            &[
93                "capacityKey",
94                "capacityMultiplier",
95                "deviceMultiplier",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for NodeAllocatableMapping {
103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104        let mut state = serializer.serialize_struct(
105            "NodeAllocatableMapping",
106            self.capacity_key.as_ref().map_or(0, |_| 1) +
107            self.capacity_multiplier.as_ref().map_or(0, |_| 1) +
108            self.device_multiplier.as_ref().map_or(0, |_| 1),
109        )?;
110        if let Some(value) = &self.capacity_key {
111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "capacityKey", value)?;
112        }
113        if let Some(value) = &self.capacity_multiplier {
114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "capacityMultiplier", value)?;
115        }
116        if let Some(value) = &self.device_multiplier {
117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deviceMultiplier", value)?;
118        }
119        crate::serde::ser::SerializeStruct::end(state)
120    }
121}
122
123#[cfg(feature = "schemars")]
124impl crate::schemars::JsonSchema for NodeAllocatableMapping {
125    fn schema_name() -> std::borrow::Cow<'static, str> {
126        "io.k8s.api.resource.v1beta2.NodeAllocatableMapping".into()
127    }
128
129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
130        crate::schemars::json_schema!({
131            "description": "NodeAllocatableMapping defines how a DRA allocation directly translates into a node allocatable resource quantity. The mapping can be derived from either the count of allocated devices (via deviceMultiplier) or the specific capacity consumed (via capacityKey and capacityMultiplier). These options are mutually exclusive. Kubelet adds this mapped resource quantity from claim to both requests and limits at the pod-level cgroup, and to limits at the container-level cgroup for each container referencing the claim.",
132            "type": "object",
133            "properties": {
134                "capacityKey": {
135                    "description": "CapacityKey references a capacity name defined as a key in the `spec.devices[*].capacity` map. When this field is set, the value associated with this key in the `status.allocation.devices.results[*].consumedCapacity` map (for a specific claim allocation) determines the base quantity for the node allocatable resource. `capacityMultiplier` must also be set and is multiplied with the base quantity. For example, if `spec.devices[*].capacity` has an entry \"dra.example.com/memory\": \"128Gi\", and this field is set to \"dra.example.com/memory\", then for a claim allocation that consumes { \"dra.example.com/memory\": \"4Gi\" } the base quantity for the node allocatable resource mapping will be \"4Gi\". The final node allocatable resource amount is `consumedCapacity[capacityKey]` * `capacityMultiplier`.",
136                    "type": "string",
137                },
138                "capacityMultiplier": ({
139                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
140                    schema_obj.ensure_object().insert("description".into(), "CapacityMultiplier is used as a multiplier for the allocated capacity consumed. It is only valid if `capacityKey` is set. The final node allocatable resource amount is `consumedCapacity[capacityKey]` * `capacityMultiplier`. For example, if a Device's capacity \"dra.example.com/cores\" is consumed, and each \"core\" provides 2 \"cpu\"s, the mapping would be: {ResourceName: \"cpu\", capacityKey: \"dra.example.com/cores\", capacityMultiplier: \"2\"}. If a claim consumes 8 \"dra.example.com/cores\", the CPU footprint is 8 * 2 = 16.".into());
141                    schema_obj
142                }),
143                "deviceMultiplier": ({
144                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
145                    schema_obj.ensure_object().insert("description".into(), "DeviceMultiplier is used as a multiplier for the allocated device count in the claim. The final node allocatable resource amount is `deviceCount` * `deviceMultiplier`. For example, a DRA driver representing each cache complex (CCX) as a device would have {ResourceName: \"cpu\", deviceMultiplier: \"8\"} in its `nodeAllocatableResources`. If 2 devices (CCX) are allocated to the claim, 2 * 8 = 16 CPUs would be considered as allocated. It is only valid when `capacityKey` and `capacityMultiplier` are not set.".into());
146                    schema_obj
147                }),
148            },
149        })
150    }
151}