Skip to main content

k8s_openapi/v1_37/api/resource/v1beta2/
device_sub_request.rs

1// Generated from definition io.k8s.api.resource.v1beta2.DeviceSubRequest
2
3/// DeviceSubRequest describes a request for device provided in the claim.spec.devices.requests\[\].firstAvailable array. Each is typically a request for a single resource like a device, but can also ask for several identical devices.
4///
5/// DeviceSubRequest is similar to ExactDeviceRequest, but doesn't expose the AdminAccess field as that one is only supported when requesting a specific device.
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct DeviceSubRequest {
8    /// AllocationMode and its related fields define how devices are allocated to satisfy this subrequest. Supported values are:
9    ///
10    /// - ExactCount: This request is for a specific number of devices.
11    ///   This is the default. The exact number is provided in the
12    ///   count field.
13    ///
14    /// - All: This subrequest is for all of the matching devices in a pool.
15    ///   Allocation will fail if some devices are already allocated,
16    ///   unless adminAccess is requested.
17    ///
18    /// 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 subrequests must specify this field.
19    ///
20    /// More modes may get added in the future. Clients must refuse to handle requests with unknown modes.
21    pub allocation_mode: Option<std::string::String>,
22
23    /// Capacity define resource requirements against each capacity.
24    ///
25    /// 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.
26    ///
27    /// 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.
28    pub capacity: Option<crate::api::resource::v1beta2::CapacityRequirements>,
29
30    /// 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.
31    pub count: Option<i64>,
32
33    /// DerivedAttributes defines a set of virtual attributes computed via CEL expressions for each candidate device. These virtual attributes can be referenced in `.devices.constraints` to align and match different devices (e.g., co-allocating a GPU and a NIC on the same NUMA node) even if their drivers publish different attributes. Derived attributes are not available via `device.attributes` in the CEL environment when evaluating selector expressions.
34    ///
35    /// Derived attributes allow you to extract, transform, or normalize topology information (such as extracting a NUMA index from a complex topology string or renaming a vendor-specific attribute) into a common virtual attribute name at scheduling time. The scheduler then evaluates these virtual attributes exactly like static attributes when matching constraints.
36    ///
37    /// Every derived attribute defined in this list must be referenced by at least one MatchAttribute or DistinctAttribute constraint in the `.devices.constraints` list.
38    ///
39    /// The maximum number of derived attributes is 32.
40    ///
41    /// This is an alpha field and requires enabling the DRADerivedAttributes feature gate.
42    pub derived_attributes: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceDerivedAttribute>>,
43
44    /// DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this subrequest.
45    ///
46    /// A class is required. Which classes are available depends on the cluster.
47    ///
48    /// 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.
49    pub device_class_name: std::string::String,
50
51    /// Name can be used to reference this subrequest in the list of constraints or the list of configurations for the claim. References must use the format \<main request\>/\<subrequest\>.
52    ///
53    /// Must be a DNS label.
54    pub name: std::string::String,
55
56    /// Selectors define criteria which must be satisfied by a specific device in order for that device to be considered for this subrequest. All selectors must be satisfied for a device to be considered.
57    pub selectors: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSelector>>,
58
59    /// If specified, the request's tolerations.
60    ///
61    /// Tolerations for NoSchedule are required to allocate a device which has a taint with that effect. The same applies to NoExecute.
62    ///
63    /// 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.
64    ///
65    /// The maximum number of tolerations is 16.
66    ///
67    /// This is a beta field and requires enabling the DRADeviceTaints feature gate.
68    pub tolerations: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceToleration>>,
69}
70
71impl crate::DeepMerge for DeviceSubRequest {
72    fn merge_from(&mut self, other: Self) {
73        crate::DeepMerge::merge_from(&mut self.allocation_mode, other.allocation_mode);
74        crate::DeepMerge::merge_from(&mut self.capacity, other.capacity);
75        crate::DeepMerge::merge_from(&mut self.count, other.count);
76        crate::merge_strategies::list::atomic(&mut self.derived_attributes, other.derived_attributes);
77        crate::DeepMerge::merge_from(&mut self.device_class_name, other.device_class_name);
78        crate::DeepMerge::merge_from(&mut self.name, other.name);
79        crate::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
80        crate::merge_strategies::list::atomic(&mut self.tolerations, other.tolerations);
81    }
82}
83
84impl<'de> crate::serde::Deserialize<'de> for DeviceSubRequest {
85    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
86        #[allow(non_camel_case_types)]
87        enum Field {
88            Key_allocation_mode,
89            Key_capacity,
90            Key_count,
91            Key_derived_attributes,
92            Key_device_class_name,
93            Key_name,
94            Key_selectors,
95            Key_tolerations,
96            Other,
97        }
98
99        impl<'de> crate::serde::Deserialize<'de> for Field {
100            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
101                struct Visitor;
102
103                impl crate::serde::de::Visitor<'_> for Visitor {
104                    type Value = Field;
105
106                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
107                        f.write_str("field identifier")
108                    }
109
110                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
111                        Ok(match v {
112                            "allocationMode" => Field::Key_allocation_mode,
113                            "capacity" => Field::Key_capacity,
114                            "count" => Field::Key_count,
115                            "derivedAttributes" => Field::Key_derived_attributes,
116                            "deviceClassName" => Field::Key_device_class_name,
117                            "name" => Field::Key_name,
118                            "selectors" => Field::Key_selectors,
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 = DeviceSubRequest;
133
134            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
135                f.write_str("DeviceSubRequest")
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_allocation_mode: Option<std::string::String> = None;
140                let mut value_capacity: Option<crate::api::resource::v1beta2::CapacityRequirements> = None;
141                let mut value_count: Option<i64> = None;
142                let mut value_derived_attributes: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceDerivedAttribute>> = None;
143                let mut value_device_class_name: Option<std::string::String> = None;
144                let mut value_name: Option<std::string::String> = None;
145                let mut value_selectors: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSelector>> = None;
146                let mut value_tolerations: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceToleration>> = None;
147
148                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
149                    match key {
150                        Field::Key_allocation_mode => value_allocation_mode = crate::serde::de::MapAccess::next_value(&mut map)?,
151                        Field::Key_capacity => value_capacity = crate::serde::de::MapAccess::next_value(&mut map)?,
152                        Field::Key_count => value_count = crate::serde::de::MapAccess::next_value(&mut map)?,
153                        Field::Key_derived_attributes => value_derived_attributes = crate::serde::de::MapAccess::next_value(&mut map)?,
154                        Field::Key_device_class_name => value_device_class_name = crate::serde::de::MapAccess::next_value(&mut map)?,
155                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
156                        Field::Key_selectors => value_selectors = crate::serde::de::MapAccess::next_value(&mut map)?,
157                        Field::Key_tolerations => value_tolerations = crate::serde::de::MapAccess::next_value(&mut map)?,
158                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
159                    }
160                }
161
162                Ok(DeviceSubRequest {
163                    allocation_mode: value_allocation_mode,
164                    capacity: value_capacity,
165                    count: value_count,
166                    derived_attributes: value_derived_attributes,
167                    device_class_name: value_device_class_name.unwrap_or_default(),
168                    name: value_name.unwrap_or_default(),
169                    selectors: value_selectors,
170                    tolerations: value_tolerations,
171                })
172            }
173        }
174
175        deserializer.deserialize_struct(
176            "DeviceSubRequest",
177            &[
178                "allocationMode",
179                "capacity",
180                "count",
181                "derivedAttributes",
182                "deviceClassName",
183                "name",
184                "selectors",
185                "tolerations",
186            ],
187            Visitor,
188        )
189    }
190}
191
192impl crate::serde::Serialize for DeviceSubRequest {
193    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
194        let mut state = serializer.serialize_struct(
195            "DeviceSubRequest",
196            2 +
197            self.allocation_mode.as_ref().map_or(0, |_| 1) +
198            self.capacity.as_ref().map_or(0, |_| 1) +
199            self.count.as_ref().map_or(0, |_| 1) +
200            self.derived_attributes.as_ref().map_or(0, |_| 1) +
201            self.selectors.as_ref().map_or(0, |_| 1) +
202            self.tolerations.as_ref().map_or(0, |_| 1),
203        )?;
204        if let Some(value) = &self.allocation_mode {
205            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationMode", value)?;
206        }
207        if let Some(value) = &self.capacity {
208            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "capacity", value)?;
209        }
210        if let Some(value) = &self.count {
211            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "count", value)?;
212        }
213        if let Some(value) = &self.derived_attributes {
214            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "derivedAttributes", value)?;
215        }
216        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deviceClassName", &self.device_class_name)?;
217        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
218        if let Some(value) = &self.selectors {
219            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
220        }
221        if let Some(value) = &self.tolerations {
222            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerations", value)?;
223        }
224        crate::serde::ser::SerializeStruct::end(state)
225    }
226}
227
228#[cfg(feature = "schemars")]
229impl crate::schemars::JsonSchema for DeviceSubRequest {
230    fn schema_name() -> std::borrow::Cow<'static, str> {
231        "io.k8s.api.resource.v1beta2.DeviceSubRequest".into()
232    }
233
234    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
235        crate::schemars::json_schema!({
236            "description": "DeviceSubRequest describes a request for device provided in the claim.spec.devices.requests[].firstAvailable array. Each is typically a request for a single resource like a device, but can also ask for several identical devices.\n\nDeviceSubRequest is similar to ExactDeviceRequest, but doesn't expose the AdminAccess field as that one is only supported when requesting a specific device.",
237            "type": "object",
238            "properties": {
239                "allocationMode": {
240                    "description": "AllocationMode and its related fields define how devices are allocated to satisfy this subrequest. 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 subrequest is for all of the matching devices in a pool.\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 subrequests must specify this field.\n\nMore modes may get added in the future. Clients must refuse to handle requests with unknown modes.",
241                    "type": "string",
242                },
243                "capacity": ({
244                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::CapacityRequirements>();
245                    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());
246                    schema_obj
247                }),
248                "count": {
249                    "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.",
250                    "type": "integer",
251                    "format": "int64",
252                },
253                "derivedAttributes": {
254                    "description": "DerivedAttributes defines a set of virtual attributes computed via CEL expressions for each candidate device. These virtual attributes can be referenced in `.devices.constraints` to align and match different devices (e.g., co-allocating a GPU and a NIC on the same NUMA node) even if their drivers publish different attributes. Derived attributes are not available via `device.attributes` in the CEL environment when evaluating selector expressions.\n\nDerived attributes allow you to extract, transform, or normalize topology information (such as extracting a NUMA index from a complex topology string or renaming a vendor-specific attribute) into a common virtual attribute name at scheduling time. The scheduler then evaluates these virtual attributes exactly like static attributes when matching constraints.\n\nEvery derived attribute defined in this list must be referenced by at least one MatchAttribute or DistinctAttribute constraint in the `.devices.constraints` list.\n\nThe maximum number of derived attributes is 32.\n\nThis is an alpha field and requires enabling the DRADerivedAttributes feature gate.",
255                    "type": "array",
256                    "items": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceDerivedAttribute>()),
257                },
258                "deviceClassName": {
259                    "description": "DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this subrequest.\n\nA class is required. 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.",
260                    "type": "string",
261                },
262                "name": {
263                    "description": "Name can be used to reference this subrequest in the list of constraints or the list of configurations for the claim. References must use the format <main request>/<subrequest>.\n\nMust be a DNS label.",
264                    "type": "string",
265                },
266                "selectors": {
267                    "description": "Selectors define criteria which must be satisfied by a specific device in order for that device to be considered for this subrequest. All selectors must be satisfied for a device to be considered.",
268                    "type": "array",
269                    "items": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceSelector>()),
270                },
271                "tolerations": {
272                    "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 is a beta field and requires enabling the DRADeviceTaints feature gate.",
273                    "type": "array",
274                    "items": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceToleration>()),
275                },
276            },
277            "required": [
278                "deviceClassName",
279                "name",
280            ],
281        })
282    }
283}