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

    1// Generated from definition io.k8s.api.core.v1.ServicePort
    2
    3/// ServicePort contains information on service's port.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct ServicePort {
    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 within the service. This must be a DNS_LABEL. All ports within a ServiceSpec must have unique names. When considering the endpoints for a Service, this must match the 'name' field in the EndpointPort. Optional if only one ServicePort is defined on this service.
    19    pub name: Option<std::string::String>,
    20
    21    /// The port on each node on which this service is exposed when type is NodePort or LoadBalancer.  Usually assigned by the system. If a value is specified, in-range, and not in use it will be used, otherwise the operation will fail.  If not specified, a port will be allocated if this Service requires one.  If this field is specified when creating a Service which does not need it, creation will fail. This field will be wiped when updating a Service to no longer need it (e.g. changing type from NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport
    22    pub node_port: Option<i32>,
    23
    24    /// The port that will be exposed by this service.
    25    pub port: i32,
    26
    27    /// The IP protocol for this port. Supports "TCP", "UDP", and "SCTP". Default is TCP.
    28    pub protocol: Option<std::string::String>,
    29
    30    /// Number or name of the port to access on the pods targeted by the service. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. If this is a string, it will be looked up as a named port in the target Pod's container ports. If this is not specified, the value of the 'port' field is used (an identity map). This field is ignored for services with clusterIP=None, and should be omitted or set equal to the 'port' field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service
    31    pub target_port: Option<crate::apimachinery::pkg::util::intstr::IntOrString>,
    32}
    33
    34impl crate::DeepMerge for ServicePort {
    35    fn merge_from(&mut self, other: Self) {
    36        crate::DeepMerge::merge_from(&mut self.app_protocol, other.app_protocol);
    37        crate::DeepMerge::merge_from(&mut self.name, other.name);
    38        crate::DeepMerge::merge_from(&mut self.node_port, other.node_port);
    39        crate::DeepMerge::merge_from(&mut self.port, other.port);
    40        crate::DeepMerge::merge_from(&mut self.protocol, other.protocol);
    41        crate::DeepMerge::merge_from(&mut self.target_port, other.target_port);
    42    }
    43}
    44
    45impl<'de> crate::serde::Deserialize<'de> for ServicePort {
    46    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    47        #[allow(non_camel_case_types)]
    48        enum Field {
    49            Key_app_protocol,
    50            Key_name,
    51            Key_node_port,
    52            Key_port,
    53            Key_protocol,
    54            Key_target_port,
    55            Other,
    56        }
    57
    58        impl<'de> crate::serde::Deserialize<'de> for Field {
    59            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    60                struct Visitor;
    61
    62                impl crate::serde::de::Visitor<'_> for Visitor {
    63                    type Value = Field;
    64
    65                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    66                        f.write_str("field identifier")
    67                    }
    68
    69                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    70                        Ok(match v {
    71                            "appProtocol" => Field::Key_app_protocol,
    72                            "name" => Field::Key_name,
    73                            "nodePort" => Field::Key_node_port,
    74                            "port" => Field::Key_port,
    75                            "protocol" => Field::Key_protocol,
    76                            "targetPort" => Field::Key_target_port,
    77                            _ => Field::Other,
    78                        })
    79                    }
    80                }
    81
    82                deserializer.deserialize_identifier(Visitor)
    83            }
    84        }
    85
    86        struct Visitor;
    87
    88        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    89            type Value = ServicePort;
    90
    91            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    92                f.write_str("ServicePort")
    93            }
    94
    95            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    96                let mut value_app_protocol: Option<std::string::String> = None;
    97                let mut value_name: Option<std::string::String> = None;
    98                let mut value_node_port: Option<i32> = None;
    99                let mut value_port: Option<i32> = None;
    100                let mut value_protocol: Option<std::string::String> = None;
    101                let mut value_target_port: Option<crate::apimachinery::pkg::util::intstr::IntOrString> = None;
    102
    103                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    104                    match key {
    105                        Field::Key_app_protocol => value_app_protocol = crate::serde::de::MapAccess::next_value(&mut map)?,
    106                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    107                        Field::Key_node_port => value_node_port = crate::serde::de::MapAccess::next_value(&mut map)?,
    108                        Field::Key_port => value_port = crate::serde::de::MapAccess::next_value(&mut map)?,
    109                        Field::Key_protocol => value_protocol = crate::serde::de::MapAccess::next_value(&mut map)?,
    110                        Field::Key_target_port => value_target_port = 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(ServicePort {
    116                    app_protocol: value_app_protocol,
    117                    name: value_name,
    118                    node_port: value_node_port,
    119                    port: value_port.unwrap_or_default(),
    120                    protocol: value_protocol,
    121                    target_port: value_target_port,
    122                })
    123            }
    124        }
    125
    126        deserializer.deserialize_struct(
    127            "ServicePort",
    128            &[
    129                "appProtocol",
    130                "name",
    131                "nodePort",
    132                "port",
    133                "protocol",
    134                "targetPort",
    135            ],
    136            Visitor,
    137        )
    138    }
    139}
    140
    141impl crate::serde::Serialize for ServicePort {
    142    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    143        let mut state = serializer.serialize_struct(
    144            "ServicePort",
    145            1 +
    146            self.app_protocol.as_ref().map_or(0, |_| 1) +
    147            self.name.as_ref().map_or(0, |_| 1) +
    148            self.node_port.as_ref().map_or(0, |_| 1) +
    149            self.protocol.as_ref().map_or(0, |_| 1) +
    150            self.target_port.as_ref().map_or(0, |_| 1),
    151        )?;
    152        if let Some(value) = &self.app_protocol {
    153            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "appProtocol", value)?;
    154        }
    155        if let Some(value) = &self.name {
    156            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
    157        }
    158        if let Some(value) = &self.node_port {
    159            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodePort", value)?;
    160        }
    161        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "port", &self.port)?;
    162        if let Some(value) = &self.protocol {
    163            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "protocol", value)?;
    164        }
    165        if let Some(value) = &self.target_port {
    166            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "targetPort", value)?;
    167        }
    168        crate::serde::ser::SerializeStruct::end(state)
    169    }
    170}
    171
    172#[cfg(feature = "schemars")]
    173impl crate::schemars::JsonSchema for ServicePort {
    174    fn schema_name() -> std::borrow::Cow<'static, str> {
    175        "io.k8s.api.core.v1.ServicePort".into()
    176    }
    177
    178    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    179        crate::schemars::json_schema!({
    180            "description": "ServicePort contains information on service's port.",
    181            "type": "object",
    182            "properties": {
    183                "appProtocol": {
    184                    "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.",
    185                    "type": "string",
    186                },
    187                "name": {
    188                    "description": "The name of this port within the service. This must be a DNS_LABEL. All ports within a ServiceSpec must have unique names. When considering the endpoints for a Service, this must match the 'name' field in the EndpointPort. Optional if only one ServicePort is defined on this service.",
    189                    "type": "string",
    190                },
    191                "nodePort": {
    192                    "description": "The port on each node on which this service is exposed when type is NodePort or LoadBalancer.  Usually assigned by the system. If a value is specified, in-range, and not in use it will be used, otherwise the operation will fail.  If not specified, a port will be allocated if this Service requires one.  If this field is specified when creating a Service which does not need it, creation will fail. This field will be wiped when updating a Service to no longer need it (e.g. changing type from NodePort to ClusterIP). More info: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport",
    193                    "type": "integer",
    194                    "format": "int32",
    195                },
    196                "port": {
    197                    "description": "The port that will be exposed by this service.",
    198                    "type": "integer",
    199                    "format": "int32",
    200                },
    201                "protocol": {
    202                    "description": "The IP protocol for this port. Supports \"TCP\", \"UDP\", and \"SCTP\". Default is TCP.",
    203                    "type": "string",
    204                },
    205                "targetPort": ({
    206                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::util::intstr::IntOrString>();
    207                    schema_obj.ensure_object().insert("description".into(), "Number or name of the port to access on the pods targeted by the service. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. If this is a string, it will be looked up as a named port in the target Pod's container ports. If this is not specified, the value of the 'port' field is used (an identity map). This field is ignored for services with clusterIP=None, and should be omitted or set equal to the 'port' field. More info: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service".into());
    208                    schema_obj
    209                }),
    210            },
    211            "required": [
    212                "port",
    213            ],
    214        })
    215    }
    216}