Skip to main content

k8s_openapi/v1_36/api/resource/v1beta1/
node_allocatable_resource_mapping.rs

1// Generated from definition io.k8s.api.resource.v1beta1.NodeAllocatableResourceMapping
2
3/// NodeAllocatableResourceMapping defines the translation between the DRA device/capacity units requested to the corresponding quantity of the node allocatable resource.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct NodeAllocatableResourceMapping {
6    /// AllocationMultiplier is used as a multiplier for the allocated device count or the allocated capacity in the claim. It defaults to 1 if not specified. How the field is used also depends on whether `capacityKey` is set. 1.  If `capacityKey` is NOT set: `allocationMultiplier` multiplies the device count allocated to the claim.
7    ///        a. A DRA driver representing each CPU core as a device would have
8    ///        {ResourceName: "cpu", allocationMultiplier: "2"} in its
9    ///        `nodeAllocatableResourceMappings`. If 4 devices are allocated to the claim,
10    ///           4 * 2 CPUs would be considered as allocated and subtracted from the node's capacity.
11    ///     b. A GPU device that needs additional node memory per GPU allocation would
12    ///        have {ResourceName: "memory", allocationMultiplier: "2Gi"}.  Each allocated
13    ///           GPU device instance of this type will account for 2Gi of memory.
14    ///
15    /// 2.  If `capacityKey` IS set: `allocationMultiplier` is multiplied by the amount of that capacity consumed.
16    ///        The final node allocatable resource amount is `consumedCapacity\[capacityKey\]` * `allocationMultiplier`.
17    ///     For example, if a Device's capacity "dra.example.com/cores" is consumed,
18    ///     and each "core" provides 2 "cpu"s, the mapping would be:
19    ///     {ResourceName: "cpu", capacityKey: "dra.example.com/cores", allocationMultiplier: "2"}.
20    ///     If a claim consumes 8 "dra.example.com/cores", the CPU footprint is 8 * 2 = 16.
21    pub allocation_multiplier: Option<crate::apimachinery::pkg::api::resource::Quantity>,
22
23    /// 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. If `allocationMultiplier` is also set, it 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", and `allocationMultiplier` should be omitted or set to "1".
24    pub capacity_key: Option<std::string::String>,
25}
26
27impl crate::DeepMerge for NodeAllocatableResourceMapping {
28    fn merge_from(&mut self, other: Self) {
29        crate::DeepMerge::merge_from(&mut self.allocation_multiplier, other.allocation_multiplier);
30        crate::DeepMerge::merge_from(&mut self.capacity_key, other.capacity_key);
31    }
32}
33
34impl<'de> crate::serde::Deserialize<'de> for NodeAllocatableResourceMapping {
35    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36        #[allow(non_camel_case_types)]
37        enum Field {
38            Key_allocation_multiplier,
39            Key_capacity_key,
40            Other,
41        }
42
43        impl<'de> crate::serde::Deserialize<'de> for Field {
44            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
45                struct Visitor;
46
47                impl crate::serde::de::Visitor<'_> for Visitor {
48                    type Value = Field;
49
50                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
51                        f.write_str("field identifier")
52                    }
53
54                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
55                        Ok(match v {
56                            "allocationMultiplier" => Field::Key_allocation_multiplier,
57                            "capacityKey" => Field::Key_capacity_key,
58                            _ => Field::Other,
59                        })
60                    }
61                }
62
63                deserializer.deserialize_identifier(Visitor)
64            }
65        }
66
67        struct Visitor;
68
69        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
70            type Value = NodeAllocatableResourceMapping;
71
72            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
73                f.write_str("NodeAllocatableResourceMapping")
74            }
75
76            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
77                let mut value_allocation_multiplier: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
78                let mut value_capacity_key: Option<std::string::String> = None;
79
80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81                    match key {
82                        Field::Key_allocation_multiplier => value_allocation_multiplier = crate::serde::de::MapAccess::next_value(&mut map)?,
83                        Field::Key_capacity_key => value_capacity_key = crate::serde::de::MapAccess::next_value(&mut map)?,
84                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
85                    }
86                }
87
88                Ok(NodeAllocatableResourceMapping {
89                    allocation_multiplier: value_allocation_multiplier,
90                    capacity_key: value_capacity_key,
91                })
92            }
93        }
94
95        deserializer.deserialize_struct(
96            "NodeAllocatableResourceMapping",
97            &[
98                "allocationMultiplier",
99                "capacityKey",
100            ],
101            Visitor,
102        )
103    }
104}
105
106impl crate::serde::Serialize for NodeAllocatableResourceMapping {
107    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
108        let mut state = serializer.serialize_struct(
109            "NodeAllocatableResourceMapping",
110            self.allocation_multiplier.as_ref().map_or(0, |_| 1) +
111            self.capacity_key.as_ref().map_or(0, |_| 1),
112        )?;
113        if let Some(value) = &self.allocation_multiplier {
114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationMultiplier", value)?;
115        }
116        if let Some(value) = &self.capacity_key {
117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "capacityKey", value)?;
118        }
119        crate::serde::ser::SerializeStruct::end(state)
120    }
121}
122
123#[cfg(feature = "schemars")]
124impl crate::schemars::JsonSchema for NodeAllocatableResourceMapping {
125    fn schema_name() -> std::borrow::Cow<'static, str> {
126        "io.k8s.api.resource.v1beta1.NodeAllocatableResourceMapping".into()
127    }
128
129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
130        crate::schemars::json_schema!({
131            "description": "NodeAllocatableResourceMapping defines the translation between the DRA device/capacity units requested to the corresponding quantity of the node allocatable resource.",
132            "type": "object",
133            "properties": {
134                "allocationMultiplier": ({
135                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
136                    schema_obj.ensure_object().insert("description".into(), "AllocationMultiplier is used as a multiplier for the allocated device count or the allocated capacity in the claim. It defaults to 1 if not specified. How the field is used also depends on whether `capacityKey` is set. 1.  If `capacityKey` is NOT set: `allocationMultiplier` multiplies the device count allocated to the claim.\n\t   a. A DRA driver representing each CPU core as a device would have\n       {ResourceName: \"cpu\", allocationMultiplier: \"2\"} in its\n       `nodeAllocatableResourceMappings`. If 4 devices are allocated to the claim,\n\t\t  4 * 2 CPUs would be considered as allocated and subtracted from the node's capacity.\n    b. A GPU device that needs additional node memory per GPU allocation would\n       have {ResourceName: \"memory\", allocationMultiplier: \"2Gi\"}.  Each allocated\n\t\t  GPU device instance of this type will account for 2Gi of memory.\n\n2.  If `capacityKey` IS set: `allocationMultiplier` is multiplied by the amount of that capacity consumed.\n\t   The final node allocatable resource amount is `consumedCapacity[capacityKey]` * `allocationMultiplier`.\n    For example, if a Device's capacity \"dra.example.com/cores\" is consumed,\n    and each \"core\" provides 2 \"cpu\"s, the mapping would be:\n    {ResourceName: \"cpu\", capacityKey: \"dra.example.com/cores\", allocationMultiplier: \"2\"}.\n    If a claim consumes 8 \"dra.example.com/cores\", the CPU footprint is 8 * 2 = 16.".into());
137                    schema_obj
138                }),
139                "capacityKey": {
140                    "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. If `allocationMultiplier` is also set, it 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\", and `allocationMultiplier` should be omitted or set to \"1\".",
141                    "type": "string",
142                },
143            },
144        })
145    }
146}
147
148#[cfg(feature = "schemars08")]
149impl crate::schemars08::JsonSchema for NodeAllocatableResourceMapping {
150    fn schema_name() -> std::string::String {
151        "io.k8s.api.resource.v1beta1.NodeAllocatableResourceMapping".into()
152    }
153
154    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
155        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
156            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
157                description: Some("NodeAllocatableResourceMapping defines the translation between the DRA device/capacity units requested to the corresponding quantity of the node allocatable resource.".into()),
158                ..Default::default()
159            })),
160            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
161            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
162                properties: [
163                    (
164                        "allocationMultiplier".into(),
165                        {
166                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>().into_object();
167                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
168                                description: Some("AllocationMultiplier is used as a multiplier for the allocated device count or the allocated capacity in the claim. It defaults to 1 if not specified. How the field is used also depends on whether `capacityKey` is set. 1.  If `capacityKey` is NOT set: `allocationMultiplier` multiplies the device count allocated to the claim.\n\t   a. A DRA driver representing each CPU core as a device would have\n       {ResourceName: \"cpu\", allocationMultiplier: \"2\"} in its\n       `nodeAllocatableResourceMappings`. If 4 devices are allocated to the claim,\n\t\t  4 * 2 CPUs would be considered as allocated and subtracted from the node's capacity.\n    b. A GPU device that needs additional node memory per GPU allocation would\n       have {ResourceName: \"memory\", allocationMultiplier: \"2Gi\"}.  Each allocated\n\t\t  GPU device instance of this type will account for 2Gi of memory.\n\n2.  If `capacityKey` IS set: `allocationMultiplier` is multiplied by the amount of that capacity consumed.\n\t   The final node allocatable resource amount is `consumedCapacity[capacityKey]` * `allocationMultiplier`.\n    For example, if a Device's capacity \"dra.example.com/cores\" is consumed,\n    and each \"core\" provides 2 \"cpu\"s, the mapping would be:\n    {ResourceName: \"cpu\", capacityKey: \"dra.example.com/cores\", allocationMultiplier: \"2\"}.\n    If a claim consumes 8 \"dra.example.com/cores\", the CPU footprint is 8 * 2 = 16.".into()),
169                                ..Default::default()
170                            }));
171                            crate::schemars08::schema::Schema::Object(schema_obj)
172                        },
173                    ),
174                    (
175                        "capacityKey".into(),
176                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
177                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
178                                description: Some("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. If `allocationMultiplier` is also set, it 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\", and `allocationMultiplier` should be omitted or set to \"1\".".into()),
179                                ..Default::default()
180                            })),
181                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
182                            ..Default::default()
183                        }),
184                    ),
185                ].into(),
186                ..Default::default()
187            })),
188            ..Default::default()
189        })
190    }
191}