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\nThis is an alpha field and requires enabling the DRAAdminAccess feature gate. Admin 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 an alpha 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 an alpha 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.",
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 an alpha 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}