k8s_openapi/v1_35/api/resource/v1beta2/
resource_slice_spec.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceSliceSpec {
6 pub all_nodes: Option<bool>,
10
11 pub devices: Option<std::vec::Vec<crate::api::resource::v1beta2::Device>>,
17
18 pub driver: std::string::String,
22
23 pub node_name: Option<std::string::String>,
29
30 pub node_selector: Option<crate::api::core::v1::NodeSelector>,
36
37 pub per_device_node_selection: Option<bool>,
41
42 pub pool: crate::api::resource::v1beta2::ResourcePool,
44
45 pub shared_counters: Option<std::vec::Vec<crate::api::resource::v1beta2::CounterSet>>,
53}
54
55impl crate::DeepMerge for ResourceSliceSpec {
56 fn merge_from(&mut self, other: Self) {
57 crate::DeepMerge::merge_from(&mut self.all_nodes, other.all_nodes);
58 crate::merge_strategies::list::atomic(&mut self.devices, other.devices);
59 crate::DeepMerge::merge_from(&mut self.driver, other.driver);
60 crate::DeepMerge::merge_from(&mut self.node_name, other.node_name);
61 crate::DeepMerge::merge_from(&mut self.node_selector, other.node_selector);
62 crate::DeepMerge::merge_from(&mut self.per_device_node_selection, other.per_device_node_selection);
63 crate::DeepMerge::merge_from(&mut self.pool, other.pool);
64 crate::merge_strategies::list::atomic(&mut self.shared_counters, other.shared_counters);
65 }
66}
67
68impl<'de> crate::serde::Deserialize<'de> for ResourceSliceSpec {
69 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
70 #[allow(non_camel_case_types)]
71 enum Field {
72 Key_all_nodes,
73 Key_devices,
74 Key_driver,
75 Key_node_name,
76 Key_node_selector,
77 Key_per_device_node_selection,
78 Key_pool,
79 Key_shared_counters,
80 Other,
81 }
82
83 impl<'de> crate::serde::Deserialize<'de> for Field {
84 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
85 struct Visitor;
86
87 impl crate::serde::de::Visitor<'_> for Visitor {
88 type Value = Field;
89
90 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
91 f.write_str("field identifier")
92 }
93
94 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
95 Ok(match v {
96 "allNodes" => Field::Key_all_nodes,
97 "devices" => Field::Key_devices,
98 "driver" => Field::Key_driver,
99 "nodeName" => Field::Key_node_name,
100 "nodeSelector" => Field::Key_node_selector,
101 "perDeviceNodeSelection" => Field::Key_per_device_node_selection,
102 "pool" => Field::Key_pool,
103 "sharedCounters" => Field::Key_shared_counters,
104 _ => Field::Other,
105 })
106 }
107 }
108
109 deserializer.deserialize_identifier(Visitor)
110 }
111 }
112
113 struct Visitor;
114
115 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
116 type Value = ResourceSliceSpec;
117
118 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
119 f.write_str("ResourceSliceSpec")
120 }
121
122 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
123 let mut value_all_nodes: Option<bool> = None;
124 let mut value_devices: Option<std::vec::Vec<crate::api::resource::v1beta2::Device>> = None;
125 let mut value_driver: Option<std::string::String> = None;
126 let mut value_node_name: Option<std::string::String> = None;
127 let mut value_node_selector: Option<crate::api::core::v1::NodeSelector> = None;
128 let mut value_per_device_node_selection: Option<bool> = None;
129 let mut value_pool: Option<crate::api::resource::v1beta2::ResourcePool> = None;
130 let mut value_shared_counters: Option<std::vec::Vec<crate::api::resource::v1beta2::CounterSet>> = None;
131
132 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
133 match key {
134 Field::Key_all_nodes => value_all_nodes = crate::serde::de::MapAccess::next_value(&mut map)?,
135 Field::Key_devices => value_devices = crate::serde::de::MapAccess::next_value(&mut map)?,
136 Field::Key_driver => value_driver = crate::serde::de::MapAccess::next_value(&mut map)?,
137 Field::Key_node_name => value_node_name = crate::serde::de::MapAccess::next_value(&mut map)?,
138 Field::Key_node_selector => value_node_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
139 Field::Key_per_device_node_selection => value_per_device_node_selection = crate::serde::de::MapAccess::next_value(&mut map)?,
140 Field::Key_pool => value_pool = crate::serde::de::MapAccess::next_value(&mut map)?,
141 Field::Key_shared_counters => value_shared_counters = crate::serde::de::MapAccess::next_value(&mut map)?,
142 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
143 }
144 }
145
146 Ok(ResourceSliceSpec {
147 all_nodes: value_all_nodes,
148 devices: value_devices,
149 driver: value_driver.unwrap_or_default(),
150 node_name: value_node_name,
151 node_selector: value_node_selector,
152 per_device_node_selection: value_per_device_node_selection,
153 pool: value_pool.unwrap_or_default(),
154 shared_counters: value_shared_counters,
155 })
156 }
157 }
158
159 deserializer.deserialize_struct(
160 "ResourceSliceSpec",
161 &[
162 "allNodes",
163 "devices",
164 "driver",
165 "nodeName",
166 "nodeSelector",
167 "perDeviceNodeSelection",
168 "pool",
169 "sharedCounters",
170 ],
171 Visitor,
172 )
173 }
174}
175
176impl crate::serde::Serialize for ResourceSliceSpec {
177 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
178 let mut state = serializer.serialize_struct(
179 "ResourceSliceSpec",
180 2 +
181 self.all_nodes.as_ref().map_or(0, |_| 1) +
182 self.devices.as_ref().map_or(0, |_| 1) +
183 self.node_name.as_ref().map_or(0, |_| 1) +
184 self.node_selector.as_ref().map_or(0, |_| 1) +
185 self.per_device_node_selection.as_ref().map_or(0, |_| 1) +
186 self.shared_counters.as_ref().map_or(0, |_| 1),
187 )?;
188 if let Some(value) = &self.all_nodes {
189 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allNodes", value)?;
190 }
191 if let Some(value) = &self.devices {
192 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "devices", value)?;
193 }
194 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "driver", &self.driver)?;
195 if let Some(value) = &self.node_name {
196 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeName", value)?;
197 }
198 if let Some(value) = &self.node_selector {
199 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeSelector", value)?;
200 }
201 if let Some(value) = &self.per_device_node_selection {
202 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "perDeviceNodeSelection", value)?;
203 }
204 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pool", &self.pool)?;
205 if let Some(value) = &self.shared_counters {
206 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "sharedCounters", value)?;
207 }
208 crate::serde::ser::SerializeStruct::end(state)
209 }
210}
211
212#[cfg(feature = "schemars")]
213impl crate::schemars::JsonSchema for ResourceSliceSpec {
214 fn schema_name() -> std::borrow::Cow<'static, str> {
215 "io.k8s.api.resource.v1beta2.ResourceSliceSpec".into()
216 }
217
218 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
219 crate::schemars::json_schema!({
220 "description": "ResourceSliceSpec contains the information published by the driver in one ResourceSlice.",
221 "type": "object",
222 "properties": {
223 "allNodes": {
224 "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.",
225 "type": "boolean",
226 },
227 "devices": {
228 "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.",
229 "type": "array",
230 "items": (__gen.subschema_for::<crate::api::resource::v1beta2::Device>()),
231 },
232 "driver": {
233 "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.",
234 "type": "string",
235 },
236 "nodeName": {
237 "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.",
238 "type": "string",
239 },
240 "nodeSelector": ({
241 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>();
242 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());
243 schema_obj
244 }),
245 "perDeviceNodeSelection": {
246 "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.",
247 "type": "boolean",
248 },
249 "pool": ({
250 let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::ResourcePool>();
251 schema_obj.ensure_object().insert("description".into(), "Pool describes the pool that this ResourceSlice belongs to.".into());
252 schema_obj
253 }),
254 "sharedCounters": {
255 "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.",
256 "type": "array",
257 "items": (__gen.subschema_for::<crate::api::resource::v1beta2::CounterSet>()),
258 },
259 },
260 "required": [
261 "driver",
262 "pool",
263 ],
264 })
265 }
266}