Skip to main content

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

1// Generated from definition io.k8s.api.resource.v1beta2.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::v1beta2::DeviceClassConfiguration>>,
10
11    /// ExtendedResourceName is the extended resource name for the devices of this class. The devices of this class can be used to satisfy a pod's extended resource requests. It has the same format as the name of a pod's extended resource. It should be unique among all the device classes in a cluster. If two device classes have the same name, then the class created later is picked to satisfy a pod's extended resource requests. If two classes are created at the same time, then the name of the class lexicographically sorted first is picked.
12    pub extended_resource_name: Option<std::string::String>,
13
14    /// Each selector must be satisfied by a device which is claimed via this class.
15    pub selectors: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSelector>>,
16}
17
18impl crate::DeepMerge for DeviceClassSpec {
19    fn merge_from(&mut self, other: Self) {
20        crate::merge_strategies::list::atomic(&mut self.config, other.config);
21        crate::DeepMerge::merge_from(&mut self.extended_resource_name, other.extended_resource_name);
22        crate::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
23    }
24}
25
26impl<'de> crate::serde::Deserialize<'de> for DeviceClassSpec {
27    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
28        #[allow(non_camel_case_types)]
29        enum Field {
30            Key_config,
31            Key_extended_resource_name,
32            Key_selectors,
33            Other,
34        }
35
36        impl<'de> crate::serde::Deserialize<'de> for Field {
37            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38                struct Visitor;
39
40                impl crate::serde::de::Visitor<'_> for Visitor {
41                    type Value = Field;
42
43                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44                        f.write_str("field identifier")
45                    }
46
47                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
48                        Ok(match v {
49                            "config" => Field::Key_config,
50                            "extendedResourceName" => Field::Key_extended_resource_name,
51                            "selectors" => Field::Key_selectors,
52                            _ => Field::Other,
53                        })
54                    }
55                }
56
57                deserializer.deserialize_identifier(Visitor)
58            }
59        }
60
61        struct Visitor;
62
63        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
64            type Value = DeviceClassSpec;
65
66            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67                f.write_str("DeviceClassSpec")
68            }
69
70            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
71                let mut value_config: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceClassConfiguration>> = None;
72                let mut value_extended_resource_name: Option<std::string::String> = None;
73                let mut value_selectors: Option<std::vec::Vec<crate::api::resource::v1beta2::DeviceSelector>> = None;
74
75                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
76                    match key {
77                        Field::Key_config => value_config = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Key_extended_resource_name => value_extended_resource_name = crate::serde::de::MapAccess::next_value(&mut map)?,
79                        Field::Key_selectors => value_selectors = crate::serde::de::MapAccess::next_value(&mut map)?,
80                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
81                    }
82                }
83
84                Ok(DeviceClassSpec {
85                    config: value_config,
86                    extended_resource_name: value_extended_resource_name,
87                    selectors: value_selectors,
88                })
89            }
90        }
91
92        deserializer.deserialize_struct(
93            "DeviceClassSpec",
94            &[
95                "config",
96                "extendedResourceName",
97                "selectors",
98            ],
99            Visitor,
100        )
101    }
102}
103
104impl crate::serde::Serialize for DeviceClassSpec {
105    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
106        let mut state = serializer.serialize_struct(
107            "DeviceClassSpec",
108            self.config.as_ref().map_or(0, |_| 1) +
109            self.extended_resource_name.as_ref().map_or(0, |_| 1) +
110            self.selectors.as_ref().map_or(0, |_| 1),
111        )?;
112        if let Some(value) = &self.config {
113            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "config", value)?;
114        }
115        if let Some(value) = &self.extended_resource_name {
116            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "extendedResourceName", value)?;
117        }
118        if let Some(value) = &self.selectors {
119            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
120        }
121        crate::serde::ser::SerializeStruct::end(state)
122    }
123}
124
125#[cfg(feature = "schemars")]
126impl crate::schemars::JsonSchema for DeviceClassSpec {
127    fn schema_name() -> std::borrow::Cow<'static, str> {
128        "io.k8s.api.resource.v1beta2.DeviceClassSpec".into()
129    }
130
131    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
132        crate::schemars::json_schema!({
133            "description": "DeviceClassSpec is used in a [DeviceClass] to define what can be allocated and how to configure it.",
134            "type": "object",
135            "properties": {
136                "config": {
137                    "description": "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.",
138                    "type": "array",
139                    "items": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceClassConfiguration>()),
140                },
141                "extendedResourceName": {
142                    "description": "ExtendedResourceName is the extended resource name for the devices of this class. The devices of this class can be used to satisfy a pod's extended resource requests. It has the same format as the name of a pod's extended resource. It should be unique among all the device classes in a cluster. If two device classes have the same name, then the class created later is picked to satisfy a pod's extended resource requests. If two classes are created at the same time, then the name of the class lexicographically sorted first is picked.",
143                    "type": "string",
144                },
145                "selectors": {
146                    "description": "Each selector must be satisfied by a device which is claimed via this class.",
147                    "type": "array",
148                    "items": (__gen.subschema_for::<crate::api::resource::v1beta2::DeviceSelector>()),
149                },
150            },
151        })
152    }
153}