k8s_openapi/v1_32/api/resource/v1beta1/
device_class.rs

1// Generated from definition io.k8s.api.resource.v1beta1.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///
5/// This is an alpha type and requires enabling the DynamicResourceAllocation feature gate.
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct DeviceClass {
8    /// Standard object metadata
9    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
10
11    /// Spec defines what can be allocated and how to configure it.
12    ///
13    /// 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.
14    ///
15    /// Changing the spec automatically increments the metadata.generation number.
16    pub spec: crate::api::resource::v1beta1::DeviceClassSpec,
17}
18
19impl crate::Resource for DeviceClass {
20    const API_VERSION: &'static str = "resource.k8s.io/v1beta1";
21    const GROUP: &'static str = "resource.k8s.io";
22    const KIND: &'static str = "DeviceClass";
23    const VERSION: &'static str = "v1beta1";
24    const URL_PATH_SEGMENT: &'static str = "deviceclasses";
25    type Scope = crate::ClusterResourceScope;
26}
27
28impl crate::ListableResource for DeviceClass {
29    const LIST_KIND: &'static str = "DeviceClassList";
30}
31
32impl crate::Metadata for DeviceClass {
33    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
34
35    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
36        &self.metadata
37    }
38
39    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
40        &mut self.metadata
41    }
42}
43
44impl crate::DeepMerge for DeviceClass {
45    fn merge_from(&mut self, other: Self) {
46        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
47        crate::DeepMerge::merge_from(&mut self.spec, other.spec);
48    }
49}
50
51impl<'de> crate::serde::Deserialize<'de> for DeviceClass {
52    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
53        #[allow(non_camel_case_types)]
54        enum Field {
55            Key_api_version,
56            Key_kind,
57            Key_metadata,
58            Key_spec,
59            Other,
60        }
61
62        impl<'de> crate::serde::Deserialize<'de> for Field {
63            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
64                struct Visitor;
65
66                impl crate::serde::de::Visitor<'_> for Visitor {
67                    type Value = Field;
68
69                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70                        f.write_str("field identifier")
71                    }
72
73                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
74                        Ok(match v {
75                            "apiVersion" => Field::Key_api_version,
76                            "kind" => Field::Key_kind,
77                            "metadata" => Field::Key_metadata,
78                            "spec" => Field::Key_spec,
79                            _ => Field::Other,
80                        })
81                    }
82                }
83
84                deserializer.deserialize_identifier(Visitor)
85            }
86        }
87
88        struct Visitor;
89
90        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
91            type Value = DeviceClass;
92
93            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
94                f.write_str(<Self::Value as crate::Resource>::KIND)
95            }
96
97            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
98                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
99                let mut value_spec: Option<crate::api::resource::v1beta1::DeviceClassSpec> = None;
100
101                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
102                    match key {
103                        Field::Key_api_version => {
104                            let value_api_version: String = crate::serde::de::MapAccess::next_value(&mut map)?;
105                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
106                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
107                            }
108                        },
109                        Field::Key_kind => {
110                            let value_kind: String = crate::serde::de::MapAccess::next_value(&mut map)?;
111                            if value_kind != <Self::Value as crate::Resource>::KIND {
112                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
113                            }
114                        },
115                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
116                        Field::Key_spec => value_spec = crate::serde::de::MapAccess::next_value(&mut map)?,
117                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
118                    }
119                }
120
121                Ok(DeviceClass {
122                    metadata: value_metadata.unwrap_or_default(),
123                    spec: value_spec.unwrap_or_default(),
124                })
125            }
126        }
127
128        deserializer.deserialize_struct(
129            <Self as crate::Resource>::KIND,
130            &[
131                "apiVersion",
132                "kind",
133                "metadata",
134                "spec",
135            ],
136            Visitor,
137        )
138    }
139}
140
141impl crate::serde::Serialize for DeviceClass {
142    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
143        let mut state = serializer.serialize_struct(
144            <Self as crate::Resource>::KIND,
145            4,
146        )?;
147        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
148        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
149        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
150        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "spec", &self.spec)?;
151        crate::serde::ser::SerializeStruct::end(state)
152    }
153}
154
155#[cfg(feature = "schemars")]
156impl crate::schemars::JsonSchema for DeviceClass {
157    fn schema_name() -> String {
158        "io.k8s.api.resource.v1beta1.DeviceClass".to_owned()
159    }
160
161    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
162        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
163            metadata: Some(Box::new(crate::schemars::schema::Metadata {
164                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.\n\nThis is an alpha type and requires enabling the DynamicResourceAllocation feature gate.".to_owned()),
165                ..Default::default()
166            })),
167            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
168            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
169                properties: [
170                    (
171                        "apiVersion".to_owned(),
172                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
173                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
174                                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".to_owned()),
175                                ..Default::default()
176                            })),
177                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
178                            ..Default::default()
179                        }),
180                    ),
181                    (
182                        "kind".to_owned(),
183                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
184                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
185                                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".to_owned()),
186                                ..Default::default()
187                            })),
188                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
189                            ..Default::default()
190                        }),
191                    ),
192                    (
193                        "metadata".to_owned(),
194                        {
195                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>().into_object();
196                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
197                                description: Some("Standard object metadata".to_owned()),
198                                ..Default::default()
199                            }));
200                            crate::schemars::schema::Schema::Object(schema_obj)
201                        },
202                    ),
203                    (
204                        "spec".to_owned(),
205                        {
206                            let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::DeviceClassSpec>().into_object();
207                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
208                                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.".to_owned()),
209                                ..Default::default()
210                            }));
211                            crate::schemars::schema::Schema::Object(schema_obj)
212                        },
213                    ),
214                ].into(),
215                required: [
216                    "metadata".to_owned(),
217                    "spec".to_owned(),
218                ].into(),
219                ..Default::default()
220            })),
221            ..Default::default()
222        })
223    }
224}