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

1// Generated from definition io.k8s.api.resource.v1beta2.Device
2
3/// Device represents one individual hardware instance that can be selected based on its attributes. Besides the name, exactly one field must be set.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct Device {
6    /// AllNodes indicates that all nodes have access to the device.
7    ///
8    /// Must only be set if Spec.PerDeviceNodeSelection is set to true. At most one of NodeName, NodeSelector and AllNodes can be set.
9    pub all_nodes: Option<bool>,
10
11    /// Attributes defines the set of attributes for this device. The name of each attribute must be unique in that set.
12    ///
13    /// The maximum number of attributes and capacities combined is 32.
14    pub attributes: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta2::DeviceAttribute>>,
15
16    /// Capacity defines the set of capacities for this device. The name of each capacity must be unique in that set.
17    ///
18    /// The maximum number of attributes and capacities combined is 32.
19    pub capacity: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta2::DeviceCapacity>>,
20
21    /// ConsumesCounters defines a list of references to sharedCounters and the set of counters that the device will consume from those counter sets.
22    ///
23    /// There can only be a single entry per counterSet.
24    ///
25    /// The 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).
26    pub consumes_counters: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceCounterConsumption>>,
27
28    /// Name is unique identifier among all devices managed by the driver in the pool. It must be a DNS label.
29    pub name: std::string::String,
30
31    /// NodeName identifies the node where the device is available.
32    ///
33    /// Must only be set if Spec.PerDeviceNodeSelection is set to true. At most one of NodeName, NodeSelector and AllNodes can be set.
34    pub node_name: Option<std::string::String>,
35
36    /// NodeSelector defines the nodes where the device is available.
37    ///
38    /// Must use exactly one term.
39    ///
40    /// Must only be set if Spec.PerDeviceNodeSelection is set to true. At most one of NodeName, NodeSelector and AllNodes can be set.
41    pub node_selector: Option<crate::api::core::v1::NodeSelector>,
42
43    /// If specified, these are the driver-defined taints.
44    ///
45    /// The maximum number of taints is 4.
46    ///
47    /// This is an alpha field and requires enabling the DRADeviceTaints feature gate.
48    pub taints: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceTaint>>,
49}
50
51impl crate::DeepMerge for Device {
52    fn merge_from(&mut self, other: Self) {
53        crate::DeepMerge::merge_from(&mut self.all_nodes, other.all_nodes);
54        crate::merge_strategies::map::granular(&mut self.attributes, other.attributes, |current_item, other_item| {
55            crate::DeepMerge::merge_from(current_item, other_item);
56        });
57        crate::merge_strategies::map::granular(&mut self.capacity, other.capacity, |current_item, other_item| {
58            crate::DeepMerge::merge_from(current_item, other_item);
59        });
60        crate::merge_strategies::list::atomic(&mut self.consumes_counters, other.consumes_counters);
61        crate::DeepMerge::merge_from(&mut self.name, other.name);
62        crate::DeepMerge::merge_from(&mut self.node_name, other.node_name);
63        crate::DeepMerge::merge_from(&mut self.node_selector, other.node_selector);
64        crate::merge_strategies::list::atomic(&mut self.taints, other.taints);
65    }
66}
67
68impl<'de> crate::serde::Deserialize<'de> for Device {
69    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
70        #[allow(non_camel_case_types)]
71        enum Field {
72            Key_all_nodes,
73            Key_attributes,
74            Key_capacity,
75            Key_consumes_counters,
76            Key_name,
77            Key_node_name,
78            Key_node_selector,
79            Key_taints,
80            Other,
81        }
82
83        impl<'de> crate::serde::Deserialize<'de> for Field {
84            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
85                struct Visitor;
86
87                impl crate::serde::de::Visitor<'_> for Visitor {
88                    type Value = Field;
89
90                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
91                        f.write_str("field identifier")
92                    }
93
94                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
95                        Ok(match v {
96                            "allNodes" => Field::Key_all_nodes,
97                            "attributes" => Field::Key_attributes,
98                            "capacity" => Field::Key_capacity,
99                            "consumesCounters" => Field::Key_consumes_counters,
100                            "name" => Field::Key_name,
101                            "nodeName" => Field::Key_node_name,
102                            "nodeSelector" => Field::Key_node_selector,
103                            "taints" => Field::Key_taints,
104                            _ => Field::Other,
105                        })
106                    }
107                }
108
109                deserializer.deserialize_identifier(Visitor)
110            }
111        }
112
113        struct Visitor;
114
115        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
116            type Value = Device;
117
118            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
119                f.write_str("Device")
120            }
121
122            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
123                let mut value_all_nodes: Option<bool> = None;
124                let mut value_attributes: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta2::DeviceAttribute>> = None;
125                let mut value_capacity: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta2::DeviceCapacity>> = None;
126                let mut value_consumes_counters: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceCounterConsumption>> = None;
127                let mut value_name: Option<std::string::String> = None;
128                let mut value_node_name: Option<std::string::String> = None;
129                let mut value_node_selector: Option<crate::api::core::v1::NodeSelector> = None;
130                let mut value_taints: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceTaint>> = None;
131
132                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
133                    match key {
134                        Field::Key_all_nodes => value_all_nodes = crate::serde::de::MapAccess::next_value(&mut map)?,
135                        Field::Key_attributes => value_attributes = crate::serde::de::MapAccess::next_value(&mut map)?,
136                        Field::Key_capacity => value_capacity = crate::serde::de::MapAccess::next_value(&mut map)?,
137                        Field::Key_consumes_counters => value_consumes_counters = crate::serde::de::MapAccess::next_value(&mut map)?,
138                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
139                        Field::Key_node_name => value_node_name = crate::serde::de::MapAccess::next_value(&mut map)?,
140                        Field::Key_node_selector => value_node_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
141                        Field::Key_taints => value_taints = crate::serde::de::MapAccess::next_value(&mut map)?,
142                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
143                    }
144                }
145
146                Ok(Device {
147                    all_nodes: value_all_nodes,
148                    attributes: value_attributes,
149                    capacity: value_capacity,
150                    consumes_counters: value_consumes_counters,
151                    name: value_name.unwrap_or_default(),
152                    node_name: value_node_name,
153                    node_selector: value_node_selector,
154                    taints: value_taints,
155                })
156            }
157        }
158
159        deserializer.deserialize_struct(
160            "Device",
161            &[
162                "allNodes",
163                "attributes",
164                "capacity",
165                "consumesCounters",
166                "name",
167                "nodeName",
168                "nodeSelector",
169                "taints",
170            ],
171            Visitor,
172        )
173    }
174}
175
176impl crate::serde::Serialize for Device {
177    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
178        let mut state = serializer.serialize_struct(
179            "Device",
180            1 +
181            self.all_nodes.as_ref().map_or(0, |_| 1) +
182            self.attributes.as_ref().map_or(0, |_| 1) +
183            self.capacity.as_ref().map_or(0, |_| 1) +
184            self.consumes_counters.as_ref().map_or(0, |_| 1) +
185            self.node_name.as_ref().map_or(0, |_| 1) +
186            self.node_selector.as_ref().map_or(0, |_| 1) +
187            self.taints.as_ref().map_or(0, |_| 1),
188        )?;
189        if let Some(value) = &self.all_nodes {
190            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allNodes", value)?;
191        }
192        if let Some(value) = &self.attributes {
193            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "attributes", value)?;
194        }
195        if let Some(value) = &self.capacity {
196            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "capacity", value)?;
197        }
198        if let Some(value) = &self.consumes_counters {
199            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "consumesCounters", value)?;
200        }
201        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
202        if let Some(value) = &self.node_name {
203            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeName", value)?;
204        }
205        if let Some(value) = &self.node_selector {
206            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeSelector", value)?;
207        }
208        if let Some(value) = &self.taints {
209            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "taints", value)?;
210        }
211        crate::serde::ser::SerializeStruct::end(state)
212    }
213}
214
215#[cfg(feature = "schemars")]
216impl crate::schemars::JsonSchema for Device {
217    fn schema_name() -> std::string::String {
218        "io.k8s.api.resource.v1beta2.Device".into()
219    }
220
221    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
222        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
223            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
224                description: Some("Device represents one individual hardware instance that can be selected based on its attributes. Besides the name, exactly one field must be set.".into()),
225                ..Default::default()
226            })),
227            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
228            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
229                properties: [
230                    (
231                        "allNodes".into(),
232                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
233                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
234                                description: Some("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.".into()),
235                                ..Default::default()
236                            })),
237                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Boolean))),
238                            ..Default::default()
239                        }),
240                    ),
241                    (
242                        "attributes".into(),
243                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
244                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
245                                description: Some("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.".into()),
246                                ..Default::default()
247                            })),
248                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
249                            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
250                                additional_properties: Some(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta2::DeviceAttribute>())),
251                                ..Default::default()
252                            })),
253                            ..Default::default()
254                        }),
255                    ),
256                    (
257                        "capacity".into(),
258                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
259                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
260                                description: Some("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.".into()),
261                                ..Default::default()
262                            })),
263                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
264                            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
265                                additional_properties: Some(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta2::DeviceCapacity>())),
266                                ..Default::default()
267                            })),
268                            ..Default::default()
269                        }),
270                    ),
271                    (
272                        "consumesCounters".into(),
273                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
274                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
275                                description: Some("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).".into()),
276                                ..Default::default()
277                            })),
278                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
279                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
280                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta2::DeviceCounterConsumption>()))),
281                                ..Default::default()
282                            })),
283                            ..Default::default()
284                        }),
285                    ),
286                    (
287                        "name".into(),
288                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
289                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
290                                description: Some("Name is unique identifier among all devices managed by the driver in the pool. It must be a DNS label.".into()),
291                                ..Default::default()
292                            })),
293                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
294                            ..Default::default()
295                        }),
296                    ),
297                    (
298                        "nodeName".into(),
299                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
300                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
301                                description: Some("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.".into()),
302                                ..Default::default()
303                            })),
304                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
305                            ..Default::default()
306                        }),
307                    ),
308                    (
309                        "nodeSelector".into(),
310                        {
311                            let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>().into_object();
312                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
313                                description: Some("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()),
314                                ..Default::default()
315                            }));
316                            crate::schemars::schema::Schema::Object(schema_obj)
317                        },
318                    ),
319                    (
320                        "taints".into(),
321                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
322                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
323                                description: Some("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.".into()),
324                                ..Default::default()
325                            })),
326                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
327                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
328                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta2::DeviceTaint>()))),
329                                ..Default::default()
330                            })),
331                            ..Default::default()
332                        }),
333                    ),
334                ].into(),
335                required: [
336                    "name".into(),
337                ].into(),
338                ..Default::default()
339            })),
340            ..Default::default()
341        })
342    }
343}