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

1// Generated from definition io.k8s.api.resource.v1beta1.ResourceSliceSpec
2
3/// ResourceSliceSpec contains the information published by the driver in one ResourceSlice.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceSliceSpec {
6    /// AllNodes indicates that all nodes have access to the resources in the pool.
7    ///
8    /// Exactly one of NodeName, NodeSelector, AllNodes, and PerDeviceNodeSelection must be set.
9    pub all_nodes: Option<bool>,
10
11    /// Devices lists some or all of the devices in this pool.
12    ///
13    /// Must not have more than 128 entries.
14    pub devices: Option<std::vec::Vec<crate::api::resource::v1beta1::Device>>,
15
16    /// Driver identifies the DRA driver providing the capacity information. A field selector can be used to list only ResourceSlice objects with a certain driver name.
17    ///
18    /// Must be a DNS subdomain and should end with a DNS domain owned by the vendor of the driver. This field is immutable.
19    pub driver: std::string::String,
20
21    /// NodeName identifies the node which provides the resources in this pool. A field selector can be used to list only ResourceSlice objects belonging to a certain node.
22    ///
23    /// This field can be used to limit access from nodes to ResourceSlices with the same node name. It also indicates to autoscalers that adding new nodes of the same type as some old node might also make new resources available.
24    ///
25    /// Exactly one of NodeName, NodeSelector, AllNodes, and PerDeviceNodeSelection must be set. This field is immutable.
26    pub node_name: Option<std::string::String>,
27
28    /// NodeSelector defines which nodes have access to the resources in the pool, when that pool is not limited to a single node.
29    ///
30    /// Must use exactly one term.
31    ///
32    /// Exactly one of NodeName, NodeSelector, AllNodes, and PerDeviceNodeSelection must be set.
33    pub node_selector: Option<crate::api::core::v1::NodeSelector>,
34
35    /// PerDeviceNodeSelection defines whether the access from nodes to resources in the pool is set on the ResourceSlice level or on each device. If it is set to true, every device defined the ResourceSlice must specify this individually.
36    ///
37    /// Exactly one of NodeName, NodeSelector, AllNodes, and PerDeviceNodeSelection must be set.
38    pub per_device_node_selection: Option<bool>,
39
40    /// Pool describes the pool that this ResourceSlice belongs to.
41    pub pool: crate::api::resource::v1beta1::ResourcePool,
42
43    /// SharedCounters defines a list of counter sets, each of which has a name and a list of counters available.
44    ///
45    /// The names of the SharedCounters must be unique in the ResourceSlice.
46    ///
47    /// The maximum number of SharedCounters is 32.
48    pub shared_counters: Option<std::vec::Vec<crate::api::resource::v1beta1::CounterSet>>,
49}
50
51impl crate::DeepMerge for ResourceSliceSpec {
52    fn merge_from(&mut self, other: Self) {
53        crate::DeepMerge::merge_from(&mut self.all_nodes, other.all_nodes);
54        crate::merge_strategies::list::atomic(&mut self.devices, other.devices);
55        crate::DeepMerge::merge_from(&mut self.driver, other.driver);
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::DeepMerge::merge_from(&mut self.per_device_node_selection, other.per_device_node_selection);
59        crate::DeepMerge::merge_from(&mut self.pool, other.pool);
60        crate::merge_strategies::list::atomic(&mut self.shared_counters, other.shared_counters);
61    }
62}
63
64impl<'de> crate::serde::Deserialize<'de> for ResourceSliceSpec {
65    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
66        #[allow(non_camel_case_types)]
67        enum Field {
68            Key_all_nodes,
69            Key_devices,
70            Key_driver,
71            Key_node_name,
72            Key_node_selector,
73            Key_per_device_node_selection,
74            Key_pool,
75            Key_shared_counters,
76            Other,
77        }
78
79        impl<'de> crate::serde::Deserialize<'de> for Field {
80            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
81                struct Visitor;
82
83                impl crate::serde::de::Visitor<'_> for Visitor {
84                    type Value = Field;
85
86                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
87                        f.write_str("field identifier")
88                    }
89
90                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
91                        Ok(match v {
92                            "allNodes" => Field::Key_all_nodes,
93                            "devices" => Field::Key_devices,
94                            "driver" => Field::Key_driver,
95                            "nodeName" => Field::Key_node_name,
96                            "nodeSelector" => Field::Key_node_selector,
97                            "perDeviceNodeSelection" => Field::Key_per_device_node_selection,
98                            "pool" => Field::Key_pool,
99                            "sharedCounters" => Field::Key_shared_counters,
100                            _ => Field::Other,
101                        })
102                    }
103                }
104
105                deserializer.deserialize_identifier(Visitor)
106            }
107        }
108
109        struct Visitor;
110
111        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
112            type Value = ResourceSliceSpec;
113
114            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
115                f.write_str("ResourceSliceSpec")
116            }
117
118            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
119                let mut value_all_nodes: Option<bool> = None;
120                let mut value_devices: Option<std::vec::Vec<crate::api::resource::v1beta1::Device>> = None;
121                let mut value_driver: Option<std::string::String> = None;
122                let mut value_node_name: Option<std::string::String> = None;
123                let mut value_node_selector: Option<crate::api::core::v1::NodeSelector> = None;
124                let mut value_per_device_node_selection: Option<bool> = None;
125                let mut value_pool: Option<crate::api::resource::v1beta1::ResourcePool> = None;
126                let mut value_shared_counters: Option<std::vec::Vec<crate::api::resource::v1beta1::CounterSet>> = None;
127
128                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
129                    match key {
130                        Field::Key_all_nodes => value_all_nodes = crate::serde::de::MapAccess::next_value(&mut map)?,
131                        Field::Key_devices => value_devices = crate::serde::de::MapAccess::next_value(&mut map)?,
132                        Field::Key_driver => value_driver = crate::serde::de::MapAccess::next_value(&mut map)?,
133                        Field::Key_node_name => value_node_name = crate::serde::de::MapAccess::next_value(&mut map)?,
134                        Field::Key_node_selector => value_node_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
135                        Field::Key_per_device_node_selection => value_per_device_node_selection = crate::serde::de::MapAccess::next_value(&mut map)?,
136                        Field::Key_pool => value_pool = crate::serde::de::MapAccess::next_value(&mut map)?,
137                        Field::Key_shared_counters => value_shared_counters = crate::serde::de::MapAccess::next_value(&mut map)?,
138                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
139                    }
140                }
141
142                Ok(ResourceSliceSpec {
143                    all_nodes: value_all_nodes,
144                    devices: value_devices,
145                    driver: value_driver.unwrap_or_default(),
146                    node_name: value_node_name,
147                    node_selector: value_node_selector,
148                    per_device_node_selection: value_per_device_node_selection,
149                    pool: value_pool.unwrap_or_default(),
150                    shared_counters: value_shared_counters,
151                })
152            }
153        }
154
155        deserializer.deserialize_struct(
156            "ResourceSliceSpec",
157            &[
158                "allNodes",
159                "devices",
160                "driver",
161                "nodeName",
162                "nodeSelector",
163                "perDeviceNodeSelection",
164                "pool",
165                "sharedCounters",
166            ],
167            Visitor,
168        )
169    }
170}
171
172impl crate::serde::Serialize for ResourceSliceSpec {
173    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
174        let mut state = serializer.serialize_struct(
175            "ResourceSliceSpec",
176            2 +
177            self.all_nodes.as_ref().map_or(0, |_| 1) +
178            self.devices.as_ref().map_or(0, |_| 1) +
179            self.node_name.as_ref().map_or(0, |_| 1) +
180            self.node_selector.as_ref().map_or(0, |_| 1) +
181            self.per_device_node_selection.as_ref().map_or(0, |_| 1) +
182            self.shared_counters.as_ref().map_or(0, |_| 1),
183        )?;
184        if let Some(value) = &self.all_nodes {
185            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allNodes", value)?;
186        }
187        if let Some(value) = &self.devices {
188            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "devices", value)?;
189        }
190        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "driver", &self.driver)?;
191        if let Some(value) = &self.node_name {
192            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeName", value)?;
193        }
194        if let Some(value) = &self.node_selector {
195            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeSelector", value)?;
196        }
197        if let Some(value) = &self.per_device_node_selection {
198            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "perDeviceNodeSelection", value)?;
199        }
200        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pool", &self.pool)?;
201        if let Some(value) = &self.shared_counters {
202            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sharedCounters", value)?;
203        }
204        crate::serde::ser::SerializeStruct::end(state)
205    }
206}
207
208#[cfg(feature = "schemars")]
209impl crate::schemars::JsonSchema for ResourceSliceSpec {
210    fn schema_name() -> std::borrow::Cow<'static, str> {
211        "io.k8s.api.resource.v1beta1.ResourceSliceSpec".into()
212    }
213
214    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
215        crate::schemars::json_schema!({
216            "description": "ResourceSliceSpec contains the information published by the driver in one ResourceSlice.",
217            "type": "object",
218            "properties": {
219                "allNodes": {
220                    "description": "AllNodes indicates that all nodes have access to the resources in the pool.\n\nExactly one of NodeName, NodeSelector, AllNodes, and PerDeviceNodeSelection must be set.",
221                    "type": "boolean",
222                },
223                "devices": {
224                    "description": "Devices lists some or all of the devices in this pool.\n\nMust not have more than 128 entries.",
225                    "type": "array",
226                    "items": (__gen.subschema_for::<crate::api::resource::v1beta1::Device>()),
227                },
228                "driver": {
229                    "description": "Driver identifies the DRA driver providing the capacity information. A field selector can be used to list only ResourceSlice objects with a certain driver name.\n\nMust be a DNS subdomain and should end with a DNS domain owned by the vendor of the driver. This field is immutable.",
230                    "type": "string",
231                },
232                "nodeName": {
233                    "description": "NodeName identifies the node which provides the resources in this pool. A field selector can be used to list only ResourceSlice objects belonging to a certain node.\n\nThis field can be used to limit access from nodes to ResourceSlices with the same node name. It also indicates to autoscalers that adding new nodes of the same type as some old node might also make new resources available.\n\nExactly one of NodeName, NodeSelector, AllNodes, and PerDeviceNodeSelection must be set. This field is immutable.",
234                    "type": "string",
235                },
236                "nodeSelector": ({
237                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>();
238                    schema_obj.ensure_object().insert("description".into(), "NodeSelector defines which nodes have access to the resources in the pool, when that pool is not limited to a single node.\n\nMust use exactly one term.\n\nExactly one of NodeName, NodeSelector, AllNodes, and PerDeviceNodeSelection must be set.".into());
239                    schema_obj
240                }),
241                "perDeviceNodeSelection": {
242                    "description": "PerDeviceNodeSelection defines whether the access from nodes to resources in the pool is set on the ResourceSlice level or on each device. If it is set to true, every device defined the ResourceSlice must specify this individually.\n\nExactly one of NodeName, NodeSelector, AllNodes, and PerDeviceNodeSelection must be set.",
243                    "type": "boolean",
244                },
245                "pool": ({
246                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::ResourcePool>();
247                    schema_obj.ensure_object().insert("description".into(), "Pool describes the pool that this ResourceSlice belongs to.".into());
248                    schema_obj
249                }),
250                "sharedCounters": {
251                    "description": "SharedCounters defines a list of counter sets, each of which has a name and a list of counters available.\n\nThe names of the SharedCounters must be unique in the ResourceSlice.\n\nThe maximum number of SharedCounters is 32.",
252                    "type": "array",
253                    "items": (__gen.subschema_for::<crate::api::resource::v1beta1::CounterSet>()),
254                },
255            },
256            "required": [
257                "driver",
258                "pool",
259            ],
260        })
261    }
262}