1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct Device {
6 pub all_nodes: Option<bool>,
10
11 pub allow_multiple_allocations: Option<bool>,
15
16 pub attributes: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta2::DeviceAttribute>>,
20
21 pub binding_conditions: Option<std::vec::Vec<std::string::String>>,
29
30 pub binding_failure_conditions: Option<std::vec::Vec<std::string::String>>,
38
39 pub binds_to_node: Option<bool>,
43
44 pub capacity: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta2::DeviceCapacity>>,
48
49 pub consumes_counters: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceCounterConsumption>>,
55
56 pub name: std::string::String,
58
59 pub node_name: Option<std::string::String>,
63
64 pub node_selector: Option<crate::api::core::v1::NodeSelector>,
70
71 pub taints: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceTaint>>,
77}
78
79impl crate::DeepMerge for Device {
80 fn merge_from(&mut self, other: Self) {
81 crate::DeepMerge::merge_from(&mut self.all_nodes, other.all_nodes);
82 crate::DeepMerge::merge_from(&mut self.allow_multiple_allocations, other.allow_multiple_allocations);
83 crate::merge_strategies::map::granular(&mut self.attributes, other.attributes, |current_item, other_item| {
84 crate::DeepMerge::merge_from(current_item, other_item);
85 });
86 crate::merge_strategies::list::atomic(&mut self.binding_conditions, other.binding_conditions);
87 crate::merge_strategies::list::atomic(&mut self.binding_failure_conditions, other.binding_failure_conditions);
88 crate::DeepMerge::merge_from(&mut self.binds_to_node, other.binds_to_node);
89 crate::merge_strategies::map::granular(&mut self.capacity, other.capacity, |current_item, other_item| {
90 crate::DeepMerge::merge_from(current_item, other_item);
91 });
92 crate::merge_strategies::list::atomic(&mut self.consumes_counters, other.consumes_counters);
93 crate::DeepMerge::merge_from(&mut self.name, other.name);
94 crate::DeepMerge::merge_from(&mut self.node_name, other.node_name);
95 crate::DeepMerge::merge_from(&mut self.node_selector, other.node_selector);
96 crate::merge_strategies::list::atomic(&mut self.taints, other.taints);
97 }
98}
99
100impl<'de> crate::serde::Deserialize<'de> for Device {
101 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
102 #[allow(non_camel_case_types)]
103 enum Field {
104 Key_all_nodes,
105 Key_allow_multiple_allocations,
106 Key_attributes,
107 Key_binding_conditions,
108 Key_binding_failure_conditions,
109 Key_binds_to_node,
110 Key_capacity,
111 Key_consumes_counters,
112 Key_name,
113 Key_node_name,
114 Key_node_selector,
115 Key_taints,
116 Other,
117 }
118
119 impl<'de> crate::serde::Deserialize<'de> for Field {
120 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
121 struct Visitor;
122
123 impl crate::serde::de::Visitor<'_> for Visitor {
124 type Value = Field;
125
126 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
127 f.write_str("field identifier")
128 }
129
130 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
131 Ok(match v {
132 "allNodes" => Field::Key_all_nodes,
133 "allowMultipleAllocations" => Field::Key_allow_multiple_allocations,
134 "attributes" => Field::Key_attributes,
135 "bindingConditions" => Field::Key_binding_conditions,
136 "bindingFailureConditions" => Field::Key_binding_failure_conditions,
137 "bindsToNode" => Field::Key_binds_to_node,
138 "capacity" => Field::Key_capacity,
139 "consumesCounters" => Field::Key_consumes_counters,
140 "name" => Field::Key_name,
141 "nodeName" => Field::Key_node_name,
142 "nodeSelector" => Field::Key_node_selector,
143 "taints" => Field::Key_taints,
144 _ => Field::Other,
145 })
146 }
147 }
148
149 deserializer.deserialize_identifier(Visitor)
150 }
151 }
152
153 struct Visitor;
154
155 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
156 type Value = Device;
157
158 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
159 f.write_str("Device")
160 }
161
162 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
163 let mut value_all_nodes: Option<bool> = None;
164 let mut value_allow_multiple_allocations: Option<bool> = None;
165 let mut value_attributes: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta2::DeviceAttribute>> = None;
166 let mut value_binding_conditions: Option<std::vec::Vec<std::string::String>> = None;
167 let mut value_binding_failure_conditions: Option<std::vec::Vec<std::string::String>> = None;
168 let mut value_binds_to_node: Option<bool> = None;
169 let mut value_capacity: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta2::DeviceCapacity>> = None;
170 let mut value_consumes_counters: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceCounterConsumption>> = None;
171 let mut value_name: Option<std::string::String> = None;
172 let mut value_node_name: Option<std::string::String> = None;
173 let mut value_node_selector: Option<crate::api::core::v1::NodeSelector> = None;
174 let mut value_taints: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceTaint>> = None;
175
176 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
177 match key {
178 Field::Key_all_nodes => value_all_nodes = crate::serde::de::MapAccess::next_value(&mut map)?,
179 Field::Key_allow_multiple_allocations => value_allow_multiple_allocations = crate::serde::de::MapAccess::next_value(&mut map)?,
180 Field::Key_attributes => value_attributes = crate::serde::de::MapAccess::next_value(&mut map)?,
181 Field::Key_binding_conditions => value_binding_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
182 Field::Key_binding_failure_conditions => value_binding_failure_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
183 Field::Key_binds_to_node => value_binds_to_node = crate::serde::de::MapAccess::next_value(&mut map)?,
184 Field::Key_capacity => value_capacity = crate::serde::de::MapAccess::next_value(&mut map)?,
185 Field::Key_consumes_counters => value_consumes_counters = crate::serde::de::MapAccess::next_value(&mut map)?,
186 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
187 Field::Key_node_name => value_node_name = crate::serde::de::MapAccess::next_value(&mut map)?,
188 Field::Key_node_selector => value_node_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
189 Field::Key_taints => value_taints = crate::serde::de::MapAccess::next_value(&mut map)?,
190 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
191 }
192 }
193
194 Ok(Device {
195 all_nodes: value_all_nodes,
196 allow_multiple_allocations: value_allow_multiple_allocations,
197 attributes: value_attributes,
198 binding_conditions: value_binding_conditions,
199 binding_failure_conditions: value_binding_failure_conditions,
200 binds_to_node: value_binds_to_node,
201 capacity: value_capacity,
202 consumes_counters: value_consumes_counters,
203 name: value_name.unwrap_or_default(),
204 node_name: value_node_name,
205 node_selector: value_node_selector,
206 taints: value_taints,
207 })
208 }
209 }
210
211 deserializer.deserialize_struct(
212 "Device",
213 &[
214 "allNodes",
215 "allowMultipleAllocations",
216 "attributes",
217 "bindingConditions",
218 "bindingFailureConditions",
219 "bindsToNode",
220 "capacity",
221 "consumesCounters",
222 "name",
223 "nodeName",
224 "nodeSelector",
225 "taints",
226 ],
227 Visitor,
228 )
229 }
230}
231
232impl crate::serde::Serialize for Device {
233 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
234 let mut state = serializer.serialize_struct(
235 "Device",
236 1 +
237 self.all_nodes.as_ref().map_or(0, |_| 1) +
238 self.allow_multiple_allocations.as_ref().map_or(0, |_| 1) +
239 self.attributes.as_ref().map_or(0, |_| 1) +
240 self.binding_conditions.as_ref().map_or(0, |_| 1) +
241 self.binding_failure_conditions.as_ref().map_or(0, |_| 1) +
242 self.binds_to_node.as_ref().map_or(0, |_| 1) +
243 self.capacity.as_ref().map_or(0, |_| 1) +
244 self.consumes_counters.as_ref().map_or(0, |_| 1) +
245 self.node_name.as_ref().map_or(0, |_| 1) +
246 self.node_selector.as_ref().map_or(0, |_| 1) +
247 self.taints.as_ref().map_or(0, |_| 1),
248 )?;
249 if let Some(value) = &self.all_nodes {
250 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allNodes", value)?;
251 }
252 if let Some(value) = &self.allow_multiple_allocations {
253 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allowMultipleAllocations", value)?;
254 }
255 if let Some(value) = &self.attributes {
256 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "attributes", value)?;
257 }
258 if let Some(value) = &self.binding_conditions {
259 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "bindingConditions", value)?;
260 }
261 if let Some(value) = &self.binding_failure_conditions {
262 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "bindingFailureConditions", value)?;
263 }
264 if let Some(value) = &self.binds_to_node {
265 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "bindsToNode", value)?;
266 }
267 if let Some(value) = &self.capacity {
268 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "capacity", value)?;
269 }
270 if let Some(value) = &self.consumes_counters {
271 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "consumesCounters", value)?;
272 }
273 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
274 if let Some(value) = &self.node_name {
275 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeName", value)?;
276 }
277 if let Some(value) = &self.node_selector {
278 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeSelector", value)?;
279 }
280 if let Some(value) = &self.taints {
281 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "taints", value)?;
282 }
283 crate::serde::ser::SerializeStruct::end(state)
284 }
285}
286
287#[cfg(feature = "schemars")]
288impl crate::schemars::JsonSchema for Device {
289 fn schema_name() -> std::borrow::Cow<'static, str> {
290 "io.k8s.api.resource.v1beta2.Device".into()
291 }
292
293 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
294 crate::schemars::json_schema!({
295 "description": "Device represents one individual hardware instance that can be selected based on its attributes. Besides the name, exactly one field must be set.",
296 "type": "object",
297 "properties": {
298 "allNodes": {
299 "description": "AllNodes indicates that all nodes have access to the device.\n\nMust only be set if Spec.PerDeviceNodeSelection is set to true. At most one of NodeName, NodeSelector and AllNodes can be set.",
300 "type": "boolean",
301 },
302 "allowMultipleAllocations": {
303 "description": "AllowMultipleAllocations marks whether the device is allowed to be allocated to multiple DeviceRequests.\n\nIf AllowMultipleAllocations is set to true, the device can be allocated more than once, and all of its capacity is consumable, regardless of whether the requestPolicy is defined or not.",
304 "type": "boolean",
305 },
306 "attributes": {
307 "description": "Attributes defines the set of attributes for this device. The name of each attribute must be unique in that set.\n\nThe maximum number of attributes and capacities combined is 32.",
308 "type": "object",
309 "additionalProperties": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceAttribute>()),
310 },
311 "bindingConditions": {
312 "description": "BindingConditions defines the conditions for proceeding with binding. All of these conditions must be set in the per-device status conditions with a value of True to proceed with binding the pod to the node while scheduling the pod.\n\nThe maximum number of binding conditions is 4.\n\nThe conditions must be a valid condition type string.\n\nThis is an alpha field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gates.",
313 "type": "array",
314 "items": {
315 "type": "string",
316 },
317 },
318 "bindingFailureConditions": {
319 "description": "BindingFailureConditions defines the conditions for binding failure. They may be set in the per-device status conditions. If any is set to \"True\", a binding failure occurred.\n\nThe maximum number of binding failure conditions is 4.\n\nThe conditions must be a valid condition type string.\n\nThis is an alpha field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gates.",
320 "type": "array",
321 "items": {
322 "type": "string",
323 },
324 },
325 "bindsToNode": {
326 "description": "BindsToNode indicates if the usage of an allocation involving this device has to be limited to exactly the node that was chosen when allocating the claim. If set to true, the scheduler will set the ResourceClaim.Status.Allocation.NodeSelector to match the node where the allocation was made.\n\nThis is an alpha field and requires enabling the DRADeviceBindingConditions and DRAResourceClaimDeviceStatus feature gates.",
327 "type": "boolean",
328 },
329 "capacity": {
330 "description": "Capacity defines the set of capacities for this device. The name of each capacity must be unique in that set.\n\nThe maximum number of attributes and capacities combined is 32.",
331 "type": "object",
332 "additionalProperties": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceCapacity>()),
333 },
334 "consumesCounters": {
335 "description": "ConsumesCounters defines a list of references to sharedCounters and the set of counters that the device will consume from those counter sets.\n\nThere can only be a single entry per counterSet.\n\nThe total number of device counter consumption entries must be <= 32. In addition, the total number in the entire ResourceSlice must be <= 1024 (for example, 64 devices with 16 counters each).",
336 "type": "array",
337 "items": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceCounterConsumption>()),
338 },
339 "name": {
340 "description": "Name is unique identifier among all devices managed by the driver in the pool. It must be a DNS label.",
341 "type": "string",
342 },
343 "nodeName": {
344 "description": "NodeName identifies the node where the device is available.\n\nMust only be set if Spec.PerDeviceNodeSelection is set to true. At most one of NodeName, NodeSelector and AllNodes can be set.",
345 "type": "string",
346 },
347 "nodeSelector": ({
348 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>();
349 schema_obj.ensure_object().insert("description".into(), "NodeSelector defines the nodes where the device is available.\n\nMust use exactly one term.\n\nMust only be set if Spec.PerDeviceNodeSelection is set to true. At most one of NodeName, NodeSelector and AllNodes can be set.".into());
350 schema_obj
351 }),
352 "taints": {
353 "description": "If specified, these are the driver-defined taints.\n\nThe maximum number of taints is 4.\n\nThis is an alpha field and requires enabling the DRADeviceTaints feature gate.",
354 "type": "array",
355 "items": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceTaint>()),
356 },
357 },
358 "required": [
359 "name",
360 ],
361 })
362 }
363}