#
k8s_openapi/v1_35/api/discovery/v1/
endpoint_slice.rs

    1// Generated from definition io.k8s.api.discovery.v1.EndpointSlice
    2
    3/// EndpointSlice represents a set of service endpoints. Most EndpointSlices are created by the EndpointSlice controller to represent the Pods selected by Service objects. For a given service there may be multiple EndpointSlice objects which must be joined to produce the full set of endpoints; you can find all of the slices for a given service by listing EndpointSlices in the service's namespace whose `kubernetes.io/service-name` label contains the service's name.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct EndpointSlice {
    6    /// addressType specifies the type of address carried by this EndpointSlice. All addresses in this slice must be the same type. This field is immutable after creation. The following address types are currently supported: * IPv4: Represents an IPv4 Address. * IPv6: Represents an IPv6 Address. * FQDN: Represents a Fully Qualified Domain Name. (Deprecated) The EndpointSlice controller only generates, and kube-proxy only processes, slices of addressType "IPv4" and "IPv6". No semantics are defined for the "FQDN" type.
    7    pub address_type: std::string::String,
    8
    9    /// endpoints is a list of unique endpoints in this slice. Each slice may include a maximum of 1000 endpoints.
    10    pub endpoints: std::vec::Vec<crate::api::discovery::v1::Endpoint>,
    11
    12    /// Standard object's metadata.
    13    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    14
    15    /// ports specifies the list of network ports exposed by each endpoint in this slice. Each port must have a unique name. Each slice may include a maximum of 100 ports. Services always have at least 1 port, so EndpointSlices generated by the EndpointSlice controller will likewise always have at least 1 port. EndpointSlices used for other purposes may have an empty ports list.
    16    pub ports: Option<std::vec::Vec<crate::api::discovery::v1::EndpointPort>>,
    17}
    18
    19impl crate::Resource for EndpointSlice {
    20    const API_VERSION: &'static str = "discovery.k8s.io/v1";
    21    const GROUP: &'static str = "discovery.k8s.io";
    22    const KIND: &'static str = "EndpointSlice";
    23    const VERSION: &'static str = "v1";
    24    const URL_PATH_SEGMENT: &'static str = "endpointslices";
    25    type Scope = crate::NamespaceResourceScope;
    26}
    27
    28impl crate::ListableResource for EndpointSlice {
    29    const LIST_KIND: &'static str = "EndpointSliceList";
    30}
    31
    32impl crate::Metadata for EndpointSlice {
    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 EndpointSlice {
    45    fn merge_from(&mut self, other: Self) {
    46        crate::DeepMerge::merge_from(&mut self.address_type, other.address_type);
    47        crate::merge_strategies::list::atomic(&mut self.endpoints, other.endpoints);
    48        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    49        crate::merge_strategies::list::atomic(&mut self.ports, other.ports);
    50    }
    51}
    52
    53impl<'de> crate::serde::Deserialize<'de> for EndpointSlice {
    54    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    55        #[allow(non_camel_case_types)]
    56        enum Field {
    57            Key_api_version,
    58            Key_kind,
    59            Key_address_type,
    60            Key_endpoints,
    61            Key_metadata,
    62            Key_ports,
    63            Other,
    64        }
    65
    66        impl<'de> crate::serde::Deserialize<'de> for Field {
    67            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    68                struct Visitor;
    69
    70                impl crate::serde::de::Visitor<'_> for Visitor {
    71                    type Value = Field;
    72
    73                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    74                        f.write_str("field identifier")
    75                    }
    76
    77                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    78                        Ok(match v {
    79                            "apiVersion" => Field::Key_api_version,
    80                            "kind" => Field::Key_kind,
    81                            "addressType" => Field::Key_address_type,
    82                            "endpoints" => Field::Key_endpoints,
    83                            "metadata" => Field::Key_metadata,
    84                            "ports" => Field::Key_ports,
    85                            _ => Field::Other,
    86                        })
    87                    }
    88                }
    89
    90                deserializer.deserialize_identifier(Visitor)
    91            }
    92        }
    93
    94        struct Visitor;
    95
    96        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    97            type Value = EndpointSlice;
    98
    99            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    100                f.write_str(<Self::Value as crate::Resource>::KIND)
    101            }
    102
    103            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    104                let mut value_address_type: Option<std::string::String> = None;
    105                let mut value_endpoints: Option<std::vec::Vec<crate::api::discovery::v1::Endpoint>> = None;
    106                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    107                let mut value_ports: Option<std::vec::Vec<crate::api::discovery::v1::EndpointPort>> = None;
    108
    109                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    110                    match key {
    111                        Field::Key_api_version => {
    112                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    113                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    114                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    115                            }
    116                        },
    117                        Field::Key_kind => {
    118                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    119                            if value_kind != <Self::Value as crate::Resource>::KIND {
    120                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    121                            }
    122                        },
    123                        Field::Key_address_type => value_address_type = crate::serde::de::MapAccess::next_value(&mut map)?,
    124                        Field::Key_endpoints => value_endpoints = crate::serde::de::MapAccess::next_value(&mut map)?,
    125                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    126                        Field::Key_ports => value_ports = crate::serde::de::MapAccess::next_value(&mut map)?,
    127                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    128                    }
    129                }
    130
    131                Ok(EndpointSlice {
    132                    address_type: value_address_type.unwrap_or_default(),
    133                    endpoints: value_endpoints.unwrap_or_default(),
    134                    metadata: value_metadata.unwrap_or_default(),
    135                    ports: value_ports,
    136                })
    137            }
    138        }
    139
    140        deserializer.deserialize_struct(
    141            <Self as crate::Resource>::KIND,
    142            &[
    143                "apiVersion",
    144                "kind",
    145                "addressType",
    146                "endpoints",
    147                "metadata",
    148                "ports",
    149            ],
    150            Visitor,
    151        )
    152    }
    153}
    154
    155impl crate::serde::Serialize for EndpointSlice {
    156    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    157        let mut state = serializer.serialize_struct(
    158            <Self as crate::Resource>::KIND,
    159            5 +
    160            self.ports.as_ref().map_or(0, |_| 1),
    161        )?;
    162        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    163        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    164        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "addressType", &self.address_type)?;
    165        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "endpoints", &self.endpoints)?;
    166        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    167        if let Some(value) = &self.ports {
    168            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ports", value)?;
    169        }
    170        crate::serde::ser::SerializeStruct::end(state)
    171    }
    172}
    173
    174#[cfg(feature = "schemars")]
    175impl crate::schemars::JsonSchema for EndpointSlice {
    176    fn schema_name() -> std::borrow::Cow<'static, str> {
    177        "io.k8s.api.discovery.v1.EndpointSlice".into()
    178    }
    179
    180    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    181        crate::schemars::json_schema!({
    182            "description": "EndpointSlice represents a set of service endpoints. Most EndpointSlices are created by the EndpointSlice controller to represent the Pods selected by Service objects. For a given service there may be multiple EndpointSlice objects which must be joined to produce the full set of endpoints; you can find all of the slices for a given service by listing EndpointSlices in the service's namespace whose `kubernetes.io/service-name` label contains the service's name.",
    183            "type": "object",
    184            "properties": {
    185                "addressType": {
    186                    "description": "addressType specifies the type of address carried by this EndpointSlice. All addresses in this slice must be the same type. This field is immutable after creation. The following address types are currently supported: * IPv4: Represents an IPv4 Address. * IPv6: Represents an IPv6 Address. * FQDN: Represents a Fully Qualified Domain Name. (Deprecated) The EndpointSlice controller only generates, and kube-proxy only processes, slices of addressType \"IPv4\" and \"IPv6\". No semantics are defined for the \"FQDN\" type.",
    187                    "type": "string",
    188                },
    189                "apiVersion": {
    190                    "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",
    191                    "type": "string",
    192                },
    193                "endpoints": {
    194                    "description": "endpoints is a list of unique endpoints in this slice. Each slice may include a maximum of 1000 endpoints.",
    195                    "type": "array",
    196                    "items": (__gen.subschema_for::<crate::api::discovery::v1::Endpoint>()),
    197                },
    198                "kind": {
    199                    "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",
    200                    "type": "string",
    201                },
    202                "metadata": ({
    203                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    204                    schema_obj.ensure_object().insert("description".into(), "Standard object's metadata.".into());
    205                    schema_obj
    206                }),
    207                "ports": {
    208                    "description": "ports specifies the list of network ports exposed by each endpoint in this slice. Each port must have a unique name. Each slice may include a maximum of 100 ports. Services always have at least 1 port, so EndpointSlices generated by the EndpointSlice controller will likewise always have at least 1 port. EndpointSlices used for other purposes may have an empty ports list.",
    209                    "type": "array",
    210                    "items": (__gen.subschema_for::<crate::api::discovery::v1::EndpointPort>()),
    211                },
    212            },
    213            "required": [
    214                "addressType",
    215                "endpoints",
    216                "metadata",
    217            ],
    218        })
    219    }
    220}