k8s_openapi/v1_34/api/resource/v1beta1/
capacity_requirements.rs

1// Generated from definition io.k8s.api.resource.v1beta1.CapacityRequirements
2
3/// CapacityRequirements defines the capacity requirements for a specific device request.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct CapacityRequirements {
6    /// Requests represent individual device resource requests for distinct resources, all of which must be provided by the device.
7    ///
8    /// This value is used as an additional filtering condition against the available capacity on the device. This is semantically equivalent to a CEL selector with `device.capacity\[\<domain\>\].\<name\>.compareTo(quantity(\<request quantity\>)) \>= 0`. For example, device.capacity\['test-driver.cdi.k8s.io'\].counters.compareTo(quantity('2')) \>= 0.
9    ///
10    /// When a requestPolicy is defined, the requested amount is adjusted upward to the nearest valid value based on the policy. If the requested amount cannot be adjusted to a valid value—because it exceeds what the requestPolicy allows— the device is considered ineligible for allocation.
11    ///
12    /// For any capacity that is not explicitly requested: - If no requestPolicy is set, the default consumed capacity is equal to the full device capacity
13    ///   (i.e., the whole device is claimed).
14    /// - If a requestPolicy is set, the default consumed capacity is determined according to that policy.
15    ///
16    /// If the device allows multiple allocation, the aggregated amount across all requests must not exceed the capacity value. The consumed capacity, which may be adjusted based on the requestPolicy if defined, is recorded in the resource claim’s status.devices\[*\].consumedCapacity field.
17    pub requests: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
18}
19
20impl crate::DeepMerge for CapacityRequirements {
21    fn merge_from(&mut self, other: Self) {
22        crate::merge_strategies::map::granular(&mut self.requests, other.requests, |current_item, other_item| {
23            crate::DeepMerge::merge_from(current_item, other_item);
24        });
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for CapacityRequirements {
29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30        #[allow(non_camel_case_types)]
31        enum Field {
32            Key_requests,
33            Other,
34        }
35
36        impl<'de> crate::serde::Deserialize<'de> for Field {
37            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38                struct Visitor;
39
40                impl crate::serde::de::Visitor<'_> for Visitor {
41                    type Value = Field;
42
43                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44                        f.write_str("field identifier")
45                    }
46
47                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
48                        Ok(match v {
49                            "requests" => Field::Key_requests,
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 = CapacityRequirements;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("CapacityRequirements")
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_requests: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
70
71                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
72                    match key {
73                        Field::Key_requests => value_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
74                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
75                    }
76                }
77
78                Ok(CapacityRequirements {
79                    requests: value_requests,
80                })
81            }
82        }
83
84        deserializer.deserialize_struct(
85            "CapacityRequirements",
86            &[
87                "requests",
88            ],
89            Visitor,
90        )
91    }
92}
93
94impl crate::serde::Serialize for CapacityRequirements {
95    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
96        let mut state = serializer.serialize_struct(
97            "CapacityRequirements",
98            self.requests.as_ref().map_or(0, |_| 1),
99        )?;
100        if let Some(value) = &self.requests {
101            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requests", value)?;
102        }
103        crate::serde::ser::SerializeStruct::end(state)
104    }
105}
106
107#[cfg(feature = "schemars")]
108impl crate::schemars::JsonSchema for CapacityRequirements {
109    fn schema_name() -> std::borrow::Cow<'static, str> {
110        "io.k8s.api.resource.v1beta1.CapacityRequirements".into()
111    }
112
113    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
114        crate::schemars::json_schema!({
115            "description": "CapacityRequirements defines the capacity requirements for a specific device request.",
116            "type": "object",
117            "properties": {
118                "requests": {
119                    "description": "Requests represent individual device resource requests for distinct resources, all of which must be provided by the device.\n\nThis value is used as an additional filtering condition against the available capacity on the device. This is semantically equivalent to a CEL selector with `device.capacity[<domain>].<name>.compareTo(quantity(<request quantity>)) >= 0`. For example, device.capacity['test-driver.cdi.k8s.io'].counters.compareTo(quantity('2')) >= 0.\n\nWhen a requestPolicy is defined, the requested amount is adjusted upward to the nearest valid value based on the policy. If the requested amount cannot be adjusted to a valid value—because it exceeds what the requestPolicy allows— the device is considered ineligible for allocation.\n\nFor any capacity that is not explicitly requested: - If no requestPolicy is set, the default consumed capacity is equal to the full device capacity\n  (i.e., the whole device is claimed).\n- If a requestPolicy is set, the default consumed capacity is determined according to that policy.\n\nIf the device allows multiple allocation, the aggregated amount across all requests must not exceed the capacity value. The consumed capacity, which may be adjusted based on the requestPolicy if defined, is recorded in the resource claim’s status.devices[*].consumedCapacity field.",
120                    "type": "object",
121                    "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
122                },
123            },
124        })
125    }
126}