k8s_openapi/v1_34/api/resource/v1beta2/
capacity_request_policy.rs

1// Generated from definition io.k8s.api.resource.v1beta2.CapacityRequestPolicy
2
3/// CapacityRequestPolicy defines how requests consume device capacity.
4///
5/// Must not set more than one ValidRequestValues.
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct CapacityRequestPolicy {
8    /// Default specifies how much of this capacity is consumed by a request that does not contain an entry for it in DeviceRequest's Capacity.
9    pub default: Option<crate::apimachinery::pkg::api::resource::Quantity>,
10
11    /// ValidRange defines an acceptable quantity value range in consuming requests.
12    ///
13    /// If this field is set, Default must be defined and it must fall within the defined ValidRange.
14    ///
15    /// If the requested amount does not fall within the defined range, the request violates the policy, and this device cannot be allocated.
16    ///
17    /// If the request doesn't contain this capacity entry, Default value is used.
18    pub valid_range: Option<crate::api::resource::v1beta2::CapacityRequestPolicyRange>,
19
20    /// ValidValues defines a set of acceptable quantity values in consuming requests.
21    ///
22    /// Must not contain more than 10 entries. Must be sorted in ascending order.
23    ///
24    /// If this field is set, Default must be defined and it must be included in ValidValues list.
25    ///
26    /// If the requested amount does not match any valid value but smaller than some valid values, the scheduler calculates the smallest valid value that is greater than or equal to the request. That is: min(ceil(requestedValue) ∈ validValues), where requestedValue ≤ max(validValues).
27    ///
28    /// If the requested amount exceeds all valid values, the request violates the policy, and this device cannot be allocated.
29    pub valid_values: Option<std::vec::Vec<crate::apimachinery::pkg::api::resource::Quantity>>,
30}
31
32impl crate::DeepMerge for CapacityRequestPolicy {
33    fn merge_from(&mut self, other: Self) {
34        crate::DeepMerge::merge_from(&mut self.default, other.default);
35        crate::DeepMerge::merge_from(&mut self.valid_range, other.valid_range);
36        crate::merge_strategies::list::atomic(&mut self.valid_values, other.valid_values);
37    }
38}
39
40impl<'de> crate::serde::Deserialize<'de> for CapacityRequestPolicy {
41    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
42        #[allow(non_camel_case_types)]
43        enum Field {
44            Key_default,
45            Key_valid_range,
46            Key_valid_values,
47            Other,
48        }
49
50        impl<'de> crate::serde::Deserialize<'de> for Field {
51            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
52                struct Visitor;
53
54                impl crate::serde::de::Visitor<'_> for Visitor {
55                    type Value = Field;
56
57                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
58                        f.write_str("field identifier")
59                    }
60
61                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
62                        Ok(match v {
63                            "default" => Field::Key_default,
64                            "validRange" => Field::Key_valid_range,
65                            "validValues" => Field::Key_valid_values,
66                            _ => Field::Other,
67                        })
68                    }
69                }
70
71                deserializer.deserialize_identifier(Visitor)
72            }
73        }
74
75        struct Visitor;
76
77        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
78            type Value = CapacityRequestPolicy;
79
80            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
81                f.write_str("CapacityRequestPolicy")
82            }
83
84            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
85                let mut value_default: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
86                let mut value_valid_range: Option<crate::api::resource::v1beta2::CapacityRequestPolicyRange> = None;
87                let mut value_valid_values: Option<std::vec::Vec<crate::apimachinery::pkg::api::resource::Quantity>> = None;
88
89                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
90                    match key {
91                        Field::Key_default => value_default = crate::serde::de::MapAccess::next_value(&mut map)?,
92                        Field::Key_valid_range => value_valid_range = crate::serde::de::MapAccess::next_value(&mut map)?,
93                        Field::Key_valid_values => value_valid_values = crate::serde::de::MapAccess::next_value(&mut map)?,
94                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
95                    }
96                }
97
98                Ok(CapacityRequestPolicy {
99                    default: value_default,
100                    valid_range: value_valid_range,
101                    valid_values: value_valid_values,
102                })
103            }
104        }
105
106        deserializer.deserialize_struct(
107            "CapacityRequestPolicy",
108            &[
109                "default",
110                "validRange",
111                "validValues",
112            ],
113            Visitor,
114        )
115    }
116}
117
118impl crate::serde::Serialize for CapacityRequestPolicy {
119    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
120        let mut state = serializer.serialize_struct(
121            "CapacityRequestPolicy",
122            self.default.as_ref().map_or(0, |_| 1) +
123            self.valid_range.as_ref().map_or(0, |_| 1) +
124            self.valid_values.as_ref().map_or(0, |_| 1),
125        )?;
126        if let Some(value) = &self.default {
127            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "default", value)?;
128        }
129        if let Some(value) = &self.valid_range {
130            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "validRange", value)?;
131        }
132        if let Some(value) = &self.valid_values {
133            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "validValues", value)?;
134        }
135        crate::serde::ser::SerializeStruct::end(state)
136    }
137}
138
139#[cfg(feature = "schemars")]
140impl crate::schemars::JsonSchema for CapacityRequestPolicy {
141    fn schema_name() -> std::borrow::Cow<'static, str> {
142        "io.k8s.api.resource.v1beta2.CapacityRequestPolicy".into()
143    }
144
145    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
146        crate::schemars::json_schema!({
147            "description": "CapacityRequestPolicy defines how requests consume device capacity.\n\nMust not set more than one ValidRequestValues.",
148            "type": "object",
149            "properties": {
150                "default": ({
151                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
152                    schema_obj.ensure_object().insert("description".into(), "Default specifies how much of this capacity is consumed by a request that does not contain an entry for it in DeviceRequest's Capacity.".into());
153                    schema_obj
154                }),
155                "validRange": ({
156                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::CapacityRequestPolicyRange>();
157                    schema_obj.ensure_object().insert("description".into(), "ValidRange defines an acceptable quantity value range in consuming requests.\n\nIf this field is set, Default must be defined and it must fall within the defined ValidRange.\n\nIf the requested amount does not fall within the defined range, the request violates the policy, and this device cannot be allocated.\n\nIf the request doesn't contain this capacity entry, Default value is used.".into());
158                    schema_obj
159                }),
160                "validValues": {
161                    "description": "ValidValues defines a set of acceptable quantity values in consuming requests.\n\nMust not contain more than 10 entries. Must be sorted in ascending order.\n\nIf this field is set, Default must be defined and it must be included in ValidValues list.\n\nIf the requested amount does not match any valid value but smaller than some valid values, the scheduler calculates the smallest valid value that is greater than or equal to the request. That is: min(ceil(requestedValue) ∈ validValues), where requestedValue ≤ max(validValues).\n\nIf the requested amount exceeds all valid values, the request violates the policy, and this device cannot be allocated.",
162                    "type": "array",
163                    "items": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
164                },
165            },
166        })
167    }
168}