k8s_openapi/v1_31/api/resource/v1alpha3/
device_class_spec.rs

1// Generated from definition io.k8s.api.resource.v1alpha3.DeviceClassSpec
2
3/// DeviceClassSpec is used in a \[DeviceClass\] to define what can be allocated and how to configure it.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceClassSpec {
6    /// Config defines configuration parameters that apply to each device that is claimed via this class. Some classses may potentially be satisfied by multiple drivers, so each instance of a vendor configuration applies to exactly one driver.
7    ///
8    /// They are passed to the driver, but are not considered while allocating the claim.
9    pub config: Option<std::vec::Vec<crate::api::resource::v1alpha3::DeviceClassConfiguration>>,
10
11    /// Each selector must be satisfied by a device which is claimed via this class.
12    pub selectors: Option<std::vec::Vec<crate::api::resource::v1alpha3::DeviceSelector>>,
13
14    /// Only nodes matching the selector will be considered by the scheduler when trying to find a Node that fits a Pod when that Pod uses a claim that has not been allocated yet *and* that claim gets allocated through a control plane controller. It is ignored when the claim does not use a control plane controller for allocation.
15    ///
16    /// Setting this field is optional. If unset, all Nodes are candidates.
17    ///
18    /// This is an alpha field and requires enabling the DRAControlPlaneController feature gate.
19    pub suitable_nodes: Option<crate::api::core::v1::NodeSelector>,
20}
21
22impl crate::DeepMerge for DeviceClassSpec {
23    fn merge_from(&mut self, other: Self) {
24        crate::merge_strategies::list::atomic(&mut self.config, other.config);
25        crate::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
26        crate::DeepMerge::merge_from(&mut self.suitable_nodes, other.suitable_nodes);
27    }
28}
29
30impl<'de> crate::serde::Deserialize<'de> for DeviceClassSpec {
31    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
32        #[allow(non_camel_case_types)]
33        enum Field {
34            Key_config,
35            Key_selectors,
36            Key_suitable_nodes,
37            Other,
38        }
39
40        impl<'de> crate::serde::Deserialize<'de> for Field {
41            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
42                struct Visitor;
43
44                impl crate::serde::de::Visitor<'_> for Visitor {
45                    type Value = Field;
46
47                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
48                        f.write_str("field identifier")
49                    }
50
51                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
52                        Ok(match v {
53                            "config" => Field::Key_config,
54                            "selectors" => Field::Key_selectors,
55                            "suitableNodes" => Field::Key_suitable_nodes,
56                            _ => Field::Other,
57                        })
58                    }
59                }
60
61                deserializer.deserialize_identifier(Visitor)
62            }
63        }
64
65        struct Visitor;
66
67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68            type Value = DeviceClassSpec;
69
70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71                f.write_str("DeviceClassSpec")
72            }
73
74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75                let mut value_config: Option<std::vec::Vec<crate::api::resource::v1alpha3::DeviceClassConfiguration>> = None;
76                let mut value_selectors: Option<std::vec::Vec<crate::api::resource::v1alpha3::DeviceSelector>> = None;
77                let mut value_suitable_nodes: Option<crate::api::core::v1::NodeSelector> = None;
78
79                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
80                    match key {
81                        Field::Key_config => value_config = crate::serde::de::MapAccess::next_value(&mut map)?,
82                        Field::Key_selectors => value_selectors = crate::serde::de::MapAccess::next_value(&mut map)?,
83                        Field::Key_suitable_nodes => value_suitable_nodes = crate::serde::de::MapAccess::next_value(&mut map)?,
84                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
85                    }
86                }
87
88                Ok(DeviceClassSpec {
89                    config: value_config,
90                    selectors: value_selectors,
91                    suitable_nodes: value_suitable_nodes,
92                })
93            }
94        }
95
96        deserializer.deserialize_struct(
97            "DeviceClassSpec",
98            &[
99                "config",
100                "selectors",
101                "suitableNodes",
102            ],
103            Visitor,
104        )
105    }
106}
107
108impl crate::serde::Serialize for DeviceClassSpec {
109    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
110        let mut state = serializer.serialize_struct(
111            "DeviceClassSpec",
112            self.config.as_ref().map_or(0, |_| 1) +
113            self.selectors.as_ref().map_or(0, |_| 1) +
114            self.suitable_nodes.as_ref().map_or(0, |_| 1),
115        )?;
116        if let Some(value) = &self.config {
117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "config", value)?;
118        }
119        if let Some(value) = &self.selectors {
120            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
121        }
122        if let Some(value) = &self.suitable_nodes {
123            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "suitableNodes", value)?;
124        }
125        crate::serde::ser::SerializeStruct::end(state)
126    }
127}
128
129#[cfg(feature = "schemars")]
130impl crate::schemars::JsonSchema for DeviceClassSpec {
131    fn schema_name() -> std::string::String {
132        "io.k8s.api.resource.v1alpha3.DeviceClassSpec".into()
133    }
134
135    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
136        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
137            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
138                description: Some("DeviceClassSpec is used in a [DeviceClass] to define what can be allocated and how to configure it.".into()),
139                ..Default::default()
140            })),
141            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
142            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
143                properties: [
144                    (
145                        "config".into(),
146                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
147                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
148                                description: Some("Config defines configuration parameters that apply to each device that is claimed via this class. Some classses may potentially be satisfied by multiple drivers, so each instance of a vendor configuration applies to exactly one driver.\n\nThey are passed to the driver, but are not considered while allocating the claim.".into()),
149                                ..Default::default()
150                            })),
151                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
152                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
153                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1alpha3::DeviceClassConfiguration>()))),
154                                ..Default::default()
155                            })),
156                            ..Default::default()
157                        }),
158                    ),
159                    (
160                        "selectors".into(),
161                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
162                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
163                                description: Some("Each selector must be satisfied by a device which is claimed via this class.".into()),
164                                ..Default::default()
165                            })),
166                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
167                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
168                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1alpha3::DeviceSelector>()))),
169                                ..Default::default()
170                            })),
171                            ..Default::default()
172                        }),
173                    ),
174                    (
175                        "suitableNodes".into(),
176                        {
177                            let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>().into_object();
178                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
179                                description: Some("Only nodes matching the selector will be considered by the scheduler when trying to find a Node that fits a Pod when that Pod uses a claim that has not been allocated yet *and* that claim gets allocated through a control plane controller. It is ignored when the claim does not use a control plane controller for allocation.\n\nSetting this field is optional. If unset, all Nodes are candidates.\n\nThis is an alpha field and requires enabling the DRAControlPlaneController feature gate.".into()),
180                                ..Default::default()
181                            }));
182                            crate::schemars::schema::Schema::Object(schema_obj)
183                        },
184                    ),
185                ].into(),
186                ..Default::default()
187            })),
188            ..Default::default()
189        })
190    }
191}