#
k8s_openapi/v1_35/apimachinery/pkg/apis/meta/v1/
api_group.rs

    1// Generated from definition io.k8s.apimachinery.pkg.apis.meta.v1.APIGroup
    2
    3/// APIGroup contains the name, the supported versions, and the preferred version of a group.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct APIGroup {
    6    /// name is the name of the group.
    7    pub name: std::string::String,
    8
    9    /// preferredVersion is the version preferred by the API server, which probably is the storage version.
    10    pub preferred_version: Option<crate::apimachinery::pkg::apis::meta::v1::GroupVersionForDiscovery>,
    11
    12    /// a map of client CIDR to server address that is serving this group. This is to help clients reach servers in the most network-efficient way possible. Clients can use the appropriate server address as per the CIDR that they match. In case of multiple matches, clients should use the longest matching CIDR. The server returns only those CIDRs that it thinks that the client can match. For example: the master will return an internal IP CIDR only, if the client reaches the server using an internal IP. Server looks at X-Forwarded-For header or X-Real-Ip header or request.RemoteAddr (in that order) to get the client IP.
    13    pub server_address_by_client_cidrs: Option<std::vec::Vec<crate::apimachinery::pkg::apis::meta::v1::ServerAddressByClientCIDR>>,
    14
    15    /// versions are the versions supported in this group.
    16    pub versions: std::vec::Vec<crate::apimachinery::pkg::apis::meta::v1::GroupVersionForDiscovery>,
    17}
    18
    19impl crate::Resource for APIGroup {
    20    const API_VERSION: &'static str = "v1";
    21    const GROUP: &'static str = "";
    22    const KIND: &'static str = "APIGroup";
    23    const VERSION: &'static str = "v1";
    24    const URL_PATH_SEGMENT: &'static str = "";
    25    type Scope = crate::ClusterResourceScope;
    26}
    27
    28impl crate::DeepMerge for APIGroup {
    29    fn merge_from(&mut self, other: Self) {
    30        crate::DeepMerge::merge_from(&mut self.name, other.name);
    31        crate::DeepMerge::merge_from(&mut self.preferred_version, other.preferred_version);
    32        crate::merge_strategies::list::atomic(&mut self.server_address_by_client_cidrs, other.server_address_by_client_cidrs);
    33        crate::merge_strategies::list::atomic(&mut self.versions, other.versions);
    34    }
    35}
    36
    37impl<'de> crate::serde::Deserialize<'de> for APIGroup {
    38    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    39        #[allow(non_camel_case_types)]
    40        enum Field {
    41            Key_api_version,
    42            Key_kind,
    43            Key_name,
    44            Key_preferred_version,
    45            Key_server_address_by_client_cidrs,
    46            Key_versions,
    47            Other,
    48        }
    49
    50        impl<'de> crate::serde::Deserialize<'de> for Field {
    51            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    52                struct Visitor;
    53
    54                impl crate::serde::de::Visitor<'_> for Visitor {
    55                    type Value = Field;
    56
    57                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    58                        f.write_str("field identifier")
    59                    }
    60
    61                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    62                        Ok(match v {
    63                            "apiVersion" => Field::Key_api_version,
    64                            "kind" => Field::Key_kind,
    65                            "name" => Field::Key_name,
    66                            "preferredVersion" => Field::Key_preferred_version,
    67                            "serverAddressByClientCIDRs" => Field::Key_server_address_by_client_cidrs,
    68                            "versions" => Field::Key_versions,
    69                            _ => Field::Other,
    70                        })
    71                    }
    72                }
    73
    74                deserializer.deserialize_identifier(Visitor)
    75            }
    76        }
    77
    78        struct Visitor;
    79
    80        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    81            type Value = APIGroup;
    82
    83            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    84                f.write_str(<Self::Value as crate::Resource>::KIND)
    85            }
    86
    87            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    88                let mut value_name: Option<std::string::String> = None;
    89                let mut value_preferred_version: Option<crate::apimachinery::pkg::apis::meta::v1::GroupVersionForDiscovery> = None;
    90                let mut value_server_address_by_client_cidrs: Option<std::vec::Vec<crate::apimachinery::pkg::apis::meta::v1::ServerAddressByClientCIDR>> = None;
    91                let mut value_versions: Option<std::vec::Vec<crate::apimachinery::pkg::apis::meta::v1::GroupVersionForDiscovery>> = None;
    92
    93                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    94                    match key {
    95                        Field::Key_api_version => {
    96                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    97                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    98                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    99                            }
    100                        },
    101                        Field::Key_kind => {
    102                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    103                            if value_kind != <Self::Value as crate::Resource>::KIND {
    104                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    105                            }
    106                        },
    107                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    108                        Field::Key_preferred_version => value_preferred_version = crate::serde::de::MapAccess::next_value(&mut map)?,
    109                        Field::Key_server_address_by_client_cidrs => value_server_address_by_client_cidrs = crate::serde::de::MapAccess::next_value(&mut map)?,
    110                        Field::Key_versions => value_versions = crate::serde::de::MapAccess::next_value(&mut map)?,
    111                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    112                    }
    113                }
    114
    115                Ok(APIGroup {
    116                    name: value_name.unwrap_or_default(),
    117                    preferred_version: value_preferred_version,
    118                    server_address_by_client_cidrs: value_server_address_by_client_cidrs,
    119                    versions: value_versions.unwrap_or_default(),
    120                })
    121            }
    122        }
    123
    124        deserializer.deserialize_struct(
    125            <Self as crate::Resource>::KIND,
    126            &[
    127                "apiVersion",
    128                "kind",
    129                "name",
    130                "preferredVersion",
    131                "serverAddressByClientCIDRs",
    132                "versions",
    133            ],
    134            Visitor,
    135        )
    136    }
    137}
    138
    139impl crate::serde::Serialize for APIGroup {
    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            self.preferred_version.as_ref().map_or(0, |_| 1) +
    145            self.server_address_by_client_cidrs.as_ref().map_or(0, |_| 1),
    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, "name", &self.name)?;
    150        if let Some(value) = &self.preferred_version {
    151            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "preferredVersion", value)?;
    152        }
    153        if let Some(value) = &self.server_address_by_client_cidrs {
    154            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "serverAddressByClientCIDRs", value)?;
    155        }
    156        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "versions", &self.versions)?;
    157        crate::serde::ser::SerializeStruct::end(state)
    158    }
    159}
    160
    161#[cfg(feature = "schemars")]
    162impl crate::schemars::JsonSchema for APIGroup {
    163    fn schema_name() -> std::borrow::Cow<'static, str> {
    164        "io.k8s.apimachinery.pkg.apis.meta.v1.APIGroup".into()
    165    }
    166
    167    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    168        crate::schemars::json_schema!({
    169            "description": "APIGroup contains the name, the supported versions, and the preferred version of a group.",
    170            "type": "object",
    171            "properties": {
    172                "apiVersion": {
    173                    "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",
    174                    "type": "string",
    175                },
    176                "kind": {
    177                    "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",
    178                    "type": "string",
    179                },
    180                "name": {
    181                    "description": "name is the name of the group.",
    182                    "type": "string",
    183                },
    184                "preferredVersion": ({
    185                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::GroupVersionForDiscovery>();
    186                    schema_obj.ensure_object().insert("description".into(), "preferredVersion is the version preferred by the API server, which probably is the storage version.".into());
    187                    schema_obj
    188                }),
    189                "serverAddressByClientCIDRs": {
    190                    "description": "a map of client CIDR to server address that is serving this group. This is to help clients reach servers in the most network-efficient way possible. Clients can use the appropriate server address as per the CIDR that they match. In case of multiple matches, clients should use the longest matching CIDR. The server returns only those CIDRs that it thinks that the client can match. For example: the master will return an internal IP CIDR only, if the client reaches the server using an internal IP. Server looks at X-Forwarded-For header or X-Real-Ip header or request.RemoteAddr (in that order) to get the client IP.",
    191                    "type": "array",
    192                    "items": (__gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ServerAddressByClientCIDR>()),
    193                },
    194                "versions": {
    195                    "description": "versions are the versions supported in this group.",
    196                    "type": "array",
    197                    "items": (__gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::GroupVersionForDiscovery>()),
    198                },
    199            },
    200            "required": [
    201                "name",
    202                "versions",
    203            ],
    204        })
    205    }
    206}