k8s_openapi/v1_33/api/resource/v1beta1/
device_sub_request.rs

1// Generated from definition io.k8s.api.resource.v1beta1.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 Request, but doesn't expose the AdminAccess or FirstAvailable fields, as those can only be set on the top-level request. AdminAccess is not supported for requests with a prioritized list, and recursive FirstAvailable fields are not supported.
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    /// 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.
24    pub count: Option<i64>,
25
26    /// DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this subrequest.
27    ///
28    /// A class is required. Which classes are available depends on the cluster.
29    ///
30    /// 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.
31    pub device_class_name: std::string::String,
32
33    /// 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\>.
34    ///
35    /// Must be a DNS label.
36    pub name: std::string::String,
37
38    /// 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.
39    pub selectors: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSelector>>,
40
41    /// If specified, the request's tolerations.
42    ///
43    /// Tolerations for NoSchedule are required to allocate a device which has a taint with that effect. The same applies to NoExecute.
44    ///
45    /// 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.
46    ///
47    /// The maximum number of tolerations is 16.
48    ///
49    /// This is an alpha field and requires enabling the DRADeviceTaints feature gate.
50    pub tolerations: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceToleration>>,
51}
52
53impl crate::DeepMerge for DeviceSubRequest {
54    fn merge_from(&mut self, other: Self) {
55        crate::DeepMerge::merge_from(&mut self.allocation_mode, other.allocation_mode);
56        crate::DeepMerge::merge_from(&mut self.count, other.count);
57        crate::DeepMerge::merge_from(&mut self.device_class_name, other.device_class_name);
58        crate::DeepMerge::merge_from(&mut self.name, other.name);
59        crate::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
60        crate::merge_strategies::list::atomic(&mut self.tolerations, other.tolerations);
61    }
62}
63
64impl<'de> crate::serde::Deserialize<'de> for DeviceSubRequest {
65    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
66        #[allow(non_camel_case_types)]
67        enum Field {
68            Key_allocation_mode,
69            Key_count,
70            Key_device_class_name,
71            Key_name,
72            Key_selectors,
73            Key_tolerations,
74            Other,
75        }
76
77        impl<'de> crate::serde::Deserialize<'de> for Field {
78            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
79                struct Visitor;
80
81                impl crate::serde::de::Visitor<'_> for Visitor {
82                    type Value = Field;
83
84                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
85                        f.write_str("field identifier")
86                    }
87
88                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
89                        Ok(match v {
90                            "allocationMode" => Field::Key_allocation_mode,
91                            "count" => Field::Key_count,
92                            "deviceClassName" => Field::Key_device_class_name,
93                            "name" => Field::Key_name,
94                            "selectors" => Field::Key_selectors,
95                            "tolerations" => Field::Key_tolerations,
96                            _ => Field::Other,
97                        })
98                    }
99                }
100
101                deserializer.deserialize_identifier(Visitor)
102            }
103        }
104
105        struct Visitor;
106
107        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
108            type Value = DeviceSubRequest;
109
110            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
111                f.write_str("DeviceSubRequest")
112            }
113
114            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
115                let mut value_allocation_mode: Option<std::string::String> = None;
116                let mut value_count: Option<i64> = None;
117                let mut value_device_class_name: Option<std::string::String> = None;
118                let mut value_name: Option<std::string::String> = None;
119                let mut value_selectors: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSelector>> = None;
120                let mut value_tolerations: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceToleration>> = None;
121
122                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
123                    match key {
124                        Field::Key_allocation_mode => value_allocation_mode = crate::serde::de::MapAccess::next_value(&mut map)?,
125                        Field::Key_count => value_count = crate::serde::de::MapAccess::next_value(&mut map)?,
126                        Field::Key_device_class_name => value_device_class_name = crate::serde::de::MapAccess::next_value(&mut map)?,
127                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
128                        Field::Key_selectors => value_selectors = crate::serde::de::MapAccess::next_value(&mut map)?,
129                        Field::Key_tolerations => value_tolerations = crate::serde::de::MapAccess::next_value(&mut map)?,
130                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
131                    }
132                }
133
134                Ok(DeviceSubRequest {
135                    allocation_mode: value_allocation_mode,
136                    count: value_count,
137                    device_class_name: value_device_class_name.unwrap_or_default(),
138                    name: value_name.unwrap_or_default(),
139                    selectors: value_selectors,
140                    tolerations: value_tolerations,
141                })
142            }
143        }
144
145        deserializer.deserialize_struct(
146            "DeviceSubRequest",
147            &[
148                "allocationMode",
149                "count",
150                "deviceClassName",
151                "name",
152                "selectors",
153                "tolerations",
154            ],
155            Visitor,
156        )
157    }
158}
159
160impl crate::serde::Serialize for DeviceSubRequest {
161    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
162        let mut state = serializer.serialize_struct(
163            "DeviceSubRequest",
164            2 +
165            self.allocation_mode.as_ref().map_or(0, |_| 1) +
166            self.count.as_ref().map_or(0, |_| 1) +
167            self.selectors.as_ref().map_or(0, |_| 1) +
168            self.tolerations.as_ref().map_or(0, |_| 1),
169        )?;
170        if let Some(value) = &self.allocation_mode {
171            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationMode", value)?;
172        }
173        if let Some(value) = &self.count {
174            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "count", value)?;
175        }
176        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deviceClassName", &self.device_class_name)?;
177        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
178        if let Some(value) = &self.selectors {
179            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
180        }
181        if let Some(value) = &self.tolerations {
182            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerations", value)?;
183        }
184        crate::serde::ser::SerializeStruct::end(state)
185    }
186}
187
188#[cfg(feature = "schemars")]
189impl crate::schemars::JsonSchema for DeviceSubRequest {
190    fn schema_name() -> std::string::String {
191        "io.k8s.api.resource.v1beta1.DeviceSubRequest".into()
192    }
193
194    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
195        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
196            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
197                description: Some("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 Request, but doesn't expose the AdminAccess or FirstAvailable fields, as those can only be set on the top-level request. AdminAccess is not supported for requests with a prioritized list, and recursive FirstAvailable fields are not supported.".into()),
198                ..Default::default()
199            })),
200            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
201            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
202                properties: [
203                    (
204                        "allocationMode".into(),
205                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
206                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
207                                description: Some("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.".into()),
208                                ..Default::default()
209                            })),
210                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
211                            ..Default::default()
212                        }),
213                    ),
214                    (
215                        "count".into(),
216                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
217                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
218                                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.".into()),
219                                ..Default::default()
220                            })),
221                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
222                            format: Some("int64".into()),
223                            ..Default::default()
224                        }),
225                    ),
226                    (
227                        "deviceClassName".into(),
228                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
229                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
230                                description: Some("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.".into()),
231                                ..Default::default()
232                            })),
233                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
234                            ..Default::default()
235                        }),
236                    ),
237                    (
238                        "name".into(),
239                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
240                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
241                                description: Some("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.".into()),
242                                ..Default::default()
243                            })),
244                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
245                            ..Default::default()
246                        }),
247                    ),
248                    (
249                        "selectors".into(),
250                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
251                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
252                                description: Some("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.".into()),
253                                ..Default::default()
254                            })),
255                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
256                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
257                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta1::DeviceSelector>()))),
258                                ..Default::default()
259                            })),
260                            ..Default::default()
261                        }),
262                    ),
263                    (
264                        "tolerations".into(),
265                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
266                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
267                                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 is an alpha field and requires enabling the DRADeviceTaints feature gate.".into()),
268                                ..Default::default()
269                            })),
270                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
271                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
272                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta1::DeviceToleration>()))),
273                                ..Default::default()
274                            })),
275                            ..Default::default()
276                        }),
277                    ),
278                ].into(),
279                required: [
280                    "deviceClassName".into(),
281                    "name".into(),
282                ].into(),
283                ..Default::default()
284            })),
285            ..Default::default()
286        })
287    }
288}