#
k8s_openapi/v1_35/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///
    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::v1::DeviceClassSpec,
    17}
    18
    19impl crate::Resource for DeviceClass {
    20    const API_VERSION: &'static str = "resource.k8s.io/v1";
    21    const GROUP: &'static str = "resource.k8s.io";
    22    const KIND: &'static str = "DeviceClass";
    23    const VERSION: &'static str = "v1";
    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 core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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::v1::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: std::string::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: std::string::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() -> std::borrow::Cow<'static, str> {
    158        "io.k8s.api.resource.v1.DeviceClass".into()
    159    }
    160
    161    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    162        crate::schemars::json_schema!({
    163            "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.\n\nThis is an alpha type and requires enabling the DynamicResourceAllocation feature gate.",
    164            "type": "object",
    165            "properties": {
    166                "apiVersion": {
    167                    "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",
    168                    "type": "string",
    169                },
    170                "kind": {
    171                    "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",
    172                    "type": "string",
    173                },
    174                "metadata": ({
    175                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    176                    schema_obj.ensure_object().insert("description".into(), "Standard object metadata".into());
    177                    schema_obj
    178                }),
    179                "spec": ({
    180                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1::DeviceClassSpec>();
    181                    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());
    182                    schema_obj
    183                }),
    184            },
    185            "required": [
    186                "metadata",
    187                "spec",
    188            ],
    189        })
    190    }
    191}