k8s_openapi/v1_34/api/resource/v1beta1/
basic_device.rs

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