Skip to main content

k8s_openapi/v1_37/api/resource/v1beta2/
resource_slice_spec.rs

1// Generated from definition io.k8s.api.resource.v1beta2.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. If any device uses taints or consumes counters the limit is 64.
14    ///
15    /// Only one of Devices and SharedCounters can be set in a ResourceSlice.
16    pub devices: Option<std::vec::Vec<crate::api::resource::v1beta2::Device>>,
17
18    /// 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.
19    ///
20    /// Must be a DNS subdomain and should end with a DNS domain owned by the vendor of the driver. It should use only lower case characters. This field is immutable.
21    pub driver: std::string::String,
22
23    /// 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.
24    ///
25    /// 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.
26    ///
27    /// Exactly one of NodeName, NodeSelector, AllNodes, and PerDeviceNodeSelection must be set. This field is immutable.
28    pub node_name: Option<std::string::String>,
29
30    /// NodeSelector defines which nodes have access to the resources in the pool, when that pool is not limited to a single node.
31    ///
32    /// Must use exactly one term.
33    ///
34    /// Exactly one of NodeName, NodeSelector, AllNodes, and PerDeviceNodeSelection must be set.
35    pub node_selector: Option<crate::api::core::v1::NodeSelector>,
36
37    /// PartitionTypeAttribute names a string device attribute (by fully qualified name, e.g. "gpu.example.com/profile") whose value labels each device with its partition type, such as "Full" or "Half" for a MIG-style GPU.
38    ///
39    /// When set, every partitionable device in the slice must carry the attribute and devices sharing a value must share the same ConsumesCounters cost.
40    pub partition_type_attribute: Option<std::string::String>,
41
42    /// 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.
43    ///
44    /// Exactly one of NodeName, NodeSelector, AllNodes, and PerDeviceNodeSelection must be set.
45    pub per_device_node_selection: Option<bool>,
46
47    /// Pool describes the pool that this ResourceSlice belongs to.
48    pub pool: crate::api::resource::v1beta2::ResourcePool,
49
50    /// SharedCounters defines a list of counter sets, each of which has a name and a list of counters available.
51    ///
52    /// The names of the counter sets must be unique in the ResourcePool.
53    ///
54    /// Only one of Devices and SharedCounters can be set in a ResourceSlice.
55    ///
56    /// The maximum number of counter sets is 8.
57    pub shared_counters: Option<std::vec::Vec<crate::api::resource::v1beta2::CounterSet>>,
58
59    /// SkipNodeOperations lists node-local resource operations (gRPC calls) that will be skipped for the devices in this slice when determining whether operations are necessary on the node. If all allocated devices for a driver in a claim skip an operation, that gRPC call will be skipped. Valid values are:
60    ///
61    /// - "NodePrepareResources": NodePrepareResources gRPC calls are skipped. This
62    ///   value cannot be specified unless "NodeUnprepareResources" is also listed
63    ///   (or "*" is specified).
64    /// - "NodeUnprepareResources": NodeUnprepareResources gRPC calls are skipped. - "*": All node-local resource operations are skipped.
65    ///
66    /// Other values may be added in the future. The kubelet must ignore unknown values.
67    pub skip_node_operations: Option<std::vec::Vec<std::string::String>>,
68}
69
70impl crate::DeepMerge for ResourceSliceSpec {
71    fn merge_from(&mut self, other: Self) {
72        crate::DeepMerge::merge_from(&mut self.all_nodes, other.all_nodes);
73        crate::merge_strategies::list::atomic(&mut self.devices, other.devices);
74        crate::DeepMerge::merge_from(&mut self.driver, other.driver);
75        crate::DeepMerge::merge_from(&mut self.node_name, other.node_name);
76        crate::DeepMerge::merge_from(&mut self.node_selector, other.node_selector);
77        crate::DeepMerge::merge_from(&mut self.partition_type_attribute, other.partition_type_attribute);
78        crate::DeepMerge::merge_from(&mut self.per_device_node_selection, other.per_device_node_selection);
79        crate::DeepMerge::merge_from(&mut self.pool, other.pool);
80        crate::merge_strategies::list::atomic(&mut self.shared_counters, other.shared_counters);
81        crate::merge_strategies::list::set(&mut self.skip_node_operations, other.skip_node_operations);
82    }
83}
84
85impl<'de> crate::serde::Deserialize<'de> for ResourceSliceSpec {
86    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
87        #[allow(non_camel_case_types)]
88        enum Field {
89            Key_all_nodes,
90            Key_devices,
91            Key_driver,
92            Key_node_name,
93            Key_node_selector,
94            Key_partition_type_attribute,
95            Key_per_device_node_selection,
96            Key_pool,
97            Key_shared_counters,
98            Key_skip_node_operations,
99            Other,
100        }
101
102        impl<'de> crate::serde::Deserialize<'de> for Field {
103            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
104                struct Visitor;
105
106                impl crate::serde::de::Visitor<'_> for Visitor {
107                    type Value = Field;
108
109                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
110                        f.write_str("field identifier")
111                    }
112
113                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
114                        Ok(match v {
115                            "allNodes" => Field::Key_all_nodes,
116                            "devices" => Field::Key_devices,
117                            "driver" => Field::Key_driver,
118                            "nodeName" => Field::Key_node_name,
119                            "nodeSelector" => Field::Key_node_selector,
120                            "partitionTypeAttribute" => Field::Key_partition_type_attribute,
121                            "perDeviceNodeSelection" => Field::Key_per_device_node_selection,
122                            "pool" => Field::Key_pool,
123                            "sharedCounters" => Field::Key_shared_counters,
124                            "skipNodeOperations" => Field::Key_skip_node_operations,
125                            _ => Field::Other,
126                        })
127                    }
128                }
129
130                deserializer.deserialize_identifier(Visitor)
131            }
132        }
133
134        struct Visitor;
135
136        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
137            type Value = ResourceSliceSpec;
138
139            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
140                f.write_str("ResourceSliceSpec")
141            }
142
143            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
144                let mut value_all_nodes: Option<bool> = None;
145                let mut value_devices: Option<std::vec::Vec<crate::api::resource::v1beta2::Device>> = None;
146                let mut value_driver: Option<std::string::String> = None;
147                let mut value_node_name: Option<std::string::String> = None;
148                let mut value_node_selector: Option<crate::api::core::v1::NodeSelector> = None;
149                let mut value_partition_type_attribute: Option<std::string::String> = None;
150                let mut value_per_device_node_selection: Option<bool> = None;
151                let mut value_pool: Option<crate::api::resource::v1beta2::ResourcePool> = None;
152                let mut value_shared_counters: Option<std::vec::Vec<crate::api::resource::v1beta2::CounterSet>> = None;
153                let mut value_skip_node_operations: Option<std::vec::Vec<std::string::String>> = None;
154
155                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
156                    match key {
157                        Field::Key_all_nodes => value_all_nodes = crate::serde::de::MapAccess::next_value(&mut map)?,
158                        Field::Key_devices => value_devices = crate::serde::de::MapAccess::next_value(&mut map)?,
159                        Field::Key_driver => value_driver = crate::serde::de::MapAccess::next_value(&mut map)?,
160                        Field::Key_node_name => value_node_name = crate::serde::de::MapAccess::next_value(&mut map)?,
161                        Field::Key_node_selector => value_node_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
162                        Field::Key_partition_type_attribute => value_partition_type_attribute = crate::serde::de::MapAccess::next_value(&mut map)?,
163                        Field::Key_per_device_node_selection => value_per_device_node_selection = crate::serde::de::MapAccess::next_value(&mut map)?,
164                        Field::Key_pool => value_pool = crate::serde::de::MapAccess::next_value(&mut map)?,
165                        Field::Key_shared_counters => value_shared_counters = crate::serde::de::MapAccess::next_value(&mut map)?,
166                        Field::Key_skip_node_operations => value_skip_node_operations = crate::serde::de::MapAccess::next_value(&mut map)?,
167                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
168                    }
169                }
170
171                Ok(ResourceSliceSpec {
172                    all_nodes: value_all_nodes,
173                    devices: value_devices,
174                    driver: value_driver.unwrap_or_default(),
175                    node_name: value_node_name,
176                    node_selector: value_node_selector,
177                    partition_type_attribute: value_partition_type_attribute,
178                    per_device_node_selection: value_per_device_node_selection,
179                    pool: value_pool.unwrap_or_default(),
180                    shared_counters: value_shared_counters,
181                    skip_node_operations: value_skip_node_operations,
182                })
183            }
184        }
185
186        deserializer.deserialize_struct(
187            "ResourceSliceSpec",
188            &[
189                "allNodes",
190                "devices",
191                "driver",
192                "nodeName",
193                "nodeSelector",
194                "partitionTypeAttribute",
195                "perDeviceNodeSelection",
196                "pool",
197                "sharedCounters",
198                "skipNodeOperations",
199            ],
200            Visitor,
201        )
202    }
203}
204
205impl crate::serde::Serialize for ResourceSliceSpec {
206    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
207        let mut state = serializer.serialize_struct(
208            "ResourceSliceSpec",
209            2 +
210            self.all_nodes.as_ref().map_or(0, |_| 1) +
211            self.devices.as_ref().map_or(0, |_| 1) +
212            self.node_name.as_ref().map_or(0, |_| 1) +
213            self.node_selector.as_ref().map_or(0, |_| 1) +
214            self.partition_type_attribute.as_ref().map_or(0, |_| 1) +
215            self.per_device_node_selection.as_ref().map_or(0, |_| 1) +
216            self.shared_counters.as_ref().map_or(0, |_| 1) +
217            self.skip_node_operations.as_ref().map_or(0, |_| 1),
218        )?;
219        if let Some(value) = &self.all_nodes {
220            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allNodes", value)?;
221        }
222        if let Some(value) = &self.devices {
223            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "devices", value)?;
224        }
225        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "driver", &self.driver)?;
226        if let Some(value) = &self.node_name {
227            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeName", value)?;
228        }
229        if let Some(value) = &self.node_selector {
230            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeSelector", value)?;
231        }
232        if let Some(value) = &self.partition_type_attribute {
233            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "partitionTypeAttribute", value)?;
234        }
235        if let Some(value) = &self.per_device_node_selection {
236            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "perDeviceNodeSelection", value)?;
237        }
238        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pool", &self.pool)?;
239        if let Some(value) = &self.shared_counters {
240            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sharedCounters", value)?;
241        }
242        if let Some(value) = &self.skip_node_operations {
243            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "skipNodeOperations", value)?;
244        }
245        crate::serde::ser::SerializeStruct::end(state)
246    }
247}
248
249#[cfg(feature = "schemars")]
250impl crate::schemars::JsonSchema for ResourceSliceSpec {
251    fn schema_name() -> std::borrow::Cow<'static, str> {
252        "io.k8s.api.resource.v1beta2.ResourceSliceSpec".into()
253    }
254
255    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
256        crate::schemars::json_schema!({
257            "description": "ResourceSliceSpec contains the information published by the driver in one ResourceSlice.",
258            "type": "object",
259            "properties": {
260                "allNodes": {
261                    "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.",
262                    "type": "boolean",
263                },
264                "devices": {
265                    "description": "Devices lists some or all of the devices in this pool.\n\nMust not have more than 128 entries. If any device uses taints or consumes counters the limit is 64.\n\nOnly one of Devices and SharedCounters can be set in a ResourceSlice.",
266                    "type": "array",
267                    "items": (__gen.subschema_for::<crate::api::resource::v1beta2::Device>()),
268                },
269                "driver": {
270                    "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. It should use only lower case characters. This field is immutable.",
271                    "type": "string",
272                },
273                "nodeName": {
274                    "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.",
275                    "type": "string",
276                },
277                "nodeSelector": ({
278                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>();
279                    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());
280                    schema_obj
281                }),
282                "partitionTypeAttribute": {
283                    "description": "PartitionTypeAttribute names a string device attribute (by fully qualified name, e.g. \"gpu.example.com/profile\") whose value labels each device with its partition type, such as \"Full\" or \"Half\" for a MIG-style GPU.\n\nWhen set, every partitionable device in the slice must carry the attribute and devices sharing a value must share the same ConsumesCounters cost.",
284                    "type": "string",
285                },
286                "perDeviceNodeSelection": {
287                    "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.",
288                    "type": "boolean",
289                },
290                "pool": ({
291                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::ResourcePool>();
292                    schema_obj.ensure_object().insert("description".into(), "Pool describes the pool that this ResourceSlice belongs to.".into());
293                    schema_obj
294                }),
295                "sharedCounters": {
296                    "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 counter sets must be unique in the ResourcePool.\n\nOnly one of Devices and SharedCounters can be set in a ResourceSlice.\n\nThe maximum number of counter sets is 8.",
297                    "type": "array",
298                    "items": (__gen.subschema_for::<crate::api::resource::v1beta2::CounterSet>()),
299                },
300                "skipNodeOperations": {
301                    "description": "SkipNodeOperations lists node-local resource operations (gRPC calls) that will be skipped for the devices in this slice when determining whether operations are necessary on the node. If all allocated devices for a driver in a claim skip an operation, that gRPC call will be skipped. Valid values are:\n\n- \"NodePrepareResources\": NodePrepareResources gRPC calls are skipped. This\n  value cannot be specified unless \"NodeUnprepareResources\" is also listed\n  (or \"*\" is specified).\n- \"NodeUnprepareResources\": NodeUnprepareResources gRPC calls are skipped. - \"*\": All node-local resource operations are skipped.\n\nOther values may be added in the future. The kubelet must ignore unknown values.",
302                    "type": "array",
303                    "items": {
304                        "type": "string",
305                    },
306                },
307            },
308            "required": [
309                "driver",
310                "pool",
311            ],
312        })
313    }
314}