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

1// Generated from definition io.k8s.api.resource.v1alpha3.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::v1alpha3::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::v1alpha3::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::v1alpha3::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::v1alpha3::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::v1alpha3::ResourcePool> = None;
126                let mut value_shared_counters: Option<std::vec::Vec<crate::api::resource::v1alpha3::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::string::String {
211        "io.k8s.api.resource.v1alpha3.ResourceSliceSpec".into()
212    }
213
214    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
215        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
216            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
217                description: Some("ResourceSliceSpec contains the information published by the driver in one ResourceSlice.".into()),
218                ..Default::default()
219            })),
220            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
221            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
222                properties: [
223                    (
224                        "allNodes".into(),
225                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
226                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
227                                description: Some("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.".into()),
228                                ..Default::default()
229                            })),
230                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Boolean))),
231                            ..Default::default()
232                        }),
233                    ),
234                    (
235                        "devices".into(),
236                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
237                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
238                                description: Some("Devices lists some or all of the devices in this pool.\n\nMust not have more than 128 entries.".into()),
239                                ..Default::default()
240                            })),
241                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
242                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
243                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1alpha3::Device>()))),
244                                ..Default::default()
245                            })),
246                            ..Default::default()
247                        }),
248                    ),
249                    (
250                        "driver".into(),
251                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
252                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
253                                description: Some("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.".into()),
254                                ..Default::default()
255                            })),
256                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
257                            ..Default::default()
258                        }),
259                    ),
260                    (
261                        "nodeName".into(),
262                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
263                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
264                                description: Some("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.".into()),
265                                ..Default::default()
266                            })),
267                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
268                            ..Default::default()
269                        }),
270                    ),
271                    (
272                        "nodeSelector".into(),
273                        {
274                            let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>().into_object();
275                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
276                                description: Some("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()),
277                                ..Default::default()
278                            }));
279                            crate::schemars::schema::Schema::Object(schema_obj)
280                        },
281                    ),
282                    (
283                        "perDeviceNodeSelection".into(),
284                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
285                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
286                                description: Some("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.".into()),
287                                ..Default::default()
288                            })),
289                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Boolean))),
290                            ..Default::default()
291                        }),
292                    ),
293                    (
294                        "pool".into(),
295                        {
296                            let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1alpha3::ResourcePool>().into_object();
297                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
298                                description: Some("Pool describes the pool that this ResourceSlice belongs to.".into()),
299                                ..Default::default()
300                            }));
301                            crate::schemars::schema::Schema::Object(schema_obj)
302                        },
303                    ),
304                    (
305                        "sharedCounters".into(),
306                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
307                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
308                                description: Some("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.".into()),
309                                ..Default::default()
310                            })),
311                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
312                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
313                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1alpha3::CounterSet>()))),
314                                ..Default::default()
315                            })),
316                            ..Default::default()
317                        }),
318                    ),
319                ].into(),
320                required: [
321                    "driver".into(),
322                    "pool".into(),
323                ].into(),
324                ..Default::default()
325            })),
326            ..Default::default()
327        })
328    }
329}