Skip to main content

k8s_openapi/v1_32/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 and AllNodes 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 and AllNodes 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 and AllNodes must be set.
33    pub node_selector: Option<crate::api::core::v1::NodeSelector>,
34
35    /// Pool describes the pool that this ResourceSlice belongs to.
36    pub pool: crate::api::resource::v1beta1::ResourcePool,
37}
38
39impl crate::DeepMerge for ResourceSliceSpec {
40    fn merge_from(&mut self, other: Self) {
41        crate::DeepMerge::merge_from(&mut self.all_nodes, other.all_nodes);
42        crate::merge_strategies::list::atomic(&mut self.devices, other.devices);
43        crate::DeepMerge::merge_from(&mut self.driver, other.driver);
44        crate::DeepMerge::merge_from(&mut self.node_name, other.node_name);
45        crate::DeepMerge::merge_from(&mut self.node_selector, other.node_selector);
46        crate::DeepMerge::merge_from(&mut self.pool, other.pool);
47    }
48}
49
50impl<'de> crate::serde::Deserialize<'de> for ResourceSliceSpec {
51    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
52        #[allow(non_camel_case_types)]
53        enum Field {
54            Key_all_nodes,
55            Key_devices,
56            Key_driver,
57            Key_node_name,
58            Key_node_selector,
59            Key_pool,
60            Other,
61        }
62
63        impl<'de> crate::serde::Deserialize<'de> for Field {
64            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
65                struct Visitor;
66
67                impl crate::serde::de::Visitor<'_> for Visitor {
68                    type Value = Field;
69
70                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71                        f.write_str("field identifier")
72                    }
73
74                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
75                        Ok(match v {
76                            "allNodes" => Field::Key_all_nodes,
77                            "devices" => Field::Key_devices,
78                            "driver" => Field::Key_driver,
79                            "nodeName" => Field::Key_node_name,
80                            "nodeSelector" => Field::Key_node_selector,
81                            "pool" => Field::Key_pool,
82                            _ => Field::Other,
83                        })
84                    }
85                }
86
87                deserializer.deserialize_identifier(Visitor)
88            }
89        }
90
91        struct Visitor;
92
93        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
94            type Value = ResourceSliceSpec;
95
96            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
97                f.write_str("ResourceSliceSpec")
98            }
99
100            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
101                let mut value_all_nodes: Option<bool> = None;
102                let mut value_devices: Option<std::vec::Vec<crate::api::resource::v1beta1::Device>> = None;
103                let mut value_driver: Option<std::string::String> = None;
104                let mut value_node_name: Option<std::string::String> = None;
105                let mut value_node_selector: Option<crate::api::core::v1::NodeSelector> = None;
106                let mut value_pool: Option<crate::api::resource::v1beta1::ResourcePool> = None;
107
108                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
109                    match key {
110                        Field::Key_all_nodes => value_all_nodes = crate::serde::de::MapAccess::next_value(&mut map)?,
111                        Field::Key_devices => value_devices = crate::serde::de::MapAccess::next_value(&mut map)?,
112                        Field::Key_driver => value_driver = crate::serde::de::MapAccess::next_value(&mut map)?,
113                        Field::Key_node_name => value_node_name = crate::serde::de::MapAccess::next_value(&mut map)?,
114                        Field::Key_node_selector => value_node_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
115                        Field::Key_pool => value_pool = crate::serde::de::MapAccess::next_value(&mut map)?,
116                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
117                    }
118                }
119
120                Ok(ResourceSliceSpec {
121                    all_nodes: value_all_nodes,
122                    devices: value_devices,
123                    driver: value_driver.unwrap_or_default(),
124                    node_name: value_node_name,
125                    node_selector: value_node_selector,
126                    pool: value_pool.unwrap_or_default(),
127                })
128            }
129        }
130
131        deserializer.deserialize_struct(
132            "ResourceSliceSpec",
133            &[
134                "allNodes",
135                "devices",
136                "driver",
137                "nodeName",
138                "nodeSelector",
139                "pool",
140            ],
141            Visitor,
142        )
143    }
144}
145
146impl crate::serde::Serialize for ResourceSliceSpec {
147    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
148        let mut state = serializer.serialize_struct(
149            "ResourceSliceSpec",
150            2 +
151            self.all_nodes.as_ref().map_or(0, |_| 1) +
152            self.devices.as_ref().map_or(0, |_| 1) +
153            self.node_name.as_ref().map_or(0, |_| 1) +
154            self.node_selector.as_ref().map_or(0, |_| 1),
155        )?;
156        if let Some(value) = &self.all_nodes {
157            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allNodes", value)?;
158        }
159        if let Some(value) = &self.devices {
160            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "devices", value)?;
161        }
162        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "driver", &self.driver)?;
163        if let Some(value) = &self.node_name {
164            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeName", value)?;
165        }
166        if let Some(value) = &self.node_selector {
167            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeSelector", value)?;
168        }
169        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pool", &self.pool)?;
170        crate::serde::ser::SerializeStruct::end(state)
171    }
172}
173
174#[cfg(feature = "schemars")]
175impl crate::schemars::JsonSchema for ResourceSliceSpec {
176    fn schema_name() -> std::borrow::Cow<'static, str> {
177        "io.k8s.api.resource.v1beta1.ResourceSliceSpec".into()
178    }
179
180    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
181        crate::schemars::json_schema!({
182            "description": "ResourceSliceSpec contains the information published by the driver in one ResourceSlice.",
183            "type": "object",
184            "properties": {
185                "allNodes": {
186                    "description": "AllNodes indicates that all nodes have access to the resources in the pool.\n\nExactly one of NodeName, NodeSelector and AllNodes must be set.",
187                    "type": "boolean",
188                },
189                "devices": {
190                    "description": "Devices lists some or all of the devices in this pool.\n\nMust not have more than 128 entries.",
191                    "type": "array",
192                    "items": (__gen.subschema_for::<crate::api::resource::v1beta1::Device>()),
193                },
194                "driver": {
195                    "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.",
196                    "type": "string",
197                },
198                "nodeName": {
199                    "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 and AllNodes must be set. This field is immutable.",
200                    "type": "string",
201                },
202                "nodeSelector": ({
203                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>();
204                    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 and AllNodes must be set.".into());
205                    schema_obj
206                }),
207                "pool": ({
208                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::ResourcePool>();
209                    schema_obj.ensure_object().insert("description".into(), "Pool describes the pool that this ResourceSlice belongs to.".into());
210                    schema_obj
211                }),
212            },
213            "required": [
214                "driver",
215                "pool",
216            ],
217        })
218    }
219}