1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceRequestAllocationResult {
6 pub admin_access: Option<bool>,
10
11 pub binding_conditions: Option<std::vec::Vec<std::string::String>>,
15
16 pub binding_failure_conditions: Option<std::vec::Vec<std::string::String>>,
20
21 pub consumed_capacity: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
27
28 pub device: std::string::String,
30
31 pub driver: std::string::String,
35
36 pub pool: std::string::String,
40
41 pub request: std::string::String,
45
46 pub share_id: Option<std::string::String>,
48
49 pub tolerations: Option<std::vec::Vec<crate::api::resource::v1::DeviceToleration>>,
55}
56
57impl crate::DeepMerge for DeviceRequestAllocationResult {
58 fn merge_from(&mut self, other: Self) {
59 crate::DeepMerge::merge_from(&mut self.admin_access, other.admin_access);
60 crate::merge_strategies::list::atomic(&mut self.binding_conditions, other.binding_conditions);
61 crate::merge_strategies::list::atomic(&mut self.binding_failure_conditions, other.binding_failure_conditions);
62 crate::merge_strategies::map::granular(&mut self.consumed_capacity, other.consumed_capacity, |current_item, other_item| {
63 crate::DeepMerge::merge_from(current_item, other_item);
64 });
65 crate::DeepMerge::merge_from(&mut self.device, other.device);
66 crate::DeepMerge::merge_from(&mut self.driver, other.driver);
67 crate::DeepMerge::merge_from(&mut self.pool, other.pool);
68 crate::DeepMerge::merge_from(&mut self.request, other.request);
69 crate::DeepMerge::merge_from(&mut self.share_id, other.share_id);
70 crate::merge_strategies::list::atomic(&mut self.tolerations, other.tolerations);
71 }
72}
73
74impl<'de> crate::serde::Deserialize<'de> for DeviceRequestAllocationResult {
75 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
76 #[allow(non_camel_case_types)]
77 enum Field {
78 Key_admin_access,
79 Key_binding_conditions,
80 Key_binding_failure_conditions,
81 Key_consumed_capacity,
82 Key_device,
83 Key_driver,
84 Key_pool,
85 Key_request,
86 Key_share_id,
87 Key_tolerations,
88 Other,
89 }
90
91 impl<'de> crate::serde::Deserialize<'de> for Field {
92 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
93 struct Visitor;
94
95 impl crate::serde::de::Visitor<'_> for Visitor {
96 type Value = Field;
97
98 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
99 f.write_str("field identifier")
100 }
101
102 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
103 Ok(match v {
104 "adminAccess" => Field::Key_admin_access,
105 "bindingConditions" => Field::Key_binding_conditions,
106 "bindingFailureConditions" => Field::Key_binding_failure_conditions,
107 "consumedCapacity" => Field::Key_consumed_capacity,
108 "device" => Field::Key_device,
109 "driver" => Field::Key_driver,
110 "pool" => Field::Key_pool,
111 "request" => Field::Key_request,
112 "shareID" => Field::Key_share_id,
113 "tolerations" => Field::Key_tolerations,
114 _ => Field::Other,
115 })
116 }
117 }
118
119 deserializer.deserialize_identifier(Visitor)
120 }
121 }
122
123 struct Visitor;
124
125 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
126 type Value = DeviceRequestAllocationResult;
127
128 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
129 f.write_str("DeviceRequestAllocationResult")
130 }
131
132 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
133 let mut value_admin_access: Option<bool> = None;
134 let mut value_binding_conditions: Option<std::vec::Vec<std::string::String>> = None;
135 let mut value_binding_failure_conditions: Option<std::vec::Vec<std::string::String>> = None;
136 let mut value_consumed_capacity: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
137 let mut value_device: Option<std::string::String> = None;
138 let mut value_driver: Option<std::string::String> = None;
139 let mut value_pool: Option<std::string::String> = None;
140 let mut value_request: Option<std::string::String> = None;
141 let mut value_share_id: Option<std::string::String> = None;
142 let mut value_tolerations: Option<std::vec::Vec<crate::api::resource::v1::DeviceToleration>> = None;
143
144 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
145 match key {
146 Field::Key_admin_access => value_admin_access = crate::serde::de::MapAccess::next_value(&mut map)?,
147 Field::Key_binding_conditions => value_binding_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
148 Field::Key_binding_failure_conditions => value_binding_failure_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
149 Field::Key_consumed_capacity => value_consumed_capacity = crate::serde::de::MapAccess::next_value(&mut map)?,
150 Field::Key_device => value_device = crate::serde::de::MapAccess::next_value(&mut map)?,
151 Field::Key_driver => value_driver = crate::serde::de::MapAccess::next_value(&mut map)?,
152 Field::Key_pool => value_pool = crate::serde::de::MapAccess::next_value(&mut map)?,
153 Field::Key_request => value_request = crate::serde::de::MapAccess::next_value(&mut map)?,
154 Field::Key_share_id => value_share_id = crate::serde::de::MapAccess::next_value(&mut map)?,
155 Field::Key_tolerations => value_tolerations = crate::serde::de::MapAccess::next_value(&mut map)?,
156 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
157 }
158 }
159
160 Ok(DeviceRequestAllocationResult {
161 admin_access: value_admin_access,
162 binding_conditions: value_binding_conditions,
163 binding_failure_conditions: value_binding_failure_conditions,
164 consumed_capacity: value_consumed_capacity,
165 device: value_device.unwrap_or_default(),
166 driver: value_driver.unwrap_or_default(),
167 pool: value_pool.unwrap_or_default(),
168 request: value_request.unwrap_or_default(),
169 share_id: value_share_id,
170 tolerations: value_tolerations,
171 })
172 }
173 }
174
175 deserializer.deserialize_struct(
176 "DeviceRequestAllocationResult",
177 &[
178 "adminAccess",
179 "bindingConditions",
180 "bindingFailureConditions",
181 "consumedCapacity",
182 "device",
183 "driver",
184 "pool",
185 "request",
186 "shareID",
187 "tolerations",
188 ],
189 Visitor,
190 )
191 }
192}
193
194impl crate::serde::Serialize for DeviceRequestAllocationResult {
195 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
196 let mut state = serializer.serialize_struct(
197 "DeviceRequestAllocationResult",
198 4 +
199 self.admin_access.as_ref().map_or(0, |_| 1) +
200 self.binding_conditions.as_ref().map_or(0, |_| 1) +
201 self.binding_failure_conditions.as_ref().map_or(0, |_| 1) +
202 self.consumed_capacity.as_ref().map_or(0, |_| 1) +
203 self.share_id.as_ref().map_or(0, |_| 1) +
204 self.tolerations.as_ref().map_or(0, |_| 1),
205 )?;
206 if let Some(value) = &self.admin_access {
207 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "adminAccess", value)?;
208 }
209 if let Some(value) = &self.binding_conditions {
210 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "bindingConditions", value)?;
211 }
212 if let Some(value) = &self.binding_failure_conditions {
213 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "bindingFailureConditions", value)?;
214 }
215 if let Some(value) = &self.consumed_capacity {
216 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "consumedCapacity", value)?;
217 }
218 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "device", &self.device)?;
219 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "driver", &self.driver)?;
220 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pool", &self.pool)?;
221 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "request", &self.request)?;
222 if let Some(value) = &self.share_id {
223 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "shareID", value)?;
224 }
225 if let Some(value) = &self.tolerations {
226 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerations", value)?;
227 }
228 crate::serde::ser::SerializeStruct::end(state)
229 }
230}
231
232#[cfg(feature = "schemars")]
233impl crate::schemars::JsonSchema for DeviceRequestAllocationResult {
234 fn schema_name() -> std::borrow::Cow<'static, str> {
235 "io.k8s.api.resource.v1.DeviceRequestAllocationResult".into()
236 }
237
238 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
239 crate::schemars::json_schema!({
240 "description": "DeviceRequestAllocationResult contains the allocation result for one request.",
241 "type": "object",
242 "properties": {
243 "adminAccess": {
244 "description": "AdminAccess indicates that this device was allocated for administrative access. See the corresponding request field for a definition of mode.\n\nAdmin access is disabled if this field is unset or set to false, otherwise it is enabled.",
245 "type": "boolean",
246 },
247 "bindingConditions": {
248 "description": "BindingConditions contains a copy of the BindingConditions from the corresponding ResourceSlice at the time of allocation.\n\nThis is a beta field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gates.",
249 "type": "array",
250 "items": {
251 "type": "string",
252 },
253 },
254 "bindingFailureConditions": {
255 "description": "BindingFailureConditions contains a copy of the BindingFailureConditions from the corresponding ResourceSlice at the time of allocation.\n\nThis is a beta field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gates.",
256 "type": "array",
257 "items": {
258 "type": "string",
259 },
260 },
261 "consumedCapacity": {
262 "description": "ConsumedCapacity tracks the amount of capacity consumed per device as part of the claim request. The consumed amount may differ from the requested amount: it is rounded up to the nearest valid value based on the device’s requestPolicy if applicable (i.e., may not be less than the requested amount).\n\nThe total consumed capacity for each device must not exceed the DeviceCapacity's Value.\n\nThis field is populated only for devices that allow multiple allocations. All capacity entries are included, even if the consumed amount is zero.",
263 "type": "object",
264 "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
265 },
266 "device": {
267 "description": "Device references one device instance via its name in the driver's resource pool. It must be a DNS label.",
268 "type": "string",
269 },
270 "driver": {
271 "description": "Driver specifies the name of the DRA driver whose kubelet plugin should be invoked to process the allocation once the claim is needed on a node.\n\nMust be a DNS subdomain and should end with a DNS domain owned by the vendor of the driver. It should use only lower case characters.",
272 "type": "string",
273 },
274 "pool": {
275 "description": "This name together with the driver name and the device name field identify which device was allocated (`<driver name>/<pool name>/<device name>`).\n\nMust not be longer than 253 characters and may contain one or more DNS sub-domains separated by slashes.",
276 "type": "string",
277 },
278 "request": {
279 "description": "Request is the name of the request in the claim which caused this device to be allocated. If it references a subrequest in the firstAvailable list on a DeviceRequest, this field must include both the name of the main request and the subrequest using the format <main request>/<subrequest>.\n\nMultiple devices may have been allocated per request.",
280 "type": "string",
281 },
282 "shareID": {
283 "description": "ShareID uniquely identifies an individual allocation share of the device, used when the device supports multiple simultaneous allocations. It serves as an additional map key to differentiate concurrent shares of the same device.",
284 "type": "string",
285 },
286 "tolerations": {
287 "description": "A copy of all tolerations specified in the request at the time when the device got allocated.\n\nThe maximum number of tolerations is 16.\n\nThis is a beta field and requires enabling the DRADeviceTaints feature gate.",
288 "type": "array",
289 "items": (__gen.subschema_for::<crate::api::resource::v1::DeviceToleration>()),
290 },
291 },
292 "required": [
293 "device",
294 "driver",
295 "pool",
296 "request",
297 ],
298 })
299 }
300}
301
302#[cfg(feature = "schemars08")]
303impl crate::schemars08::JsonSchema for DeviceRequestAllocationResult {
304 fn schema_name() -> std::string::String {
305 "io.k8s.api.resource.v1.DeviceRequestAllocationResult".into()
306 }
307
308 fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
309 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
310 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
311 description: Some("DeviceRequestAllocationResult contains the allocation result for one request.".into()),
312 ..Default::default()
313 })),
314 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
315 object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
316 properties: [
317 (
318 "adminAccess".into(),
319 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
320 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
321 description: Some("AdminAccess indicates that this device was allocated for administrative access. See the corresponding request field for a definition of mode.\n\nAdmin access is disabled if this field is unset or set to false, otherwise it is enabled.".into()),
322 ..Default::default()
323 })),
324 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Boolean))),
325 ..Default::default()
326 }),
327 ),
328 (
329 "bindingConditions".into(),
330 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
331 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
332 description: Some("BindingConditions contains a copy of the BindingConditions from the corresponding ResourceSlice at the time of allocation.\n\nThis is a beta field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gates.".into()),
333 ..Default::default()
334 })),
335 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
336 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
337 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
338 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
339 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
340 ..Default::default()
341 })
342 ))),
343 ..Default::default()
344 })),
345 ..Default::default()
346 }),
347 ),
348 (
349 "bindingFailureConditions".into(),
350 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
351 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
352 description: Some("BindingFailureConditions contains a copy of the BindingFailureConditions from the corresponding ResourceSlice at the time of allocation.\n\nThis is a beta field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gates.".into()),
353 ..Default::default()
354 })),
355 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
356 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
357 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
358 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
359 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
360 ..Default::default()
361 })
362 ))),
363 ..Default::default()
364 })),
365 ..Default::default()
366 }),
367 ),
368 (
369 "consumedCapacity".into(),
370 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
371 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
372 description: Some("ConsumedCapacity tracks the amount of capacity consumed per device as part of the claim request. The consumed amount may differ from the requested amount: it is rounded up to the nearest valid value based on the device’s requestPolicy if applicable (i.e., may not be less than the requested amount).\n\nThe total consumed capacity for each device must not exceed the DeviceCapacity's Value.\n\nThis field is populated only for devices that allow multiple allocations. All capacity entries are included, even if the consumed amount is zero.".into()),
373 ..Default::default()
374 })),
375 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
376 object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
377 additional_properties: Some(std::boxed::Box::new(__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>())),
378 ..Default::default()
379 })),
380 ..Default::default()
381 }),
382 ),
383 (
384 "device".into(),
385 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
386 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
387 description: Some("Device references one device instance via its name in the driver's resource pool. It must be a DNS label.".into()),
388 ..Default::default()
389 })),
390 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
391 ..Default::default()
392 }),
393 ),
394 (
395 "driver".into(),
396 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
397 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
398 description: Some("Driver specifies the name of the DRA driver whose kubelet plugin should be invoked to process the allocation once the claim is needed on a node.\n\nMust be a DNS subdomain and should end with a DNS domain owned by the vendor of the driver. It should use only lower case characters.".into()),
399 ..Default::default()
400 })),
401 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
402 ..Default::default()
403 }),
404 ),
405 (
406 "pool".into(),
407 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
408 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
409 description: Some("This name together with the driver name and the device name field identify which device was allocated (`<driver name>/<pool name>/<device name>`).\n\nMust not be longer than 253 characters and may contain one or more DNS sub-domains separated by slashes.".into()),
410 ..Default::default()
411 })),
412 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
413 ..Default::default()
414 }),
415 ),
416 (
417 "request".into(),
418 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
419 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
420 description: Some("Request is the name of the request in the claim which caused this device to be allocated. If it references a subrequest in the firstAvailable list on a DeviceRequest, this field must include both the name of the main request and the subrequest using the format <main request>/<subrequest>.\n\nMultiple devices may have been allocated per request.".into()),
421 ..Default::default()
422 })),
423 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
424 ..Default::default()
425 }),
426 ),
427 (
428 "shareID".into(),
429 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
430 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
431 description: Some("ShareID uniquely identifies an individual allocation share of the device, used when the device supports multiple simultaneous allocations. It serves as an additional map key to differentiate concurrent shares of the same device.".into()),
432 ..Default::default()
433 })),
434 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
435 ..Default::default()
436 }),
437 ),
438 (
439 "tolerations".into(),
440 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
441 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
442 description: Some("A copy of all tolerations specified in the request at the time when the device got allocated.\n\nThe maximum number of tolerations is 16.\n\nThis is a beta field and requires enabling the DRADeviceTaints feature gate.".into()),
443 ..Default::default()
444 })),
445 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
446 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
447 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1::DeviceToleration>()))),
448 ..Default::default()
449 })),
450 ..Default::default()
451 }),
452 ),
453 ].into(),
454 required: [
455 "device".into(),
456 "driver".into(),
457 "pool".into(),
458 "request".into(),
459 ].into(),
460 ..Default::default()
461 })),
462 ..Default::default()
463 })
464 }
465}