#
k8s_openapi/v1_35/api/networking/v1/
network_policy_port.rs

    1// Generated from definition io.k8s.api.networking.v1.NetworkPolicyPort
    2
    3/// NetworkPolicyPort describes a port to allow traffic on
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct NetworkPolicyPort {
    6    /// endPort indicates that the range of ports from port to endPort if set, inclusive, should be allowed by the policy. This field cannot be defined if the port field is not defined or if the port field is defined as a named (string) port. The endPort must be equal or greater than port.
    7    pub end_port: Option<i32>,
    8
    9    /// port represents the port on the given protocol. This can either be a numerical or named port on a pod. If this field is not provided, this matches all port names and numbers. If present, only traffic on the specified protocol AND port will be matched.
    10    pub port: Option<crate::apimachinery::pkg::util::intstr::IntOrString>,
    11
    12    /// protocol represents the protocol (TCP, UDP, or SCTP) which traffic must match. If not specified, this field defaults to TCP.
    13    pub protocol: Option<std::string::String>,
    14}
    15
    16impl crate::DeepMerge for NetworkPolicyPort {
    17    fn merge_from(&mut self, other: Self) {
    18        crate::DeepMerge::merge_from(&mut self.end_port, other.end_port);
    19        crate::DeepMerge::merge_from(&mut self.port, other.port);
    20        crate::DeepMerge::merge_from(&mut self.protocol, other.protocol);
    21    }
    22}
    23
    24impl<'de> crate::serde::Deserialize<'de> for NetworkPolicyPort {
    25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    26        #[allow(non_camel_case_types)]
    27        enum Field {
    28            Key_end_port,
    29            Key_port,
    30            Key_protocol,
    31            Other,
    32        }
    33
    34        impl<'de> crate::serde::Deserialize<'de> for Field {
    35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    36                struct Visitor;
    37
    38                impl crate::serde::de::Visitor<'_> for Visitor {
    39                    type Value = Field;
    40
    41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    42                        f.write_str("field identifier")
    43                    }
    44
    45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    46                        Ok(match v {
    47                            "endPort" => Field::Key_end_port,
    48                            "port" => Field::Key_port,
    49                            "protocol" => Field::Key_protocol,
    50                            _ => Field::Other,
    51                        })
    52                    }
    53                }
    54
    55                deserializer.deserialize_identifier(Visitor)
    56            }
    57        }
    58
    59        struct Visitor;
    60
    61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    62            type Value = NetworkPolicyPort;
    63
    64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    65                f.write_str("NetworkPolicyPort")
    66            }
    67
    68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    69                let mut value_end_port: Option<i32> = None;
    70                let mut value_port: Option<crate::apimachinery::pkg::util::intstr::IntOrString> = None;
    71                let mut value_protocol: Option<std::string::String> = None;
    72
    73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    74                    match key {
    75                        Field::Key_end_port => value_end_port = crate::serde::de::MapAccess::next_value(&mut map)?,
    76                        Field::Key_port => value_port = crate::serde::de::MapAccess::next_value(&mut map)?,
    77                        Field::Key_protocol => value_protocol = crate::serde::de::MapAccess::next_value(&mut map)?,
    78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    79                    }
    80                }
    81
    82                Ok(NetworkPolicyPort {
    83                    end_port: value_end_port,
    84                    port: value_port,
    85                    protocol: value_protocol,
    86                })
    87            }
    88        }
    89
    90        deserializer.deserialize_struct(
    91            "NetworkPolicyPort",
    92            &[
    93                "endPort",
    94                "port",
    95                "protocol",
    96            ],
    97            Visitor,
    98        )
    99    }
    100}
    101
    102impl crate::serde::Serialize for NetworkPolicyPort {
    103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    104        let mut state = serializer.serialize_struct(
    105            "NetworkPolicyPort",
    106            self.end_port.as_ref().map_or(0, |_| 1) +
    107            self.port.as_ref().map_or(0, |_| 1) +
    108            self.protocol.as_ref().map_or(0, |_| 1),
    109        )?;
    110        if let Some(value) = &self.end_port {
    111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "endPort", value)?;
    112        }
    113        if let Some(value) = &self.port {
    114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "port", value)?;
    115        }
    116        if let Some(value) = &self.protocol {
    117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "protocol", value)?;
    118        }
    119        crate::serde::ser::SerializeStruct::end(state)
    120    }
    121}
    122
    123#[cfg(feature = "schemars")]
    124impl crate::schemars::JsonSchema for NetworkPolicyPort {
    125    fn schema_name() -> std::borrow::Cow<'static, str> {
    126        "io.k8s.api.networking.v1.NetworkPolicyPort".into()
    127    }
    128
    129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    130        crate::schemars::json_schema!({
    131            "description": "NetworkPolicyPort describes a port to allow traffic on",
    132            "type": "object",
    133            "properties": {
    134                "endPort": {
    135                    "description": "endPort indicates that the range of ports from port to endPort if set, inclusive, should be allowed by the policy. This field cannot be defined if the port field is not defined or if the port field is defined as a named (string) port. The endPort must be equal or greater than port.",
    136                    "type": "integer",
    137                    "format": "int32",
    138                },
    139                "port": ({
    140                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::util::intstr::IntOrString>();
    141                    schema_obj.ensure_object().insert("description".into(), "port represents the port on the given protocol. This can either be a numerical or named port on a pod. If this field is not provided, this matches all port names and numbers. If present, only traffic on the specified protocol AND port will be matched.".into());
    142                    schema_obj
    143                }),
    144                "protocol": {
    145                    "description": "protocol represents the protocol (TCP, UDP, or SCTP) which traffic must match. If not specified, this field defaults to TCP.",
    146                    "type": "string",
    147                },
    148            },
    149        })
    150    }
    151}