#
k8s_openapi/v1_35/api/core/v1/
endpoint_port.rs

    1// Generated from definition io.k8s.api.core.v1.EndpointPort
    2
    3/// EndpointPort is a tuple that describes a single port. Deprecated: This API is deprecated in v1.33+.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct EndpointPort {
    6    /// The application protocol for this port. This is used as a hint for implementations to offer richer behavior for protocols that they understand. This field follows standard Kubernetes label syntax. Valid values are either:
    7    ///
    8    /// * Un-prefixed protocol names - reserved for IANA standard service names (as per RFC-6335 and https://www.iana.org/assignments/service-names).
    9    ///
    10    /// * Kubernetes-defined prefixed names:
    11    ///   * 'kubernetes.io/h2c' - HTTP/2 prior knowledge over cleartext as described in https://www.rfc-editor.org/rfc/rfc9113.html#name-starting-http-2-with-prior-
    12    ///   * 'kubernetes.io/ws'  - WebSocket over cleartext as described in https://www.rfc-editor.org/rfc/rfc6455
    13    ///   * 'kubernetes.io/wss' - WebSocket over TLS as described in https://www.rfc-editor.org/rfc/rfc6455
    14    ///
    15    /// * Other protocols should use implementation-defined prefixed names such as mycompany.com/my-custom-protocol.
    16    pub app_protocol: Option<std::string::String>,
    17
    18    /// The name of this port.  This must match the 'name' field in the corresponding ServicePort. Must be a DNS_LABEL. Optional only if one port is defined.
    19    pub name: Option<std::string::String>,
    20
    21    /// The port number of the endpoint.
    22    pub port: i32,
    23
    24    /// The IP protocol for this port. Must be UDP, TCP, or SCTP. Default is TCP.
    25    pub protocol: Option<std::string::String>,
    26}
    27
    28impl crate::DeepMerge for EndpointPort {
    29    fn merge_from(&mut self, other: Self) {
    30        crate::DeepMerge::merge_from(&mut self.app_protocol, other.app_protocol);
    31        crate::DeepMerge::merge_from(&mut self.name, other.name);
    32        crate::DeepMerge::merge_from(&mut self.port, other.port);
    33        crate::DeepMerge::merge_from(&mut self.protocol, other.protocol);
    34    }
    35}
    36
    37impl<'de> crate::serde::Deserialize<'de> for EndpointPort {
    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_app_protocol,
    42            Key_name,
    43            Key_port,
    44            Key_protocol,
    45            Other,
    46        }
    47
    48        impl<'de> crate::serde::Deserialize<'de> for Field {
    49            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    50                struct Visitor;
    51
    52                impl crate::serde::de::Visitor<'_> for Visitor {
    53                    type Value = Field;
    54
    55                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    56                        f.write_str("field identifier")
    57                    }
    58
    59                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    60                        Ok(match v {
    61                            "appProtocol" => Field::Key_app_protocol,
    62                            "name" => Field::Key_name,
    63                            "port" => Field::Key_port,
    64                            "protocol" => Field::Key_protocol,
    65                            _ => Field::Other,
    66                        })
    67                    }
    68                }
    69
    70                deserializer.deserialize_identifier(Visitor)
    71            }
    72        }
    73
    74        struct Visitor;
    75
    76        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    77            type Value = EndpointPort;
    78
    79            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    80                f.write_str("EndpointPort")
    81            }
    82
    83            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    84                let mut value_app_protocol: Option<std::string::String> = None;
    85                let mut value_name: Option<std::string::String> = None;
    86                let mut value_port: Option<i32> = None;
    87                let mut value_protocol: Option<std::string::String> = None;
    88
    89                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    90                    match key {
    91                        Field::Key_app_protocol => value_app_protocol = crate::serde::de::MapAccess::next_value(&mut map)?,
    92                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    93                        Field::Key_port => value_port = crate::serde::de::MapAccess::next_value(&mut map)?,
    94                        Field::Key_protocol => value_protocol = crate::serde::de::MapAccess::next_value(&mut map)?,
    95                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    96                    }
    97                }
    98
    99                Ok(EndpointPort {
    100                    app_protocol: value_app_protocol,
    101                    name: value_name,
    102                    port: value_port.unwrap_or_default(),
    103                    protocol: value_protocol,
    104                })
    105            }
    106        }
    107
    108        deserializer.deserialize_struct(
    109            "EndpointPort",
    110            &[
    111                "appProtocol",
    112                "name",
    113                "port",
    114                "protocol",
    115            ],
    116            Visitor,
    117        )
    118    }
    119}
    120
    121impl crate::serde::Serialize for EndpointPort {
    122    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    123        let mut state = serializer.serialize_struct(
    124            "EndpointPort",
    125            1 +
    126            self.app_protocol.as_ref().map_or(0, |_| 1) +
    127            self.name.as_ref().map_or(0, |_| 1) +
    128            self.protocol.as_ref().map_or(0, |_| 1),
    129        )?;
    130        if let Some(value) = &self.app_protocol {
    131            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "appProtocol", value)?;
    132        }
    133        if let Some(value) = &self.name {
    134            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
    135        }
    136        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "port", &self.port)?;
    137        if let Some(value) = &self.protocol {
    138            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "protocol", value)?;
    139        }
    140        crate::serde::ser::SerializeStruct::end(state)
    141    }
    142}
    143
    144#[cfg(feature = "schemars")]
    145impl crate::schemars::JsonSchema for EndpointPort {
    146    fn schema_name() -> std::borrow::Cow<'static, str> {
    147        "io.k8s.api.core.v1.EndpointPort".into()
    148    }
    149
    150    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    151        crate::schemars::json_schema!({
    152            "description": "EndpointPort is a tuple that describes a single port. Deprecated: This API is deprecated in v1.33+.",
    153            "type": "object",
    154            "properties": {
    155                "appProtocol": {
    156                    "description": "The application protocol for this port. This is used as a hint for implementations to offer richer behavior for protocols that they understand. This field follows standard Kubernetes label syntax. Valid values are either:\n\n* Un-prefixed protocol names - reserved for IANA standard service names (as per RFC-6335 and https://www.iana.org/assignments/service-names).\n\n* Kubernetes-defined prefixed names:\n  * 'kubernetes.io/h2c' - HTTP/2 prior knowledge over cleartext as described in https://www.rfc-editor.org/rfc/rfc9113.html#name-starting-http-2-with-prior-\n  * 'kubernetes.io/ws'  - WebSocket over cleartext as described in https://www.rfc-editor.org/rfc/rfc6455\n  * 'kubernetes.io/wss' - WebSocket over TLS as described in https://www.rfc-editor.org/rfc/rfc6455\n\n* Other protocols should use implementation-defined prefixed names such as mycompany.com/my-custom-protocol.",
    157                    "type": "string",
    158                },
    159                "name": {
    160                    "description": "The name of this port.  This must match the 'name' field in the corresponding ServicePort. Must be a DNS_LABEL. Optional only if one port is defined.",
    161                    "type": "string",
    162                },
    163                "port": {
    164                    "description": "The port number of the endpoint.",
    165                    "type": "integer",
    166                    "format": "int32",
    167                },
    168                "protocol": {
    169                    "description": "The IP protocol for this port. Must be UDP, TCP, or SCTP. Default is TCP.",
    170                    "type": "string",
    171                },
    172            },
    173            "required": [
    174                "port",
    175            ],
    176        })
    177    }
    178}