#
k8s_openapi/v1_35/api/resource/v1/
resource_claim_template.rs

    1// Generated from definition io.k8s.api.resource.v1.ResourceClaimTemplate
    2
    3/// ResourceClaimTemplate is used to produce ResourceClaim objects.
    4///
    5/// This is an alpha type and requires enabling the DynamicResourceAllocation feature gate.
    6#[derive(Clone, Debug, Default, PartialEq)]
    7pub struct ResourceClaimTemplate {
    8    /// Standard object metadata
    9    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    10
    11    /// Describes the ResourceClaim that is to be generated.
    12    ///
    13    /// This field is immutable. A ResourceClaim will get created by the control plane for a Pod when needed and then not get updated anymore.
    14    pub spec: crate::api::resource::v1::ResourceClaimTemplateSpec,
    15}
    16
    17impl crate::Resource for ResourceClaimTemplate {
    18    const API_VERSION: &'static str = "resource.k8s.io/v1";
    19    const GROUP: &'static str = "resource.k8s.io";
    20    const KIND: &'static str = "ResourceClaimTemplate";
    21    const VERSION: &'static str = "v1";
    22    const URL_PATH_SEGMENT: &'static str = "resourceclaimtemplates";
    23    type Scope = crate::NamespaceResourceScope;
    24}
    25
    26impl crate::ListableResource for ResourceClaimTemplate {
    27    const LIST_KIND: &'static str = "ResourceClaimTemplateList";
    28}
    29
    30impl crate::Metadata for ResourceClaimTemplate {
    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 ResourceClaimTemplate {
    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 ResourceClaimTemplate {
    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 = ResourceClaimTemplate;
    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::ResourceClaimTemplateSpec> = 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(ResourceClaimTemplate {
    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 ResourceClaimTemplate {
    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 ResourceClaimTemplate {
    155    fn schema_name() -> std::borrow::Cow<'static, str> {
    156        "io.k8s.api.resource.v1.ResourceClaimTemplate".into()
    157    }
    158
    159    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    160        crate::schemars::json_schema!({
    161            "description": "ResourceClaimTemplate is used to produce ResourceClaim objects.\n\nThis is an alpha type and requires enabling the DynamicResourceAllocation feature gate.",
    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::ResourceClaimTemplateSpec>();
    179                    schema_obj.ensure_object().insert("description".into(), "Describes the ResourceClaim that is to be generated.\n\nThis field is immutable. A ResourceClaim will get created by the control plane for a Pod when needed and then not get updated anymore.".into());
    180                    schema_obj
    181                }),
    182            },
    183            "required": [
    184                "metadata",
    185                "spec",
    186            ],
    187        })
    188    }
    189}