Skip to main content

k8s_openapi/v1_37/api/resource/v1beta1/
capacity_request_policy_range.rs

1// Generated from definition io.k8s.api.resource.v1beta1.CapacityRequestPolicyRange
2
3/// CapacityRequestPolicyRange defines a valid range for consumable capacity values.
4///
5/// If the DRAFractionalCapacityRange feature gate is enabled and at least one of Min, Max, or Step is a fractional quantity (i.e. its value is not an integer), milli-unit arithmetic is used instead, supporting values with up to 3 decimal places (e.g. 100m = 0.1). The largest supported value then is 1000 times smaller compared to using 64-bit integers. Otherwise, all comparisons use 64-bit integer arithmetic via resource.Quantity.Value().
6///
7///   - If the requested amount is less than Min, it is rounded up to the Min value.
8///   - If Step is set and the requested amount is between Min and Max but not aligned with Step,
9///     it will be rounded up to the next value equal to Min + (n * Step).
10///   - If Step is not set, the requested amount is used as-is if it falls within the range Min to Max (if set).
11///   - If the requested or rounded amount exceeds Max (if set), the request does not satisfy the policy,
12///     and the device cannot be allocated.
13#[derive(Clone, Debug, Default, PartialEq)]
14pub struct CapacityRequestPolicyRange {
15    /// Max defines the upper limit for capacity that can be requested.
16    ///
17    /// Max must be less than or equal to the capacity value. Min and requestPolicy.default must be less than or equal to the maximum.
18    pub max: Option<crate::apimachinery::pkg::api::resource::Quantity>,
19
20    /// Min specifies the minimum capacity allowed for a consumption request.
21    ///
22    /// Min must be greater than or equal to zero, and less than or equal to the capacity value. requestPolicy.default must be more than or equal to the minimum.
23    pub min: crate::apimachinery::pkg::api::resource::Quantity,
24
25    /// Step defines the step size between valid capacity amounts within the range.
26    ///
27    /// Max (if set) and requestPolicy.default must be a multiple of Step. Min + Step must be less than or equal to the capacity value.
28    pub step: Option<crate::apimachinery::pkg::api::resource::Quantity>,
29}
30
31impl crate::DeepMerge for CapacityRequestPolicyRange {
32    fn merge_from(&mut self, other: Self) {
33        crate::DeepMerge::merge_from(&mut self.max, other.max);
34        crate::DeepMerge::merge_from(&mut self.min, other.min);
35        crate::DeepMerge::merge_from(&mut self.step, other.step);
36    }
37}
38
39impl<'de> crate::serde::Deserialize<'de> for CapacityRequestPolicyRange {
40    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41        #[allow(non_camel_case_types)]
42        enum Field {
43            Key_max,
44            Key_min,
45            Key_step,
46            Other,
47        }
48
49        impl<'de> crate::serde::Deserialize<'de> for Field {
50            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
51                struct Visitor;
52
53                impl crate::serde::de::Visitor<'_> for Visitor {
54                    type Value = Field;
55
56                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57                        f.write_str("field identifier")
58                    }
59
60                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
61                        Ok(match v {
62                            "max" => Field::Key_max,
63                            "min" => Field::Key_min,
64                            "step" => Field::Key_step,
65                            _ => Field::Other,
66                        })
67                    }
68                }
69
70                deserializer.deserialize_identifier(Visitor)
71            }
72        }
73
74        struct Visitor;
75
76        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
77            type Value = CapacityRequestPolicyRange;
78
79            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
80                f.write_str("CapacityRequestPolicyRange")
81            }
82
83            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
84                let mut value_max: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
85                let mut value_min: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
86                let mut value_step: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
87
88                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
89                    match key {
90                        Field::Key_max => value_max = crate::serde::de::MapAccess::next_value(&mut map)?,
91                        Field::Key_min => value_min = crate::serde::de::MapAccess::next_value(&mut map)?,
92                        Field::Key_step => value_step = crate::serde::de::MapAccess::next_value(&mut map)?,
93                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
94                    }
95                }
96
97                Ok(CapacityRequestPolicyRange {
98                    max: value_max,
99                    min: value_min.unwrap_or_default(),
100                    step: value_step,
101                })
102            }
103        }
104
105        deserializer.deserialize_struct(
106            "CapacityRequestPolicyRange",
107            &[
108                "max",
109                "min",
110                "step",
111            ],
112            Visitor,
113        )
114    }
115}
116
117impl crate::serde::Serialize for CapacityRequestPolicyRange {
118    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
119        let mut state = serializer.serialize_struct(
120            "CapacityRequestPolicyRange",
121            1 +
122            self.max.as_ref().map_or(0, |_| 1) +
123            self.step.as_ref().map_or(0, |_| 1),
124        )?;
125        if let Some(value) = &self.max {
126            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "max", value)?;
127        }
128        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "min", &self.min)?;
129        if let Some(value) = &self.step {
130            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "step", value)?;
131        }
132        crate::serde::ser::SerializeStruct::end(state)
133    }
134}
135
136#[cfg(feature = "schemars")]
137impl crate::schemars::JsonSchema for CapacityRequestPolicyRange {
138    fn schema_name() -> std::borrow::Cow<'static, str> {
139        "io.k8s.api.resource.v1beta1.CapacityRequestPolicyRange".into()
140    }
141
142    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
143        crate::schemars::json_schema!({
144            "description": "CapacityRequestPolicyRange defines a valid range for consumable capacity values.\n\nIf the DRAFractionalCapacityRange feature gate is enabled and at least one of Min, Max, or Step is a fractional quantity (i.e. its value is not an integer), milli-unit arithmetic is used instead, supporting values with up to 3 decimal places (e.g. 100m = 0.1). The largest supported value then is 1000 times smaller compared to using 64-bit integers. Otherwise, all comparisons use 64-bit integer arithmetic via resource.Quantity.Value().\n\n  - If the requested amount is less than Min, it is rounded up to the Min value.\n  - If Step is set and the requested amount is between Min and Max but not aligned with Step,\n    it will be rounded up to the next value equal to Min + (n * Step).\n  - If Step is not set, the requested amount is used as-is if it falls within the range Min to Max (if set).\n  - If the requested or rounded amount exceeds Max (if set), the request does not satisfy the policy,\n    and the device cannot be allocated.",
145            "type": "object",
146            "properties": {
147                "max": ({
148                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
149                    schema_obj.ensure_object().insert("description".into(), "Max defines the upper limit for capacity that can be requested.\n\nMax must be less than or equal to the capacity value. Min and requestPolicy.default must be less than or equal to the maximum.".into());
150                    schema_obj
151                }),
152                "min": ({
153                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
154                    schema_obj.ensure_object().insert("description".into(), "Min specifies the minimum capacity allowed for a consumption request.\n\nMin must be greater than or equal to zero, and less than or equal to the capacity value. requestPolicy.default must be more than or equal to the minimum.".into());
155                    schema_obj
156                }),
157                "step": ({
158                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
159                    schema_obj.ensure_object().insert("description".into(), "Step defines the step size between valid capacity amounts within the range.\n\nMax (if set) and requestPolicy.default must be a multiple of Step. Min + Step must be less than or equal to the capacity value.".into());
160                    schema_obj
161                }),
162            },
163            "required": [
164                "min",
165            ],
166        })
167    }
168}