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 skip_node_operations: Option<std::vec::Vec<std::string::String>>,
51
52 pub tolerations: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceToleration>>,
58}
59
60impl crate::DeepMerge for DeviceRequestAllocationResult {
61 fn merge_from(&mut self, other: Self) {
62 crate::DeepMerge::merge_from(&mut self.admin_access, other.admin_access);
63 crate::merge_strategies::list::atomic(&mut self.binding_conditions, other.binding_conditions);
64 crate::merge_strategies::list::atomic(&mut self.binding_failure_conditions, other.binding_failure_conditions);
65 crate::merge_strategies::map::granular(&mut self.consumed_capacity, other.consumed_capacity, |current_item, other_item| {
66 crate::DeepMerge::merge_from(current_item, other_item);
67 });
68 crate::DeepMerge::merge_from(&mut self.device, other.device);
69 crate::DeepMerge::merge_from(&mut self.driver, other.driver);
70 crate::DeepMerge::merge_from(&mut self.pool, other.pool);
71 crate::DeepMerge::merge_from(&mut self.request, other.request);
72 crate::DeepMerge::merge_from(&mut self.share_id, other.share_id);
73 crate::merge_strategies::list::set(&mut self.skip_node_operations, other.skip_node_operations);
74 crate::merge_strategies::list::atomic(&mut self.tolerations, other.tolerations);
75 }
76}
77
78impl<'de> crate::serde::Deserialize<'de> for DeviceRequestAllocationResult {
79 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
80 #[allow(non_camel_case_types)]
81 enum Field {
82 Key_admin_access,
83 Key_binding_conditions,
84 Key_binding_failure_conditions,
85 Key_consumed_capacity,
86 Key_device,
87 Key_driver,
88 Key_pool,
89 Key_request,
90 Key_share_id,
91 Key_skip_node_operations,
92 Key_tolerations,
93 Other,
94 }
95
96 impl<'de> crate::serde::Deserialize<'de> for Field {
97 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
98 struct Visitor;
99
100 impl crate::serde::de::Visitor<'_> for Visitor {
101 type Value = Field;
102
103 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
104 f.write_str("field identifier")
105 }
106
107 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
108 Ok(match v {
109 "adminAccess" => Field::Key_admin_access,
110 "bindingConditions" => Field::Key_binding_conditions,
111 "bindingFailureConditions" => Field::Key_binding_failure_conditions,
112 "consumedCapacity" => Field::Key_consumed_capacity,
113 "device" => Field::Key_device,
114 "driver" => Field::Key_driver,
115 "pool" => Field::Key_pool,
116 "request" => Field::Key_request,
117 "shareID" => Field::Key_share_id,
118 "skipNodeOperations" => Field::Key_skip_node_operations,
119 "tolerations" => Field::Key_tolerations,
120 _ => Field::Other,
121 })
122 }
123 }
124
125 deserializer.deserialize_identifier(Visitor)
126 }
127 }
128
129 struct Visitor;
130
131 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
132 type Value = DeviceRequestAllocationResult;
133
134 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
135 f.write_str("DeviceRequestAllocationResult")
136 }
137
138 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
139 let mut value_admin_access: Option<bool> = None;
140 let mut value_binding_conditions: Option<std::vec::Vec<std::string::String>> = None;
141 let mut value_binding_failure_conditions: Option<std::vec::Vec<std::string::String>> = None;
142 let mut value_consumed_capacity: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
143 let mut value_device: Option<std::string::String> = None;
144 let mut value_driver: Option<std::string::String> = None;
145 let mut value_pool: Option<std::string::String> = None;
146 let mut value_request: Option<std::string::String> = None;
147 let mut value_share_id: Option<std::string::String> = None;
148 let mut value_skip_node_operations: Option<std::vec::Vec<std::string::String>> = None;
149 let mut value_tolerations: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceToleration>> = None;
150
151 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
152 match key {
153 Field::Key_admin_access => value_admin_access = crate::serde::de::MapAccess::next_value(&mut map)?,
154 Field::Key_binding_conditions => value_binding_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
155 Field::Key_binding_failure_conditions => value_binding_failure_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
156 Field::Key_consumed_capacity => value_consumed_capacity = crate::serde::de::MapAccess::next_value(&mut map)?,
157 Field::Key_device => value_device = crate::serde::de::MapAccess::next_value(&mut map)?,
158 Field::Key_driver => value_driver = crate::serde::de::MapAccess::next_value(&mut map)?,
159 Field::Key_pool => value_pool = crate::serde::de::MapAccess::next_value(&mut map)?,
160 Field::Key_request => value_request = crate::serde::de::MapAccess::next_value(&mut map)?,
161 Field::Key_share_id => value_share_id = crate::serde::de::MapAccess::next_value(&mut map)?,
162 Field::Key_skip_node_operations => value_skip_node_operations = crate::serde::de::MapAccess::next_value(&mut map)?,
163 Field::Key_tolerations => value_tolerations = crate::serde::de::MapAccess::next_value(&mut map)?,
164 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
165 }
166 }
167
168 Ok(DeviceRequestAllocationResult {
169 admin_access: value_admin_access,
170 binding_conditions: value_binding_conditions,
171 binding_failure_conditions: value_binding_failure_conditions,
172 consumed_capacity: value_consumed_capacity,
173 device: value_device.unwrap_or_default(),
174 driver: value_driver.unwrap_or_default(),
175 pool: value_pool.unwrap_or_default(),
176 request: value_request.unwrap_or_default(),
177 share_id: value_share_id,
178 skip_node_operations: value_skip_node_operations,
179 tolerations: value_tolerations,
180 })
181 }
182 }
183
184 deserializer.deserialize_struct(
185 "DeviceRequestAllocationResult",
186 &[
187 "adminAccess",
188 "bindingConditions",
189 "bindingFailureConditions",
190 "consumedCapacity",
191 "device",
192 "driver",
193 "pool",
194 "request",
195 "shareID",
196 "skipNodeOperations",
197 "tolerations",
198 ],
199 Visitor,
200 )
201 }
202}
203
204impl crate::serde::Serialize for DeviceRequestAllocationResult {
205 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
206 let mut state = serializer.serialize_struct(
207 "DeviceRequestAllocationResult",
208 4 +
209 self.admin_access.as_ref().map_or(0, |_| 1) +
210 self.binding_conditions.as_ref().map_or(0, |_| 1) +
211 self.binding_failure_conditions.as_ref().map_or(0, |_| 1) +
212 self.consumed_capacity.as_ref().map_or(0, |_| 1) +
213 self.share_id.as_ref().map_or(0, |_| 1) +
214 self.skip_node_operations.as_ref().map_or(0, |_| 1) +
215 self.tolerations.as_ref().map_or(0, |_| 1),
216 )?;
217 if let Some(value) = &self.admin_access {
218 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "adminAccess", value)?;
219 }
220 if let Some(value) = &self.binding_conditions {
221 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "bindingConditions", value)?;
222 }
223 if let Some(value) = &self.binding_failure_conditions {
224 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "bindingFailureConditions", value)?;
225 }
226 if let Some(value) = &self.consumed_capacity {
227 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "consumedCapacity", value)?;
228 }
229 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "device", &self.device)?;
230 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "driver", &self.driver)?;
231 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pool", &self.pool)?;
232 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "request", &self.request)?;
233 if let Some(value) = &self.share_id {
234 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "shareID", value)?;
235 }
236 if let Some(value) = &self.skip_node_operations {
237 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "skipNodeOperations", value)?;
238 }
239 if let Some(value) = &self.tolerations {
240 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerations", value)?;
241 }
242 crate::serde::ser::SerializeStruct::end(state)
243 }
244}
245
246#[cfg(feature = "schemars")]
247impl crate::schemars::JsonSchema for DeviceRequestAllocationResult {
248 fn schema_name() -> std::borrow::Cow<'static, str> {
249 "io.k8s.api.resource.v1beta2.DeviceRequestAllocationResult".into()
250 }
251
252 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
253 crate::schemars::json_schema!({
254 "description": "DeviceRequestAllocationResult contains the allocation result for one request.",
255 "type": "object",
256 "properties": {
257 "adminAccess": {
258 "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.",
259 "type": "boolean",
260 },
261 "bindingConditions": {
262 "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.",
263 "type": "array",
264 "items": {
265 "type": "string",
266 },
267 },
268 "bindingFailureConditions": {
269 "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.",
270 "type": "array",
271 "items": {
272 "type": "string",
273 },
274 },
275 "consumedCapacity": {
276 "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.",
277 "type": "object",
278 "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
279 },
280 "device": {
281 "description": "Device references one device instance via its name in the driver's resource pool. It must be a DNS label.",
282 "type": "string",
283 },
284 "driver": {
285 "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.",
286 "type": "string",
287 },
288 "pool": {
289 "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.",
290 "type": "string",
291 },
292 "request": {
293 "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.",
294 "type": "string",
295 },
296 "shareID": {
297 "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.",
298 "type": "string",
299 },
300 "skipNodeOperations": {
301 "description": "SkipNodeOperations lists node-local resource operations (gRPC calls) that will be skipped for this allocated device when determining whether operations are necessary on the node. If all allocated devices for a driver in a claim skip an operation, that gRPC call will be skipped. It is a copy of the ResourceSlice.spec.skipNodeOperations value at the time when the device was allocated.",
302 "type": "array",
303 "items": {
304 "type": "string",
305 },
306 },
307 "tolerations": {
308 "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.",
309 "type": "array",
310 "items": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceToleration>()),
311 },
312 },
313 "required": [
314 "device",
315 "driver",
316 "pool",
317 "request",
318 ],
319 })
320 }
321}