#
k8s_openapi/v1_35/api/resource/v1beta1/
resource_pool.rs

    1// Generated from definition io.k8s.api.resource.v1beta1.ResourcePool
    2
    3/// ResourcePool describes the pool that ResourceSlices belong to.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct ResourcePool {
    6    /// Generation tracks the change in a pool over time. Whenever a driver changes something about one or more of the resources in a pool, it must change the generation in all ResourceSlices which are part of that pool. Consumers of ResourceSlices should only consider resources from the pool with the highest generation number. The generation may be reset by drivers, which should be fine for consumers, assuming that all ResourceSlices in a pool are updated to match or deleted.
    7    ///
    8    /// Combined with ResourceSliceCount, this mechanism enables consumers to detect pools which are comprised of multiple ResourceSlices and are in an incomplete state.
    9    pub generation: i64,
    10
    11    /// Name is used to identify the pool. For node-local devices, this is often the node name, but this is not required.
    12    ///
    13    /// It must not be longer than 253 characters and must consist of one or more DNS sub-domains separated by slashes. This field is immutable.
    14    pub name: std::string::String,
    15
    16    /// ResourceSliceCount is the total number of ResourceSlices in the pool at this generation number. Must be greater than zero.
    17    ///
    18    /// Consumers can use this to check whether they have seen all ResourceSlices belonging to the same pool.
    19    pub resource_slice_count: i64,
    20}
    21
    22impl crate::DeepMerge for ResourcePool {
    23    fn merge_from(&mut self, other: Self) {
    24        crate::DeepMerge::merge_from(&mut self.generation, other.generation);
    25        crate::DeepMerge::merge_from(&mut self.name, other.name);
    26        crate::DeepMerge::merge_from(&mut self.resource_slice_count, other.resource_slice_count);
    27    }
    28}
    29
    30impl<'de> crate::serde::Deserialize<'de> for ResourcePool {
    31    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    32        #[allow(non_camel_case_types)]
    33        enum Field {
    34            Key_generation,
    35            Key_name,
    36            Key_resource_slice_count,
    37            Other,
    38        }
    39
    40        impl<'de> crate::serde::Deserialize<'de> for Field {
    41            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    42                struct Visitor;
    43
    44                impl crate::serde::de::Visitor<'_> for Visitor {
    45                    type Value = Field;
    46
    47                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    48                        f.write_str("field identifier")
    49                    }
    50
    51                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    52                        Ok(match v {
    53                            "generation" => Field::Key_generation,
    54                            "name" => Field::Key_name,
    55                            "resourceSliceCount" => Field::Key_resource_slice_count,
    56                            _ => Field::Other,
    57                        })
    58                    }
    59                }
    60
    61                deserializer.deserialize_identifier(Visitor)
    62            }
    63        }
    64
    65        struct Visitor;
    66
    67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    68            type Value = ResourcePool;
    69
    70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    71                f.write_str("ResourcePool")
    72            }
    73
    74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    75                let mut value_generation: Option<i64> = None;
    76                let mut value_name: Option<std::string::String> = None;
    77                let mut value_resource_slice_count: Option<i64> = None;
    78
    79                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    80                    match key {
    81                        Field::Key_generation => value_generation = crate::serde::de::MapAccess::next_value(&mut map)?,
    82                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    83                        Field::Key_resource_slice_count => value_resource_slice_count = crate::serde::de::MapAccess::next_value(&mut map)?,
    84                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    85                    }
    86                }
    87
    88                Ok(ResourcePool {
    89                    generation: value_generation.unwrap_or_default(),
    90                    name: value_name.unwrap_or_default(),
    91                    resource_slice_count: value_resource_slice_count.unwrap_or_default(),
    92                })
    93            }
    94        }
    95
    96        deserializer.deserialize_struct(
    97            "ResourcePool",
    98            &[
    99                "generation",
    100                "name",
    101                "resourceSliceCount",
    102            ],
    103            Visitor,
    104        )
    105    }
    106}
    107
    108impl crate::serde::Serialize for ResourcePool {
    109    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    110        let mut state = serializer.serialize_struct(
    111            "ResourcePool",
    112            3,
    113        )?;
    114        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "generation", &self.generation)?;
    115        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
    116        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceSliceCount", &self.resource_slice_count)?;
    117        crate::serde::ser::SerializeStruct::end(state)
    118    }
    119}
    120
    121#[cfg(feature = "schemars")]
    122impl crate::schemars::JsonSchema for ResourcePool {
    123    fn schema_name() -> std::borrow::Cow<'static, str> {
    124        "io.k8s.api.resource.v1beta1.ResourcePool".into()
    125    }
    126
    127    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    128        crate::schemars::json_schema!({
    129            "description": "ResourcePool describes the pool that ResourceSlices belong to.",
    130            "type": "object",
    131            "properties": {
    132                "generation": {
    133                    "description": "Generation tracks the change in a pool over time. Whenever a driver changes something about one or more of the resources in a pool, it must change the generation in all ResourceSlices which are part of that pool. Consumers of ResourceSlices should only consider resources from the pool with the highest generation number. The generation may be reset by drivers, which should be fine for consumers, assuming that all ResourceSlices in a pool are updated to match or deleted.\n\nCombined with ResourceSliceCount, this mechanism enables consumers to detect pools which are comprised of multiple ResourceSlices and are in an incomplete state.",
    134                    "type": "integer",
    135                    "format": "int64",
    136                },
    137                "name": {
    138                    "description": "Name is used to identify the pool. For node-local devices, this is often the node name, but this is not required.\n\nIt must not be longer than 253 characters and must consist of one or more DNS sub-domains separated by slashes. This field is immutable.",
    139                    "type": "string",
    140                },
    141                "resourceSliceCount": {
    142                    "description": "ResourceSliceCount is the total number of ResourceSlices in the pool at this generation number. Must be greater than zero.\n\nConsumers can use this to check whether they have seen all ResourceSlices belonging to the same pool.",
    143                    "type": "integer",
    144                    "format": "int64",
    145                },
    146            },
    147            "required": [
    148                "generation",
    149                "name",
    150                "resourceSliceCount",
    151            ],
    152        })
    153    }
    154}