k8s_openapi/v1_34/api/resource/v1beta1/
capacity_request_policy_range.rs1#[derive(Clone, Debug, Default, PartialEq)]
12pub struct CapacityRequestPolicyRange {
13 pub max: Option<crate::apimachinery::pkg::api::resource::Quantity>,
17
18 pub min: crate::apimachinery::pkg::api::resource::Quantity,
22
23 pub step: Option<crate::apimachinery::pkg::api::resource::Quantity>,
27}
28
29impl crate::DeepMerge for CapacityRequestPolicyRange {
30 fn merge_from(&mut self, other: Self) {
31 crate::DeepMerge::merge_from(&mut self.max, other.max);
32 crate::DeepMerge::merge_from(&mut self.min, other.min);
33 crate::DeepMerge::merge_from(&mut self.step, other.step);
34 }
35}
36
37impl<'de> crate::serde::Deserialize<'de> for CapacityRequestPolicyRange {
38 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
39 #[allow(non_camel_case_types)]
40 enum Field {
41 Key_max,
42 Key_min,
43 Key_step,
44 Other,
45 }
46
47 impl<'de> crate::serde::Deserialize<'de> for Field {
48 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
49 struct Visitor;
50
51 impl crate::serde::de::Visitor<'_> for Visitor {
52 type Value = Field;
53
54 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
55 f.write_str("field identifier")
56 }
57
58 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
59 Ok(match v {
60 "max" => Field::Key_max,
61 "min" => Field::Key_min,
62 "step" => Field::Key_step,
63 _ => Field::Other,
64 })
65 }
66 }
67
68 deserializer.deserialize_identifier(Visitor)
69 }
70 }
71
72 struct Visitor;
73
74 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
75 type Value = CapacityRequestPolicyRange;
76
77 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
78 f.write_str("CapacityRequestPolicyRange")
79 }
80
81 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
82 let mut value_max: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
83 let mut value_min: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
84 let mut value_step: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
85
86 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
87 match key {
88 Field::Key_max => value_max = crate::serde::de::MapAccess::next_value(&mut map)?,
89 Field::Key_min => value_min = crate::serde::de::MapAccess::next_value(&mut map)?,
90 Field::Key_step => value_step = crate::serde::de::MapAccess::next_value(&mut map)?,
91 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
92 }
93 }
94
95 Ok(CapacityRequestPolicyRange {
96 max: value_max,
97 min: value_min.unwrap_or_default(),
98 step: value_step,
99 })
100 }
101 }
102
103 deserializer.deserialize_struct(
104 "CapacityRequestPolicyRange",
105 &[
106 "max",
107 "min",
108 "step",
109 ],
110 Visitor,
111 )
112 }
113}
114
115impl crate::serde::Serialize for CapacityRequestPolicyRange {
116 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
117 let mut state = serializer.serialize_struct(
118 "CapacityRequestPolicyRange",
119 1 +
120 self.max.as_ref().map_or(0, |_| 1) +
121 self.step.as_ref().map_or(0, |_| 1),
122 )?;
123 if let Some(value) = &self.max {
124 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "max", value)?;
125 }
126 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "min", &self.min)?;
127 if let Some(value) = &self.step {
128 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "step", value)?;
129 }
130 crate::serde::ser::SerializeStruct::end(state)
131 }
132}
133
134#[cfg(feature = "schemars")]
135impl crate::schemars::JsonSchema for CapacityRequestPolicyRange {
136 fn schema_name() -> std::borrow::Cow<'static, str> {
137 "io.k8s.api.resource.v1beta1.CapacityRequestPolicyRange".into()
138 }
139
140 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
141 crate::schemars::json_schema!({
142 "description": "CapacityRequestPolicyRange defines a valid range for consumable capacity values.\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.",
143 "type": "object",
144 "properties": {
145 "max": ({
146 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
147 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());
148 schema_obj
149 }),
150 "min": ({
151 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
152 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());
153 schema_obj
154 }),
155 "step": ({
156 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
157 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());
158 schema_obj
159 }),
160 },
161 "required": [
162 "min",
163 ],
164 })
165 }
166}