1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceRequest {
6 pub admin_access: Option<bool>,
12
13 pub allocation_mode: Option<std::string::String>,
30
31 pub count: Option<i64>,
35
36 pub device_class_name: Option<std::string::String>,
42
43 pub first_available: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSubRequest>>,
49
50 pub name: std::string::String,
54
55 pub selectors: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSelector>>,
59
60 pub tolerations: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceToleration>>,
72}
73
74impl crate::DeepMerge for DeviceRequest {
75 fn merge_from(&mut self, other: Self) {
76 crate::DeepMerge::merge_from(&mut self.admin_access, other.admin_access);
77 crate::DeepMerge::merge_from(&mut self.allocation_mode, other.allocation_mode);
78 crate::DeepMerge::merge_from(&mut self.count, other.count);
79 crate::DeepMerge::merge_from(&mut self.device_class_name, other.device_class_name);
80 crate::merge_strategies::list::atomic(&mut self.first_available, other.first_available);
81 crate::DeepMerge::merge_from(&mut self.name, other.name);
82 crate::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
83 crate::merge_strategies::list::atomic(&mut self.tolerations, other.tolerations);
84 }
85}
86
87impl<'de> crate::serde::Deserialize<'de> for DeviceRequest {
88 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
89 #[allow(non_camel_case_types)]
90 enum Field {
91 Key_admin_access,
92 Key_allocation_mode,
93 Key_count,
94 Key_device_class_name,
95 Key_first_available,
96 Key_name,
97 Key_selectors,
98 Key_tolerations,
99 Other,
100 }
101
102 impl<'de> crate::serde::Deserialize<'de> for Field {
103 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
104 struct Visitor;
105
106 impl crate::serde::de::Visitor<'_> for Visitor {
107 type Value = Field;
108
109 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
110 f.write_str("field identifier")
111 }
112
113 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
114 Ok(match v {
115 "adminAccess" => Field::Key_admin_access,
116 "allocationMode" => Field::Key_allocation_mode,
117 "count" => Field::Key_count,
118 "deviceClassName" => Field::Key_device_class_name,
119 "firstAvailable" => Field::Key_first_available,
120 "name" => Field::Key_name,
121 "selectors" => Field::Key_selectors,
122 "tolerations" => Field::Key_tolerations,
123 _ => Field::Other,
124 })
125 }
126 }
127
128 deserializer.deserialize_identifier(Visitor)
129 }
130 }
131
132 struct Visitor;
133
134 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
135 type Value = DeviceRequest;
136
137 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
138 f.write_str("DeviceRequest")
139 }
140
141 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
142 let mut value_admin_access: Option<bool> = None;
143 let mut value_allocation_mode: Option<std::string::String> = None;
144 let mut value_count: Option<i64> = None;
145 let mut value_device_class_name: Option<std::string::String> = None;
146 let mut value_first_available: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSubRequest>> = None;
147 let mut value_name: Option<std::string::String> = None;
148 let mut value_selectors: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSelector>> = None;
149 let mut value_tolerations: Option<std::vec::Vec<crate::api::resource::v1beta1::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_allocation_mode => value_allocation_mode = crate::serde::de::MapAccess::next_value(&mut map)?,
155 Field::Key_count => value_count = crate::serde::de::MapAccess::next_value(&mut map)?,
156 Field::Key_device_class_name => value_device_class_name = crate::serde::de::MapAccess::next_value(&mut map)?,
157 Field::Key_first_available => value_first_available = crate::serde::de::MapAccess::next_value(&mut map)?,
158 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
159 Field::Key_selectors => value_selectors = crate::serde::de::MapAccess::next_value(&mut map)?,
160 Field::Key_tolerations => value_tolerations = crate::serde::de::MapAccess::next_value(&mut map)?,
161 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
162 }
163 }
164
165 Ok(DeviceRequest {
166 admin_access: value_admin_access,
167 allocation_mode: value_allocation_mode,
168 count: value_count,
169 device_class_name: value_device_class_name,
170 first_available: value_first_available,
171 name: value_name.unwrap_or_default(),
172 selectors: value_selectors,
173 tolerations: value_tolerations,
174 })
175 }
176 }
177
178 deserializer.deserialize_struct(
179 "DeviceRequest",
180 &[
181 "adminAccess",
182 "allocationMode",
183 "count",
184 "deviceClassName",
185 "firstAvailable",
186 "name",
187 "selectors",
188 "tolerations",
189 ],
190 Visitor,
191 )
192 }
193}
194
195impl crate::serde::Serialize for DeviceRequest {
196 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
197 let mut state = serializer.serialize_struct(
198 "DeviceRequest",
199 1 +
200 self.admin_access.as_ref().map_or(0, |_| 1) +
201 self.allocation_mode.as_ref().map_or(0, |_| 1) +
202 self.count.as_ref().map_or(0, |_| 1) +
203 self.device_class_name.as_ref().map_or(0, |_| 1) +
204 self.first_available.as_ref().map_or(0, |_| 1) +
205 self.selectors.as_ref().map_or(0, |_| 1) +
206 self.tolerations.as_ref().map_or(0, |_| 1),
207 )?;
208 if let Some(value) = &self.admin_access {
209 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "adminAccess", value)?;
210 }
211 if let Some(value) = &self.allocation_mode {
212 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationMode", value)?;
213 }
214 if let Some(value) = &self.count {
215 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "count", value)?;
216 }
217 if let Some(value) = &self.device_class_name {
218 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deviceClassName", value)?;
219 }
220 if let Some(value) = &self.first_available {
221 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "firstAvailable", value)?;
222 }
223 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
224 if let Some(value) = &self.selectors {
225 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
226 }
227 if let Some(value) = &self.tolerations {
228 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerations", value)?;
229 }
230 crate::serde::ser::SerializeStruct::end(state)
231 }
232}
233
234#[cfg(feature = "schemars")]
235impl crate::schemars::JsonSchema for DeviceRequest {
236 fn schema_name() -> std::string::String {
237 "io.k8s.api.resource.v1beta1.DeviceRequest".into()
238 }
239
240 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
241 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
242 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
243 description: Some("DeviceRequest is a request for devices required for a claim. This is typically a request for a single resource like a device, but can also ask for several identical devices.".into()),
244 ..Default::default()
245 })),
246 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
247 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
248 properties: [
249 (
250 "adminAccess".into(),
251 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
252 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
253 description: Some("AdminAccess indicates that this is a claim for administrative access to the device(s). Claims with AdminAccess are expected to be used for monitoring or other management services for a device. They ignore all ordinary claims to the device with respect to access modes and any resource allocations.\n\nThis field can only be set when deviceClassName is set and no subrequests are specified in the firstAvailable list.\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.".into()),
254 ..Default::default()
255 })),
256 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Boolean))),
257 ..Default::default()
258 }),
259 ),
260 (
261 "allocationMode".into(),
262 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
263 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
264 description: Some("AllocationMode and its related fields define how devices are allocated to satisfy this request. Supported values are:\n\n- ExactCount: This request is for a specific number of devices.\n This is the default. The exact number is provided in the\n count field.\n\n- All: This request is for all of the matching devices in a pool.\n At least one device must exist on the node for the allocation to succeed.\n Allocation will fail if some devices are already allocated,\n unless adminAccess is requested.\n\nIf AllocationMode is not specified, the default mode is ExactCount. If the mode is ExactCount and count is not specified, the default count is one. Any other requests must specify this field.\n\nThis field can only be set when deviceClassName is set and no subrequests are specified in the firstAvailable list.\n\nMore modes may get added in the future. Clients must refuse to handle requests with unknown modes.".into()),
265 ..Default::default()
266 })),
267 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
268 ..Default::default()
269 }),
270 ),
271 (
272 "count".into(),
273 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
274 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
275 description: Some("Count is used only when the count mode is \"ExactCount\". Must be greater than zero. If AllocationMode is ExactCount and this field is not specified, the default is one.\n\nThis field can only be set when deviceClassName is set and no subrequests are specified in the firstAvailable list.".into()),
276 ..Default::default()
277 })),
278 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
279 format: Some("int64".into()),
280 ..Default::default()
281 }),
282 ),
283 (
284 "deviceClassName".into(),
285 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
286 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
287 description: Some("DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this request.\n\nA class is required if no subrequests are specified in the firstAvailable list and no class can be set if subrequests are specified in the firstAvailable list. Which classes are available depends on the cluster.\n\nAdministrators may use this to restrict which devices may get requested by only installing classes with selectors for permitted devices. If users are free to request anything without restrictions, then administrators can create an empty DeviceClass for users to reference.".into()),
288 ..Default::default()
289 })),
290 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
291 ..Default::default()
292 }),
293 ),
294 (
295 "firstAvailable".into(),
296 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
297 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
298 description: Some("FirstAvailable contains subrequests, of which exactly one will be satisfied by the scheduler to satisfy this request. It tries to satisfy them in the order in which they are listed here. So if there are two entries in the list, the scheduler will only check the second one if it determines that the first one cannot be used.\n\nThis field may only be set in the entries of DeviceClaim.Requests.\n\nDRA does not yet implement scoring, so the scheduler will select the first set of devices that satisfies all the requests in the claim. And if the requirements can be satisfied on more than one node, other scheduling features will determine which node is chosen. This means that the set of devices allocated to a claim might not be the optimal set available to the cluster. Scoring will be implemented later.".into()),
299 ..Default::default()
300 })),
301 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
302 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
303 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta1::DeviceSubRequest>()))),
304 ..Default::default()
305 })),
306 ..Default::default()
307 }),
308 ),
309 (
310 "name".into(),
311 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
312 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
313 description: Some("Name can be used to reference this request in a pod.spec.containers[].resources.claims entry and in a constraint of the claim.\n\nMust be a DNS label and unique among all DeviceRequests in a ResourceClaim.".into()),
314 ..Default::default()
315 })),
316 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
317 ..Default::default()
318 }),
319 ),
320 (
321 "selectors".into(),
322 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
323 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
324 description: Some("Selectors define criteria which must be satisfied by a specific device in order for that device to be considered for this request. All selectors must be satisfied for a device to be considered.\n\nThis field can only be set when deviceClassName is set and no subrequests are specified in the firstAvailable list.".into()),
325 ..Default::default()
326 })),
327 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
328 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
329 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta1::DeviceSelector>()))),
330 ..Default::default()
331 })),
332 ..Default::default()
333 }),
334 ),
335 (
336 "tolerations".into(),
337 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
338 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
339 description: Some("If specified, the request's tolerations.\n\nTolerations for NoSchedule are required to allocate a device which has a taint with that effect. The same applies to NoExecute.\n\nIn addition, should any of the allocated devices get tainted with NoExecute after allocation and that effect is not tolerated, then all pods consuming the ResourceClaim get deleted to evict them. The scheduler will not let new pods reserve the claim while it has these tainted devices. Once all pods are evicted, the claim will get deallocated.\n\nThe maximum number of tolerations is 16.\n\nThis field can only be set when deviceClassName is set and no subrequests are specified in the firstAvailable list.\n\nThis is an alpha field and requires enabling the DRADeviceTaints feature gate.".into()),
340 ..Default::default()
341 })),
342 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
343 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
344 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta1::DeviceToleration>()))),
345 ..Default::default()
346 })),
347 ..Default::default()
348 }),
349 ),
350 ].into(),
351 required: [
352 "name".into(),
353 ].into(),
354 ..Default::default()
355 })),
356 ..Default::default()
357 })
358 }
359}