k8s_openapi/v1_33/api/resource/v1beta2/
exact_device_request.rs

1// Generated from definition io.k8s.api.resource.v1beta2.ExactDeviceRequest
2
3/// ExactDeviceRequest is a request for one or more identical devices.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ExactDeviceRequest {
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 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.
9    pub admin_access: Option<bool>,
10
11    /// AllocationMode and its related fields define how devices are allocated to satisfy this request. Supported values are:
12    ///
13    /// - ExactCount: This request is for a specific number of devices.
14    ///   This is the default. The exact number is provided in the
15    ///   count field.
16    ///
17    /// - All: This request is for all of the matching devices in a pool.
18    ///   At least one device must exist on the node for the allocation to succeed.
19    ///   Allocation will fail if some devices are already allocated,
20    ///   unless adminAccess is requested.
21    ///
22    /// 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.
23    ///
24    /// More modes may get added in the future. Clients must refuse to handle requests with unknown modes.
25    pub allocation_mode: Option<std::string::String>,
26
27    /// 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.
28    pub count: Option<i64>,
29
30    /// DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this request.
31    ///
32    /// A DeviceClassName is required.
33    ///
34    /// 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.
35    pub device_class_name: std::string::String,
36
37    /// 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.
38    pub selectors: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSelector>>,
39
40    /// If specified, the request's tolerations.
41    ///
42    /// Tolerations for NoSchedule are required to allocate a device which has a taint with that effect. The same applies to NoExecute.
43    ///
44    /// 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.
45    ///
46    /// The maximum number of tolerations is 16.
47    ///
48    /// This is an alpha field and requires enabling the DRADeviceTaints feature gate.
49    pub tolerations: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceToleration>>,
50}
51
52impl crate::DeepMerge for ExactDeviceRequest {
53    fn merge_from(&mut self, other: Self) {
54        crate::DeepMerge::merge_from(&mut self.admin_access, other.admin_access);
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::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
59        crate::merge_strategies::list::atomic(&mut self.tolerations, other.tolerations);
60    }
61}
62
63impl<'de> crate::serde::Deserialize<'de> for ExactDeviceRequest {
64    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
65        #[allow(non_camel_case_types)]
66        enum Field {
67            Key_admin_access,
68            Key_allocation_mode,
69            Key_count,
70            Key_device_class_name,
71            Key_selectors,
72            Key_tolerations,
73            Other,
74        }
75
76        impl<'de> crate::serde::Deserialize<'de> for Field {
77            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
78                struct Visitor;
79
80                impl crate::serde::de::Visitor<'_> for Visitor {
81                    type Value = Field;
82
83                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
84                        f.write_str("field identifier")
85                    }
86
87                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
88                        Ok(match v {
89                            "adminAccess" => Field::Key_admin_access,
90                            "allocationMode" => Field::Key_allocation_mode,
91                            "count" => Field::Key_count,
92                            "deviceClassName" => Field::Key_device_class_name,
93                            "selectors" => Field::Key_selectors,
94                            "tolerations" => Field::Key_tolerations,
95                            _ => Field::Other,
96                        })
97                    }
98                }
99
100                deserializer.deserialize_identifier(Visitor)
101            }
102        }
103
104        struct Visitor;
105
106        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
107            type Value = ExactDeviceRequest;
108
109            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
110                f.write_str("ExactDeviceRequest")
111            }
112
113            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
114                let mut value_admin_access: Option<bool> = None;
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_selectors: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSelector>> = None;
119                let mut value_tolerations: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceToleration>> = None;
120
121                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
122                    match key {
123                        Field::Key_admin_access => value_admin_access = crate::serde::de::MapAccess::next_value(&mut map)?,
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_selectors => value_selectors = crate::serde::de::MapAccess::next_value(&mut map)?,
128                        Field::Key_tolerations => value_tolerations = crate::serde::de::MapAccess::next_value(&mut map)?,
129                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
130                    }
131                }
132
133                Ok(ExactDeviceRequest {
134                    admin_access: value_admin_access,
135                    allocation_mode: value_allocation_mode,
136                    count: value_count,
137                    device_class_name: value_device_class_name.unwrap_or_default(),
138                    selectors: value_selectors,
139                    tolerations: value_tolerations,
140                })
141            }
142        }
143
144        deserializer.deserialize_struct(
145            "ExactDeviceRequest",
146            &[
147                "adminAccess",
148                "allocationMode",
149                "count",
150                "deviceClassName",
151                "selectors",
152                "tolerations",
153            ],
154            Visitor,
155        )
156    }
157}
158
159impl crate::serde::Serialize for ExactDeviceRequest {
160    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
161        let mut state = serializer.serialize_struct(
162            "ExactDeviceRequest",
163            1 +
164            self.admin_access.as_ref().map_or(0, |_| 1) +
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.admin_access {
171            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "adminAccess", value)?;
172        }
173        if let Some(value) = &self.allocation_mode {
174            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationMode", value)?;
175        }
176        if let Some(value) = &self.count {
177            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "count", value)?;
178        }
179        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deviceClassName", &self.device_class_name)?;
180        if let Some(value) = &self.selectors {
181            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
182        }
183        if let Some(value) = &self.tolerations {
184            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerations", value)?;
185        }
186        crate::serde::ser::SerializeStruct::end(state)
187    }
188}
189
190#[cfg(feature = "schemars")]
191impl crate::schemars::JsonSchema for ExactDeviceRequest {
192    fn schema_name() -> std::string::String {
193        "io.k8s.api.resource.v1beta2.ExactDeviceRequest".into()
194    }
195
196    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
197        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
198            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
199                description: Some("ExactDeviceRequest is a request for one or more identical devices.".into()),
200                ..Default::default()
201            })),
202            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
203            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
204                properties: [
205                    (
206                        "adminAccess".into(),
207                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
208                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
209                                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 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()),
210                                ..Default::default()
211                            })),
212                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Boolean))),
213                            ..Default::default()
214                        }),
215                    ),
216                    (
217                        "allocationMode".into(),
218                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
219                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
220                                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\nMore modes may get added in the future. Clients must refuse to handle requests with unknown modes.".into()),
221                                ..Default::default()
222                            })),
223                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
224                            ..Default::default()
225                        }),
226                    ),
227                    (
228                        "count".into(),
229                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
230                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
231                                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()),
232                                ..Default::default()
233                            })),
234                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
235                            format: Some("int64".into()),
236                            ..Default::default()
237                        }),
238                    ),
239                    (
240                        "deviceClassName".into(),
241                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
242                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
243                                description: Some("DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this request.\n\nA DeviceClassName is required.\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()),
244                                ..Default::default()
245                            })),
246                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
247                            ..Default::default()
248                        }),
249                    ),
250                    (
251                        "selectors".into(),
252                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
253                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
254                                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.".into()),
255                                ..Default::default()
256                            })),
257                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
258                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
259                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta2::DeviceSelector>()))),
260                                ..Default::default()
261                            })),
262                            ..Default::default()
263                        }),
264                    ),
265                    (
266                        "tolerations".into(),
267                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
268                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
269                                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()),
270                                ..Default::default()
271                            })),
272                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
273                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
274                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta2::DeviceToleration>()))),
275                                ..Default::default()
276                            })),
277                            ..Default::default()
278                        }),
279                    ),
280                ].into(),
281                required: [
282                    "deviceClassName".into(),
283                ].into(),
284                ..Default::default()
285            })),
286            ..Default::default()
287        })
288    }
289}