k8s_openapi/v1_34/api/resource/v1beta1/
device_request.rs

1// Generated from definition io.k8s.api.resource.v1beta1.DeviceRequest
2
3/// 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.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceRequest {
6    /// 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.
7    ///
8    /// This field can only be set when deviceClassName is set and no subrequests are specified in the firstAvailable list.
9    ///
10    /// This 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.
11    pub admin_access: Option<bool>,
12
13    /// AllocationMode and its related fields define how devices are allocated to satisfy this request. Supported values are:
14    ///
15    /// - ExactCount: This request is for a specific number of devices.
16    ///   This is the default. The exact number is provided in the
17    ///   count field.
18    ///
19    /// - All: This request is for all of the matching devices in a pool.
20    ///   At least one device must exist on the node for the allocation to succeed.
21    ///   Allocation will fail if some devices are already allocated,
22    ///   unless adminAccess is requested.
23    ///
24    /// If 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.
25    ///
26    /// This field can only be set when deviceClassName is set and no subrequests are specified in the firstAvailable list.
27    ///
28    /// More modes may get added in the future. Clients must refuse to handle requests with unknown modes.
29    pub allocation_mode: Option<std::string::String>,
30
31    /// Capacity define resource requirements against each capacity.
32    ///
33    /// If this field is unset and the device supports multiple allocations, the default value will be applied to each capacity according to requestPolicy. For the capacity that has no requestPolicy, default is the full capacity value.
34    ///
35    /// Applies to each device allocation. If Count \> 1, the request fails if there aren't enough devices that meet the requirements. If AllocationMode is set to All, the request fails if there are devices that otherwise match the request, and have this capacity, with a value \>= the requested amount, but which cannot be allocated to this request.
36    pub capacity: Option<crate::api::resource::v1beta1::CapacityRequirements>,
37
38    /// 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.
39    ///
40    /// This field can only be set when deviceClassName is set and no subrequests are specified in the firstAvailable list.
41    pub count: Option<i64>,
42
43    /// DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this request.
44    ///
45    /// A 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.
46    ///
47    /// Administrators 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.
48    pub device_class_name: Option<std::string::String>,
49
50    /// 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.
51    ///
52    /// This field may only be set in the entries of DeviceClaim.Requests.
53    ///
54    /// DRA 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.
55    pub first_available: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSubRequest>>,
56
57    /// Name can be used to reference this request in a pod.spec.containers\[\].resources.claims entry and in a constraint of the claim.
58    ///
59    /// Must be a DNS label and unique among all DeviceRequests in a ResourceClaim.
60    pub name: std::string::String,
61
62    /// 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.
63    ///
64    /// This field can only be set when deviceClassName is set and no subrequests are specified in the firstAvailable list.
65    pub selectors: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSelector>>,
66
67    /// If specified, the request's tolerations.
68    ///
69    /// Tolerations for NoSchedule are required to allocate a device which has a taint with that effect. The same applies to NoExecute.
70    ///
71    /// In 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.
72    ///
73    /// The maximum number of tolerations is 16.
74    ///
75    /// This field can only be set when deviceClassName is set and no subrequests are specified in the firstAvailable list.
76    ///
77    /// This is an alpha field and requires enabling the DRADeviceTaints feature gate.
78    pub tolerations: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceToleration>>,
79}
80
81impl crate::DeepMerge for DeviceRequest {
82    fn merge_from(&mut self, other: Self) {
83        crate::DeepMerge::merge_from(&mut self.admin_access, other.admin_access);
84        crate::DeepMerge::merge_from(&mut self.allocation_mode, other.allocation_mode);
85        crate::DeepMerge::merge_from(&mut self.capacity, other.capacity);
86        crate::DeepMerge::merge_from(&mut self.count, other.count);
87        crate::DeepMerge::merge_from(&mut self.device_class_name, other.device_class_name);
88        crate::merge_strategies::list::atomic(&mut self.first_available, other.first_available);
89        crate::DeepMerge::merge_from(&mut self.name, other.name);
90        crate::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
91        crate::merge_strategies::list::atomic(&mut self.tolerations, other.tolerations);
92    }
93}
94
95impl<'de> crate::serde::Deserialize<'de> for DeviceRequest {
96    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
97        #[allow(non_camel_case_types)]
98        enum Field {
99            Key_admin_access,
100            Key_allocation_mode,
101            Key_capacity,
102            Key_count,
103            Key_device_class_name,
104            Key_first_available,
105            Key_name,
106            Key_selectors,
107            Key_tolerations,
108            Other,
109        }
110
111        impl<'de> crate::serde::Deserialize<'de> for Field {
112            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
113                struct Visitor;
114
115                impl crate::serde::de::Visitor<'_> for Visitor {
116                    type Value = Field;
117
118                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
119                        f.write_str("field identifier")
120                    }
121
122                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
123                        Ok(match v {
124                            "adminAccess" => Field::Key_admin_access,
125                            "allocationMode" => Field::Key_allocation_mode,
126                            "capacity" => Field::Key_capacity,
127                            "count" => Field::Key_count,
128                            "deviceClassName" => Field::Key_device_class_name,
129                            "firstAvailable" => Field::Key_first_available,
130                            "name" => Field::Key_name,
131                            "selectors" => Field::Key_selectors,
132                            "tolerations" => Field::Key_tolerations,
133                            _ => Field::Other,
134                        })
135                    }
136                }
137
138                deserializer.deserialize_identifier(Visitor)
139            }
140        }
141
142        struct Visitor;
143
144        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
145            type Value = DeviceRequest;
146
147            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
148                f.write_str("DeviceRequest")
149            }
150
151            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
152                let mut value_admin_access: Option<bool> = None;
153                let mut value_allocation_mode: Option<std::string::String> = None;
154                let mut value_capacity: Option<crate::api::resource::v1beta1::CapacityRequirements> = None;
155                let mut value_count: Option<i64> = None;
156                let mut value_device_class_name: Option<std::string::String> = None;
157                let mut value_first_available: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSubRequest>> = None;
158                let mut value_name: Option<std::string::String> = None;
159                let mut value_selectors: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSelector>> = None;
160                let mut value_tolerations: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceToleration>> = None;
161
162                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
163                    match key {
164                        Field::Key_admin_access => value_admin_access = crate::serde::de::MapAccess::next_value(&mut map)?,
165                        Field::Key_allocation_mode => value_allocation_mode = crate::serde::de::MapAccess::next_value(&mut map)?,
166                        Field::Key_capacity => value_capacity = crate::serde::de::MapAccess::next_value(&mut map)?,
167                        Field::Key_count => value_count = crate::serde::de::MapAccess::next_value(&mut map)?,
168                        Field::Key_device_class_name => value_device_class_name = crate::serde::de::MapAccess::next_value(&mut map)?,
169                        Field::Key_first_available => value_first_available = crate::serde::de::MapAccess::next_value(&mut map)?,
170                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
171                        Field::Key_selectors => value_selectors = crate::serde::de::MapAccess::next_value(&mut map)?,
172                        Field::Key_tolerations => value_tolerations = crate::serde::de::MapAccess::next_value(&mut map)?,
173                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
174                    }
175                }
176
177                Ok(DeviceRequest {
178                    admin_access: value_admin_access,
179                    allocation_mode: value_allocation_mode,
180                    capacity: value_capacity,
181                    count: value_count,
182                    device_class_name: value_device_class_name,
183                    first_available: value_first_available,
184                    name: value_name.unwrap_or_default(),
185                    selectors: value_selectors,
186                    tolerations: value_tolerations,
187                })
188            }
189        }
190
191        deserializer.deserialize_struct(
192            "DeviceRequest",
193            &[
194                "adminAccess",
195                "allocationMode",
196                "capacity",
197                "count",
198                "deviceClassName",
199                "firstAvailable",
200                "name",
201                "selectors",
202                "tolerations",
203            ],
204            Visitor,
205        )
206    }
207}
208
209impl crate::serde::Serialize for DeviceRequest {
210    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
211        let mut state = serializer.serialize_struct(
212            "DeviceRequest",
213            1 +
214            self.admin_access.as_ref().map_or(0, |_| 1) +
215            self.allocation_mode.as_ref().map_or(0, |_| 1) +
216            self.capacity.as_ref().map_or(0, |_| 1) +
217            self.count.as_ref().map_or(0, |_| 1) +
218            self.device_class_name.as_ref().map_or(0, |_| 1) +
219            self.first_available.as_ref().map_or(0, |_| 1) +
220            self.selectors.as_ref().map_or(0, |_| 1) +
221            self.tolerations.as_ref().map_or(0, |_| 1),
222        )?;
223        if let Some(value) = &self.admin_access {
224            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "adminAccess", value)?;
225        }
226        if let Some(value) = &self.allocation_mode {
227            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationMode", value)?;
228        }
229        if let Some(value) = &self.capacity {
230            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "capacity", value)?;
231        }
232        if let Some(value) = &self.count {
233            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "count", value)?;
234        }
235        if let Some(value) = &self.device_class_name {
236            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deviceClassName", value)?;
237        }
238        if let Some(value) = &self.first_available {
239            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "firstAvailable", value)?;
240        }
241        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
242        if let Some(value) = &self.selectors {
243            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
244        }
245        if let Some(value) = &self.tolerations {
246            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerations", value)?;
247        }
248        crate::serde::ser::SerializeStruct::end(state)
249    }
250}
251
252#[cfg(feature = "schemars")]
253impl crate::schemars::JsonSchema for DeviceRequest {
254    fn schema_name() -> std::borrow::Cow<'static, str> {
255        "io.k8s.api.resource.v1beta1.DeviceRequest".into()
256    }
257
258    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
259        crate::schemars::json_schema!({
260            "description": "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.",
261            "type": "object",
262            "properties": {
263                "adminAccess": {
264                    "description": "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.",
265                    "type": "boolean",
266                },
267                "allocationMode": {
268                    "description": "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.",
269                    "type": "string",
270                },
271                "capacity": ({
272                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::CapacityRequirements>();
273                    schema_obj.ensure_object().insert("description".into(), "Capacity define resource requirements against each capacity.\n\nIf this field is unset and the device supports multiple allocations, the default value will be applied to each capacity according to requestPolicy. For the capacity that has no requestPolicy, default is the full capacity value.\n\nApplies to each device allocation. If Count > 1, the request fails if there aren't enough devices that meet the requirements. If AllocationMode is set to All, the request fails if there are devices that otherwise match the request, and have this capacity, with a value >= the requested amount, but which cannot be allocated to this request.".into());
274                    schema_obj
275                }),
276                "count": {
277                    "description": "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.",
278                    "type": "integer",
279                    "format": "int64",
280                },
281                "deviceClassName": {
282                    "description": "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.",
283                    "type": "string",
284                },
285                "firstAvailable": {
286                    "description": "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.",
287                    "type": "array",
288                    "items": (__gen.subschema_for::<crate::api::resource::v1beta1::DeviceSubRequest>()),
289                },
290                "name": {
291                    "description": "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.",
292                    "type": "string",
293                },
294                "selectors": {
295                    "description": "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.",
296                    "type": "array",
297                    "items": (__gen.subschema_for::<crate::api::resource::v1beta1::DeviceSelector>()),
298                },
299                "tolerations": {
300                    "description": "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.",
301                    "type": "array",
302                    "items": (__gen.subschema_for::<crate::api::resource::v1beta1::DeviceToleration>()),
303                },
304            },
305            "required": [
306                "name",
307            ],
308        })
309    }
310}