k8s_openapi/v1_36/api/resource/v1beta1/
resource_claim_status.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceClaimStatus {
6 pub allocation: Option<crate::api::resource::v1beta1::AllocationResult>,
8
9 pub devices: Option<std::vec::Vec<crate::api::resource::v1beta1::AllocatedDeviceStatus>>,
11
12 pub reserved_for: Option<std::vec::Vec<crate::api::resource::v1beta1::ResourceClaimConsumerReference>>,
20}
21
22impl crate::DeepMerge for ResourceClaimStatus {
23 fn merge_from(&mut self, other: Self) {
24 crate::DeepMerge::merge_from(&mut self.allocation, other.allocation);
25 crate::merge_strategies::list::map(
26 &mut self.devices,
27 other.devices,
28 &[|lhs, rhs| lhs.driver == rhs.driver, |lhs, rhs| lhs.device == rhs.device, |lhs, rhs| lhs.pool == rhs.pool, |lhs, rhs| lhs.share_id == rhs.share_id],
29 |current_item, other_item| {
30 crate::DeepMerge::merge_from(current_item, other_item);
31 },
32 );
33 crate::merge_strategies::list::map(
34 &mut self.reserved_for,
35 other.reserved_for,
36 &[|lhs, rhs| lhs.uid == rhs.uid],
37 |current_item, other_item| {
38 crate::DeepMerge::merge_from(current_item, other_item);
39 },
40 );
41 }
42}
43
44impl<'de> crate::serde::Deserialize<'de> for ResourceClaimStatus {
45 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
46 #[allow(non_camel_case_types)]
47 enum Field {
48 Key_allocation,
49 Key_devices,
50 Key_reserved_for,
51 Other,
52 }
53
54 impl<'de> crate::serde::Deserialize<'de> for Field {
55 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
56 struct Visitor;
57
58 impl crate::serde::de::Visitor<'_> for Visitor {
59 type Value = Field;
60
61 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
62 f.write_str("field identifier")
63 }
64
65 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
66 Ok(match v {
67 "allocation" => Field::Key_allocation,
68 "devices" => Field::Key_devices,
69 "reservedFor" => Field::Key_reserved_for,
70 _ => Field::Other,
71 })
72 }
73 }
74
75 deserializer.deserialize_identifier(Visitor)
76 }
77 }
78
79 struct Visitor;
80
81 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
82 type Value = ResourceClaimStatus;
83
84 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
85 f.write_str("ResourceClaimStatus")
86 }
87
88 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
89 let mut value_allocation: Option<crate::api::resource::v1beta1::AllocationResult> = None;
90 let mut value_devices: Option<std::vec::Vec<crate::api::resource::v1beta1::AllocatedDeviceStatus>> = None;
91 let mut value_reserved_for: Option<std::vec::Vec<crate::api::resource::v1beta1::ResourceClaimConsumerReference>> = None;
92
93 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
94 match key {
95 Field::Key_allocation => value_allocation = crate::serde::de::MapAccess::next_value(&mut map)?,
96 Field::Key_devices => value_devices = crate::serde::de::MapAccess::next_value(&mut map)?,
97 Field::Key_reserved_for => value_reserved_for = crate::serde::de::MapAccess::next_value(&mut map)?,
98 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
99 }
100 }
101
102 Ok(ResourceClaimStatus {
103 allocation: value_allocation,
104 devices: value_devices,
105 reserved_for: value_reserved_for,
106 })
107 }
108 }
109
110 deserializer.deserialize_struct(
111 "ResourceClaimStatus",
112 &[
113 "allocation",
114 "devices",
115 "reservedFor",
116 ],
117 Visitor,
118 )
119 }
120}
121
122impl crate::serde::Serialize for ResourceClaimStatus {
123 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
124 let mut state = serializer.serialize_struct(
125 "ResourceClaimStatus",
126 self.allocation.as_ref().map_or(0, |_| 1) +
127 self.devices.as_ref().map_or(0, |_| 1) +
128 self.reserved_for.as_ref().map_or(0, |_| 1),
129 )?;
130 if let Some(value) = &self.allocation {
131 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocation", value)?;
132 }
133 if let Some(value) = &self.devices {
134 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "devices", value)?;
135 }
136 if let Some(value) = &self.reserved_for {
137 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "reservedFor", value)?;
138 }
139 crate::serde::ser::SerializeStruct::end(state)
140 }
141}
142
143#[cfg(feature = "schemars")]
144impl crate::schemars::JsonSchema for ResourceClaimStatus {
145 fn schema_name() -> std::borrow::Cow<'static, str> {
146 "io.k8s.api.resource.v1beta1.ResourceClaimStatus".into()
147 }
148
149 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
150 crate::schemars::json_schema!({
151 "description": "ResourceClaimStatus tracks whether the resource has been allocated and what the result of that was.",
152 "type": "object",
153 "properties": {
154 "allocation": ({
155 let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::AllocationResult>();
156 schema_obj.ensure_object().insert("description".into(), "Allocation is set once the claim has been allocated successfully.".into());
157 schema_obj
158 }),
159 "devices": {
160 "description": "Devices contains the status of each device allocated for this claim, as reported by the driver. This can include driver-specific information. Entries are owned by their respective drivers.",
161 "type": "array",
162 "items": (__gen.subschema_for::<crate::api::resource::v1beta1::AllocatedDeviceStatus>()),
163 },
164 "reservedFor": {
165 "description": "ReservedFor indicates which entities are currently allowed to use the claim. A Pod which references a ResourceClaim which is not reserved for that Pod will not be started. A claim that is in use or might be in use because it has been reserved must not get deallocated.\n\nIn a cluster with multiple scheduler instances, two pods might get scheduled concurrently by different schedulers. When they reference the same ResourceClaim which already has reached its maximum number of consumers, only one pod can be scheduled.\n\nBoth schedulers try to add their pod to the claim.status.reservedFor field, but only the update that reaches the API server first gets stored. The other one fails with an error and the scheduler which issued it knows that it must put the pod back into the queue, waiting for the ResourceClaim to become usable again.\n\nThere can be at most 256 such reservations. This may get increased in the future, but not reduced.",
166 "type": "array",
167 "items": (__gen.subschema_for::<crate::api::resource::v1beta1::ResourceClaimConsumerReference>()),
168 },
169 },
170 })
171 }
172}
173
174#[cfg(feature = "schemars08")]
175impl crate::schemars08::JsonSchema for ResourceClaimStatus {
176 fn schema_name() -> std::string::String {
177 "io.k8s.api.resource.v1beta1.ResourceClaimStatus".into()
178 }
179
180 fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
181 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
182 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
183 description: Some("ResourceClaimStatus tracks whether the resource has been allocated and what the result of that was.".into()),
184 ..Default::default()
185 })),
186 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
187 object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
188 properties: [
189 (
190 "allocation".into(),
191 {
192 let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::AllocationResult>().into_object();
193 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
194 description: Some("Allocation is set once the claim has been allocated successfully.".into()),
195 ..Default::default()
196 }));
197 crate::schemars08::schema::Schema::Object(schema_obj)
198 },
199 ),
200 (
201 "devices".into(),
202 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
203 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
204 description: Some("Devices contains the status of each device allocated for this claim, as reported by the driver. This can include driver-specific information. Entries are owned by their respective drivers.".into()),
205 ..Default::default()
206 })),
207 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
208 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
209 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta1::AllocatedDeviceStatus>()))),
210 ..Default::default()
211 })),
212 ..Default::default()
213 }),
214 ),
215 (
216 "reservedFor".into(),
217 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
218 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
219 description: Some("ReservedFor indicates which entities are currently allowed to use the claim. A Pod which references a ResourceClaim which is not reserved for that Pod will not be started. A claim that is in use or might be in use because it has been reserved must not get deallocated.\n\nIn a cluster with multiple scheduler instances, two pods might get scheduled concurrently by different schedulers. When they reference the same ResourceClaim which already has reached its maximum number of consumers, only one pod can be scheduled.\n\nBoth schedulers try to add their pod to the claim.status.reservedFor field, but only the update that reaches the API server first gets stored. The other one fails with an error and the scheduler which issued it knows that it must put the pod back into the queue, waiting for the ResourceClaim to become usable again.\n\nThere can be at most 256 such reservations. This may get increased in the future, but not reduced.".into()),
220 ..Default::default()
221 })),
222 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
223 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
224 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta1::ResourceClaimConsumerReference>()))),
225 ..Default::default()
226 })),
227 ..Default::default()
228 }),
229 ),
230 ].into(),
231 ..Default::default()
232 })),
233 ..Default::default()
234 })
235 }
236}