#
k8s_openapi/v1_35/api/resource/v1beta2/
resource_claim.rs

    1// Generated from definition io.k8s.api.resource.v1beta2.ResourceClaim
    2
    3/// ResourceClaim describes a request for access to resources in the cluster, for use by workloads. For example, if a workload needs an accelerator device with specific properties, this is how that request is expressed. The status stanza tracks whether this claim has been satisfied and what specific resources have been allocated.
    4///
    5/// This is an alpha type and requires enabling the DynamicResourceAllocation feature gate.
    6#[derive(Clone, Debug, Default, PartialEq)]
    7pub struct ResourceClaim {
    8    /// Standard object metadata
    9    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    10
    11    /// Spec describes what is being requested and how to configure it. The spec is immutable.
    12    pub spec: crate::api::resource::v1beta2::ResourceClaimSpec,
    13
    14    /// Status describes whether the claim is ready to use and what has been allocated.
    15    pub status: Option<crate::api::resource::v1beta2::ResourceClaimStatus>,
    16}
    17
    18impl crate::Resource for ResourceClaim {
    19    const API_VERSION: &'static str = "resource.k8s.io/v1beta2";
    20    const GROUP: &'static str = "resource.k8s.io";
    21    const KIND: &'static str = "ResourceClaim";
    22    const VERSION: &'static str = "v1beta2";
    23    const URL_PATH_SEGMENT: &'static str = "resourceclaims";
    24    type Scope = crate::NamespaceResourceScope;
    25}
    26
    27impl crate::ListableResource for ResourceClaim {
    28    const LIST_KIND: &'static str = "ResourceClaimList";
    29}
    30
    31impl crate::Metadata for ResourceClaim {
    32    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    33
    34    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
    35        &self.metadata
    36    }
    37
    38    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
    39        &mut self.metadata
    40    }
    41}
    42
    43impl crate::DeepMerge for ResourceClaim {
    44    fn merge_from(&mut self, other: Self) {
    45        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    46        crate::DeepMerge::merge_from(&mut self.spec, other.spec);
    47        crate::DeepMerge::merge_from(&mut self.status, other.status);
    48    }
    49}
    50
    51impl<'de> crate::serde::Deserialize<'de> for ResourceClaim {
    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            Key_status,
    60            Other,
    61        }
    62
    63        impl<'de> crate::serde::Deserialize<'de> for Field {
    64            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    65                struct Visitor;
    66
    67                impl crate::serde::de::Visitor<'_> for Visitor {
    68                    type Value = Field;
    69
    70                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    71                        f.write_str("field identifier")
    72                    }
    73
    74                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    75                        Ok(match v {
    76                            "apiVersion" => Field::Key_api_version,
    77                            "kind" => Field::Key_kind,
    78                            "metadata" => Field::Key_metadata,
    79                            "spec" => Field::Key_spec,
    80                            "status" => Field::Key_status,
    81                            _ => Field::Other,
    82                        })
    83                    }
    84                }
    85
    86                deserializer.deserialize_identifier(Visitor)
    87            }
    88        }
    89
    90        struct Visitor;
    91
    92        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    93            type Value = ResourceClaim;
    94
    95            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    96                f.write_str(<Self::Value as crate::Resource>::KIND)
    97            }
    98
    99            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    100                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    101                let mut value_spec: Option<crate::api::resource::v1beta2::ResourceClaimSpec> = None;
    102                let mut value_status: Option<crate::api::resource::v1beta2::ResourceClaimStatus> = None;
    103
    104                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    105                    match key {
    106                        Field::Key_api_version => {
    107                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    108                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    109                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    110                            }
    111                        },
    112                        Field::Key_kind => {
    113                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    114                            if value_kind != <Self::Value as crate::Resource>::KIND {
    115                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    116                            }
    117                        },
    118                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    119                        Field::Key_spec => value_spec = crate::serde::de::MapAccess::next_value(&mut map)?,
    120                        Field::Key_status => value_status = crate::serde::de::MapAccess::next_value(&mut map)?,
    121                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    122                    }
    123                }
    124
    125                Ok(ResourceClaim {
    126                    metadata: value_metadata.unwrap_or_default(),
    127                    spec: value_spec.unwrap_or_default(),
    128                    status: value_status,
    129                })
    130            }
    131        }
    132
    133        deserializer.deserialize_struct(
    134            <Self as crate::Resource>::KIND,
    135            &[
    136                "apiVersion",
    137                "kind",
    138                "metadata",
    139                "spec",
    140                "status",
    141            ],
    142            Visitor,
    143        )
    144    }
    145}
    146
    147impl crate::serde::Serialize for ResourceClaim {
    148    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    149        let mut state = serializer.serialize_struct(
    150            <Self as crate::Resource>::KIND,
    151            4 +
    152            self.status.as_ref().map_or(0, |_| 1),
    153        )?;
    154        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    155        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    156        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    157        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "spec", &self.spec)?;
    158        if let Some(value) = &self.status {
    159            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "status", value)?;
    160        }
    161        crate::serde::ser::SerializeStruct::end(state)
    162    }
    163}
    164
    165#[cfg(feature = "schemars")]
    166impl crate::schemars::JsonSchema for ResourceClaim {
    167    fn schema_name() -> std::borrow::Cow<'static, str> {
    168        "io.k8s.api.resource.v1beta2.ResourceClaim".into()
    169    }
    170
    171    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    172        crate::schemars::json_schema!({
    173            "description": "ResourceClaim describes a request for access to resources in the cluster, for use by workloads. For example, if a workload needs an accelerator device with specific properties, this is how that request is expressed. The status stanza tracks whether this claim has been satisfied and what specific resources have been allocated.\n\nThis is an alpha type and requires enabling the DynamicResourceAllocation feature gate.",
    174            "type": "object",
    175            "properties": {
    176                "apiVersion": {
    177                    "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",
    178                    "type": "string",
    179                },
    180                "kind": {
    181                    "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",
    182                    "type": "string",
    183                },
    184                "metadata": ({
    185                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    186                    schema_obj.ensure_object().insert("description".into(), "Standard object metadata".into());
    187                    schema_obj
    188                }),
    189                "spec": ({
    190                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::ResourceClaimSpec>();
    191                    schema_obj.ensure_object().insert("description".into(), "Spec describes what is being requested and how to configure it. The spec is immutable.".into());
    192                    schema_obj
    193                }),
    194                "status": ({
    195                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::ResourceClaimStatus>();
    196                    schema_obj.ensure_object().insert("description".into(), "Status describes whether the claim is ready to use and what has been allocated.".into());
    197                    schema_obj
    198                }),
    199            },
    200            "required": [
    201                "metadata",
    202                "spec",
    203            ],
    204        })
    205    }
    206}