k8s_openapi/v1_33/api/resource/v1alpha3/
basic_device.rs

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