Skip to main content

k8s_openapi/v1_36/api/resource/v1/
device_class.rs

1// Generated from definition io.k8s.api.resource.v1.DeviceClass
2
3/// DeviceClass is a vendor- or admin-provided resource that contains device configuration and selectors. It can be referenced in the device requests of a claim to apply these presets. Cluster scoped.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceClass {
6    /// Standard object metadata
7    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
8
9    /// Spec defines what can be allocated and how to configure it.
10    ///
11    /// This is mutable. Consumers have to be prepared for classes changing at any time, either because they get updated or replaced. Claim allocations are done once based on whatever was set in classes at the time of allocation.
12    ///
13    /// Changing the spec automatically increments the metadata.generation number.
14    pub spec: crate::api::resource::v1::DeviceClassSpec,
15}
16
17impl crate::Resource for DeviceClass {
18    const API_VERSION: &'static str = "resource.k8s.io/v1";
19    const GROUP: &'static str = "resource.k8s.io";
20    const KIND: &'static str = "DeviceClass";
21    const VERSION: &'static str = "v1";
22    const URL_PATH_SEGMENT: &'static str = "deviceclasses";
23    type Scope = crate::ClusterResourceScope;
24}
25
26impl crate::ListableResource for DeviceClass {
27    const LIST_KIND: &'static str = "DeviceClassList";
28}
29
30impl crate::Metadata for DeviceClass {
31    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
32
33    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
34        &self.metadata
35    }
36
37    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
38        &mut self.metadata
39    }
40}
41
42impl crate::DeepMerge for DeviceClass {
43    fn merge_from(&mut self, other: Self) {
44        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
45        crate::DeepMerge::merge_from(&mut self.spec, other.spec);
46    }
47}
48
49impl<'de> crate::serde::Deserialize<'de> for DeviceClass {
50    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
51        #[allow(non_camel_case_types)]
52        enum Field {
53            Key_api_version,
54            Key_kind,
55            Key_metadata,
56            Key_spec,
57            Other,
58        }
59
60        impl<'de> crate::serde::Deserialize<'de> for Field {
61            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
62                struct Visitor;
63
64                impl crate::serde::de::Visitor<'_> for Visitor {
65                    type Value = Field;
66
67                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
68                        f.write_str("field identifier")
69                    }
70
71                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
72                        Ok(match v {
73                            "apiVersion" => Field::Key_api_version,
74                            "kind" => Field::Key_kind,
75                            "metadata" => Field::Key_metadata,
76                            "spec" => Field::Key_spec,
77                            _ => Field::Other,
78                        })
79                    }
80                }
81
82                deserializer.deserialize_identifier(Visitor)
83            }
84        }
85
86        struct Visitor;
87
88        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
89            type Value = DeviceClass;
90
91            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
92                f.write_str(<Self::Value as crate::Resource>::KIND)
93            }
94
95            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
96                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
97                let mut value_spec: Option<crate::api::resource::v1::DeviceClassSpec> = None;
98
99                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
100                    match key {
101                        Field::Key_api_version => {
102                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
103                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
104                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
105                            }
106                        },
107                        Field::Key_kind => {
108                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
109                            if value_kind != <Self::Value as crate::Resource>::KIND {
110                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
111                            }
112                        },
113                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
114                        Field::Key_spec => value_spec = crate::serde::de::MapAccess::next_value(&mut map)?,
115                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
116                    }
117                }
118
119                Ok(DeviceClass {
120                    metadata: value_metadata.unwrap_or_default(),
121                    spec: value_spec.unwrap_or_default(),
122                })
123            }
124        }
125
126        deserializer.deserialize_struct(
127            <Self as crate::Resource>::KIND,
128            &[
129                "apiVersion",
130                "kind",
131                "metadata",
132                "spec",
133            ],
134            Visitor,
135        )
136    }
137}
138
139impl crate::serde::Serialize for DeviceClass {
140    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
141        let mut state = serializer.serialize_struct(
142            <Self as crate::Resource>::KIND,
143            4,
144        )?;
145        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
146        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
147        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
148        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "spec", &self.spec)?;
149        crate::serde::ser::SerializeStruct::end(state)
150    }
151}
152
153#[cfg(feature = "schemars")]
154impl crate::schemars::JsonSchema for DeviceClass {
155    fn schema_name() -> std::borrow::Cow<'static, str> {
156        "io.k8s.api.resource.v1.DeviceClass".into()
157    }
158
159    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
160        crate::schemars::json_schema!({
161            "description": "DeviceClass is a vendor- or admin-provided resource that contains device configuration and selectors. It can be referenced in the device requests of a claim to apply these presets. Cluster scoped.",
162            "type": "object",
163            "properties": {
164                "apiVersion": {
165                    "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
166                    "type": "string",
167                },
168                "kind": {
169                    "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
170                    "type": "string",
171                },
172                "metadata": ({
173                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
174                    schema_obj.ensure_object().insert("description".into(), "Standard object metadata".into());
175                    schema_obj
176                }),
177                "spec": ({
178                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1::DeviceClassSpec>();
179                    schema_obj.ensure_object().insert("description".into(), "Spec defines what can be allocated and how to configure it.\n\nThis is mutable. Consumers have to be prepared for classes changing at any time, either because they get updated or replaced. Claim allocations are done once based on whatever was set in classes at the time of allocation.\n\nChanging the spec automatically increments the metadata.generation number.".into());
180                    schema_obj
181                }),
182            },
183            "required": [
184                "metadata",
185                "spec",
186            ],
187        })
188    }
189}
190
191#[cfg(feature = "schemars08")]
192impl crate::schemars08::JsonSchema for DeviceClass {
193    fn schema_name() -> std::string::String {
194        "io.k8s.api.resource.v1.DeviceClass".into()
195    }
196
197    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
198        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
199            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
200                description: Some("DeviceClass is a vendor- or admin-provided resource that contains device configuration and selectors. It can be referenced in the device requests of a claim to apply these presets. Cluster scoped.".into()),
201                ..Default::default()
202            })),
203            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
204            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
205                properties: [
206                    (
207                        "apiVersion".into(),
208                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
209                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
210                                description: Some("APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources".into()),
211                                ..Default::default()
212                            })),
213                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
214                            ..Default::default()
215                        }),
216                    ),
217                    (
218                        "kind".into(),
219                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
220                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
221                                description: Some("Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds".into()),
222                                ..Default::default()
223                            })),
224                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
225                            ..Default::default()
226                        }),
227                    ),
228                    (
229                        "metadata".into(),
230                        {
231                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>().into_object();
232                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
233                                description: Some("Standard object metadata".into()),
234                                ..Default::default()
235                            }));
236                            crate::schemars08::schema::Schema::Object(schema_obj)
237                        },
238                    ),
239                    (
240                        "spec".into(),
241                        {
242                            let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1::DeviceClassSpec>().into_object();
243                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
244                                description: Some("Spec defines what can be allocated and how to configure it.\n\nThis is mutable. Consumers have to be prepared for classes changing at any time, either because they get updated or replaced. Claim allocations are done once based on whatever was set in classes at the time of allocation.\n\nChanging the spec automatically increments the metadata.generation number.".into()),
245                                ..Default::default()
246                            }));
247                            crate::schemars08::schema::Schema::Object(schema_obj)
248                        },
249                    ),
250                ].into(),
251                required: [
252                    "metadata".into(),
253                    "spec".into(),
254                ].into(),
255                ..Default::default()
256            })),
257            ..Default::default()
258        })
259    }
260}