1// Generated from definition io.k8s.api.resource.v1beta1.DeviceSubRequest
23/// 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.
21pub allocation_mode: Option<std::string::String>,
2223/// 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.
24pub count: Option<i64>,
2526/// 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.
31pub device_class_name: std::string::String,
3233/// 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.
36pub name: std::string::String,
3738/// 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.
39pub selectors: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSelector>>,
4041/// 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.
50pub tolerations: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceToleration>>,
51}
5253impl crate::DeepMerge for DeviceSubRequest {
54fn merge_from(&mut self, other: Self) {
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::DeepMerge::merge_from(&mut self.name, other.name);
59crate::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
60crate::merge_strategies::list::atomic(&mut self.tolerations, other.tolerations);
61 }
62}
6364impl<'de> crate::serde::Deserialize<'de> for DeviceSubRequest {
65fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
66#[allow(non_camel_case_types)]
67enum 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 }
7677impl<'de> crate::serde::Deserialize<'de> for Field {
78fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
79struct Visitor;
8081impl crate::serde::de::Visitor<'_> for Visitor {
82type Value = Field;
8384fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
85 f.write_str("field identifier")
86 }
8788fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
89Ok(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 }
100101 deserializer.deserialize_identifier(Visitor)
102 }
103 }
104105struct Visitor;
106107impl<'de> crate::serde::de::Visitor<'de> for Visitor {
108type Value = DeviceSubRequest;
109110fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
111 f.write_str("DeviceSubRequest")
112 }
113114fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
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_name: Option<std::string::String> = None;
119let mut value_selectors: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSelector>> = None;
120let mut value_tolerations: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceToleration>> = None;
121122while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
123match 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 }
133134Ok(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 }
144145 deserializer.deserialize_struct(
146"DeviceSubRequest",
147&[
148"allocationMode",
149"count",
150"deviceClassName",
151"name",
152"selectors",
153"tolerations",
154 ],
155 Visitor,
156 )
157 }
158}
159160impl crate::serde::Serialize for DeviceSubRequest {
161fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
162let mut state = serializer.serialize_struct(
163"DeviceSubRequest",
1642 +
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.allocation_mode {
171crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationMode", value)?;
172 }
173if let Some(value) = &self.count {
174crate::serde::ser::SerializeStruct::serialize_field(&mut state, "count", value)?;
175 }
176crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deviceClassName", &self.device_class_name)?;
177crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
178if let Some(value) = &self.selectors {
179crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
180 }
181if let Some(value) = &self.tolerations {
182crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerations", value)?;
183 }
184crate::serde::ser::SerializeStruct::end(state)
185 }
186}
187188#[cfg(feature = "schemars")]
189impl crate::schemars::JsonSchema for DeviceSubRequest {
190fn schema_name() -> std::string::String {
191"io.k8s.api.resource.v1beta1.DeviceSubRequest".into()
192 }
193194fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
195crate::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(),
205crate::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(),
216crate::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(),
228crate::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(),
239crate::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(),
250crate::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(),
265crate::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}