1// Generated from definition io.k8s.api.resource.v1beta2.ExactDeviceRequest
23/// 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.
9pub admin_access: Option<bool>,
1011/// 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.
25pub allocation_mode: Option<std::string::String>,
2627/// 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.
28pub count: Option<i64>,
2930/// 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.
35pub device_class_name: std::string::String,
3637/// 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.
38pub selectors: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSelector>>,
3940/// 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.
49pub tolerations: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceToleration>>,
50}
5152impl crate::DeepMerge for ExactDeviceRequest {
53fn merge_from(&mut self, other: Self) {
54crate::DeepMerge::merge_from(&mut self.admin_access, other.admin_access);
55crate::DeepMerge::merge_from(&mut self.allocation_mode, other.allocation_mode);
56crate::DeepMerge::merge_from(&mut self.count, other.count);
57crate::DeepMerge::merge_from(&mut self.device_class_name, other.device_class_name);
58crate::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
59crate::merge_strategies::list::atomic(&mut self.tolerations, other.tolerations);
60 }
61}
6263impl<'de> crate::serde::Deserialize<'de> for ExactDeviceRequest {
64fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
65#[allow(non_camel_case_types)]
66enum 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 }
7576impl<'de> crate::serde::Deserialize<'de> for Field {
77fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
78struct Visitor;
7980impl crate::serde::de::Visitor<'_> for Visitor {
81type Value = Field;
8283fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
84 f.write_str("field identifier")
85 }
8687fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
88Ok(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 }
99100 deserializer.deserialize_identifier(Visitor)
101 }
102 }
103104struct Visitor;
105106impl<'de> crate::serde::de::Visitor<'de> for Visitor {
107type Value = ExactDeviceRequest;
108109fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
110 f.write_str("ExactDeviceRequest")
111 }
112113fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
114let mut value_admin_access: Option<bool> = None;
115let mut value_allocation_mode: Option<std::string::String> = None;
116let mut value_count: Option<i64> = None;
117let mut value_device_class_name: Option<std::string::String> = None;
118let mut value_selectors: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSelector>> = None;
119let mut value_tolerations: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceToleration>> = None;
120121while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
122match 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 }
132133Ok(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 }
143144 deserializer.deserialize_struct(
145"ExactDeviceRequest",
146&[
147"adminAccess",
148"allocationMode",
149"count",
150"deviceClassName",
151"selectors",
152"tolerations",
153 ],
154 Visitor,
155 )
156 }
157}
158159impl crate::serde::Serialize for ExactDeviceRequest {
160fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
161let mut state = serializer.serialize_struct(
162"ExactDeviceRequest",
1631 +
164self.admin_access.as_ref().map_or(0, |_| 1) +
165self.allocation_mode.as_ref().map_or(0, |_| 1) +
166self.count.as_ref().map_or(0, |_| 1) +
167self.selectors.as_ref().map_or(0, |_| 1) +
168self.tolerations.as_ref().map_or(0, |_| 1),
169 )?;
170if let Some(value) = &self.admin_access {
171crate::serde::ser::SerializeStruct::serialize_field(&mut state, "adminAccess", value)?;
172 }
173if let Some(value) = &self.allocation_mode {
174crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationMode", value)?;
175 }
176if let Some(value) = &self.count {
177crate::serde::ser::SerializeStruct::serialize_field(&mut state, "count", value)?;
178 }
179crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deviceClassName", &self.device_class_name)?;
180if let Some(value) = &self.selectors {
181crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
182 }
183if let Some(value) = &self.tolerations {
184crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerations", value)?;
185 }
186crate::serde::ser::SerializeStruct::end(state)
187 }
188}
189190#[cfg(feature = "schemars")]
191impl crate::schemars::JsonSchema for ExactDeviceRequest {
192fn schema_name() -> std::string::String {
193"io.k8s.api.resource.v1beta2.ExactDeviceRequest".into()
194 }
195196fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
197crate::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(),
207crate::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(),
218crate::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(),
229crate::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(),
241crate::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(),
252crate::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(),
267crate::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}