k8s_openapi/v1_32/api/resource/v1alpha3/
device_request.rs

1// Generated from definition io.k8s.api.resource.v1alpha3.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///
5/// A DeviceClassName is currently required. Clients must check that it is indeed set. It's absence indicates that something changed in a way that is not supported by the client yet, in which case it must refuse to handle the request.
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct DeviceRequest {
8    /// 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.
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    ///   Allocation will fail if some devices are already allocated,
21    ///   unless adminAccess is requested.
22    ///
23    /// If AlloctionMode 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.
24    ///
25    /// More modes may get added in the future. Clients must refuse to handle requests with unknown modes.
26    pub allocation_mode: Option<String>,
27
28    /// 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.
29    pub count: Option<i64>,
30
31    /// DeviceClassName references a specific DeviceClass, which can define additional configuration and selectors to be inherited by this request.
32    ///
33    /// A class is required. Which classes are available depends on the cluster.
34    ///
35    /// 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.
36    pub device_class_name: String,
37
38    /// Name can be used to reference this request in a pod.spec.containers\[\].resources.claims entry and in a constraint of the claim.
39    ///
40    /// Must be a DNS label.
41    pub name: String,
42
43    /// 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.
44    pub selectors: Option<Vec<crate::api::resource::v1alpha3::DeviceSelector>>,
45}
46
47impl crate::DeepMerge for DeviceRequest {
48    fn merge_from(&mut self, other: Self) {
49        crate::DeepMerge::merge_from(&mut self.admin_access, other.admin_access);
50        crate::DeepMerge::merge_from(&mut self.allocation_mode, other.allocation_mode);
51        crate::DeepMerge::merge_from(&mut self.count, other.count);
52        crate::DeepMerge::merge_from(&mut self.device_class_name, other.device_class_name);
53        crate::DeepMerge::merge_from(&mut self.name, other.name);
54        crate::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
55    }
56}
57
58impl<'de> crate::serde::Deserialize<'de> for DeviceRequest {
59    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
60        #[allow(non_camel_case_types)]
61        enum Field {
62            Key_admin_access,
63            Key_allocation_mode,
64            Key_count,
65            Key_device_class_name,
66            Key_name,
67            Key_selectors,
68            Other,
69        }
70
71        impl<'de> crate::serde::Deserialize<'de> for Field {
72            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
73                struct Visitor;
74
75                impl crate::serde::de::Visitor<'_> for Visitor {
76                    type Value = Field;
77
78                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79                        f.write_str("field identifier")
80                    }
81
82                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
83                        Ok(match v {
84                            "adminAccess" => Field::Key_admin_access,
85                            "allocationMode" => Field::Key_allocation_mode,
86                            "count" => Field::Key_count,
87                            "deviceClassName" => Field::Key_device_class_name,
88                            "name" => Field::Key_name,
89                            "selectors" => Field::Key_selectors,
90                            _ => Field::Other,
91                        })
92                    }
93                }
94
95                deserializer.deserialize_identifier(Visitor)
96            }
97        }
98
99        struct Visitor;
100
101        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
102            type Value = DeviceRequest;
103
104            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
105                f.write_str("DeviceRequest")
106            }
107
108            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
109                let mut value_admin_access: Option<bool> = None;
110                let mut value_allocation_mode: Option<String> = None;
111                let mut value_count: Option<i64> = None;
112                let mut value_device_class_name: Option<String> = None;
113                let mut value_name: Option<String> = None;
114                let mut value_selectors: Option<Vec<crate::api::resource::v1alpha3::DeviceSelector>> = None;
115
116                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
117                    match key {
118                        Field::Key_admin_access => value_admin_access = crate::serde::de::MapAccess::next_value(&mut map)?,
119                        Field::Key_allocation_mode => value_allocation_mode = crate::serde::de::MapAccess::next_value(&mut map)?,
120                        Field::Key_count => value_count = crate::serde::de::MapAccess::next_value(&mut map)?,
121                        Field::Key_device_class_name => value_device_class_name = crate::serde::de::MapAccess::next_value(&mut map)?,
122                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
123                        Field::Key_selectors => value_selectors = crate::serde::de::MapAccess::next_value(&mut map)?,
124                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
125                    }
126                }
127
128                Ok(DeviceRequest {
129                    admin_access: value_admin_access,
130                    allocation_mode: value_allocation_mode,
131                    count: value_count,
132                    device_class_name: value_device_class_name.unwrap_or_default(),
133                    name: value_name.unwrap_or_default(),
134                    selectors: value_selectors,
135                })
136            }
137        }
138
139        deserializer.deserialize_struct(
140            "DeviceRequest",
141            &[
142                "adminAccess",
143                "allocationMode",
144                "count",
145                "deviceClassName",
146                "name",
147                "selectors",
148            ],
149            Visitor,
150        )
151    }
152}
153
154impl crate::serde::Serialize for DeviceRequest {
155    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
156        let mut state = serializer.serialize_struct(
157            "DeviceRequest",
158            2 +
159            self.admin_access.as_ref().map_or(0, |_| 1) +
160            self.allocation_mode.as_ref().map_or(0, |_| 1) +
161            self.count.as_ref().map_or(0, |_| 1) +
162            self.selectors.as_ref().map_or(0, |_| 1),
163        )?;
164        if let Some(value) = &self.admin_access {
165            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "adminAccess", value)?;
166        }
167        if let Some(value) = &self.allocation_mode {
168            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationMode", value)?;
169        }
170        if let Some(value) = &self.count {
171            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "count", value)?;
172        }
173        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deviceClassName", &self.device_class_name)?;
174        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
175        if let Some(value) = &self.selectors {
176            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
177        }
178        crate::serde::ser::SerializeStruct::end(state)
179    }
180}
181
182#[cfg(feature = "schemars")]
183impl crate::schemars::JsonSchema for DeviceRequest {
184    fn schema_name() -> String {
185        "io.k8s.api.resource.v1alpha3.DeviceRequest".to_owned()
186    }
187
188    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
189        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
190            metadata: Some(Box::new(crate::schemars::schema::Metadata {
191                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.\n\nA DeviceClassName is currently required. Clients must check that it is indeed set. It's absence indicates that something changed in a way that is not supported by the client yet, in which case it must refuse to handle the request.".to_owned()),
192                ..Default::default()
193            })),
194            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
195            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
196                properties: [
197                    (
198                        "adminAccess".to_owned(),
199                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
200                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
201                                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.".to_owned()),
202                                ..Default::default()
203                            })),
204                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Boolean))),
205                            ..Default::default()
206                        }),
207                    ),
208                    (
209                        "allocationMode".to_owned(),
210                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
211                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
212                                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  Allocation will fail if some devices are already allocated,\n  unless adminAccess is requested.\n\nIf AlloctionMode 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.".to_owned()),
213                                ..Default::default()
214                            })),
215                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
216                            ..Default::default()
217                        }),
218                    ),
219                    (
220                        "count".to_owned(),
221                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
222                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
223                                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.".to_owned()),
224                                ..Default::default()
225                            })),
226                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
227                            format: Some("int64".to_owned()),
228                            ..Default::default()
229                        }),
230                    ),
231                    (
232                        "deviceClassName".to_owned(),
233                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
234                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
235                                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. 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.".to_owned()),
236                                ..Default::default()
237                            })),
238                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
239                            ..Default::default()
240                        }),
241                    ),
242                    (
243                        "name".to_owned(),
244                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
245                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
246                                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.".to_owned()),
247                                ..Default::default()
248                            })),
249                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
250                            ..Default::default()
251                        }),
252                    ),
253                    (
254                        "selectors".to_owned(),
255                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
256                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
257                                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.".to_owned()),
258                                ..Default::default()
259                            })),
260                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
261                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
262                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::resource::v1alpha3::DeviceSelector>()))),
263                                ..Default::default()
264                            })),
265                            ..Default::default()
266                        }),
267                    ),
268                ].into(),
269                required: [
270                    "deviceClassName".to_owned(),
271                    "name".to_owned(),
272                ].into(),
273                ..Default::default()
274            })),
275            ..Default::default()
276        })
277    }
278}