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

    1// Generated from definition io.k8s.api.networking.v1.NetworkPolicySpec
    2
    3/// NetworkPolicySpec provides the specification of a NetworkPolicy
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct NetworkPolicySpec {
    6    /// egress is a list of egress rules to be applied to the selected pods. Outgoing traffic is allowed if there are no NetworkPolicies selecting the pod (and cluster policy otherwise allows the traffic), OR if the traffic matches at least one egress rule across all of the NetworkPolicy objects whose podSelector matches the pod. If this field is empty then this NetworkPolicy limits all outgoing traffic (and serves solely to ensure that the pods it selects are isolated by default). This field is beta-level in 1.8
    7    pub egress: Option<std::vec::Vec<crate::api::networking::v1::NetworkPolicyEgressRule>>,
    8
    9    /// ingress is a list of ingress rules to be applied to the selected pods. Traffic is allowed to a pod if there are no NetworkPolicies selecting the pod (and cluster policy otherwise allows the traffic), OR if the traffic source is the pod's local node, OR if the traffic matches at least one ingress rule across all of the NetworkPolicy objects whose podSelector matches the pod. If this field is empty then this NetworkPolicy does not allow any traffic (and serves solely to ensure that the pods it selects are isolated by default)
    10    pub ingress: Option<std::vec::Vec<crate::api::networking::v1::NetworkPolicyIngressRule>>,
    11
    12    /// podSelector selects the pods to which this NetworkPolicy object applies. The array of rules is applied to any pods selected by this field. An empty selector matches all pods in the policy's namespace. Multiple network policies can select the same set of pods. In this case, the ingress rules for each are combined additively. This field is optional. If it is not specified, it defaults to an empty selector.
    13    pub pod_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
    14
    15    /// policyTypes is a list of rule types that the NetworkPolicy relates to. Valid options are \["Ingress"\], \["Egress"\], or \["Ingress", "Egress"\]. If this field is not specified, it will default based on the existence of ingress or egress rules; policies that contain an egress section are assumed to affect egress, and all policies (whether or not they contain an ingress section) are assumed to affect ingress. If you want to write an egress-only policy, you must explicitly specify policyTypes \[ "Egress" \]. Likewise, if you want to write a policy that specifies that no egress is allowed, you must specify a policyTypes value that include "Egress" (since such a policy would not include an egress section and would otherwise default to just \[ "Ingress" \]). This field is beta-level in 1.8
    16    pub policy_types: Option<std::vec::Vec<std::string::String>>,
    17}
    18
    19impl crate::DeepMerge for NetworkPolicySpec {
    20    fn merge_from(&mut self, other: Self) {
    21        crate::merge_strategies::list::atomic(&mut self.egress, other.egress);
    22        crate::merge_strategies::list::atomic(&mut self.ingress, other.ingress);
    23        crate::DeepMerge::merge_from(&mut self.pod_selector, other.pod_selector);
    24        crate::merge_strategies::list::atomic(&mut self.policy_types, other.policy_types);
    25    }
    26}
    27
    28impl<'de> crate::serde::Deserialize<'de> for NetworkPolicySpec {
    29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    30        #[allow(non_camel_case_types)]
    31        enum Field {
    32            Key_egress,
    33            Key_ingress,
    34            Key_pod_selector,
    35            Key_policy_types,
    36            Other,
    37        }
    38
    39        impl<'de> crate::serde::Deserialize<'de> for Field {
    40            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    41                struct Visitor;
    42
    43                impl crate::serde::de::Visitor<'_> for Visitor {
    44                    type Value = Field;
    45
    46                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    47                        f.write_str("field identifier")
    48                    }
    49
    50                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    51                        Ok(match v {
    52                            "egress" => Field::Key_egress,
    53                            "ingress" => Field::Key_ingress,
    54                            "podSelector" => Field::Key_pod_selector,
    55                            "policyTypes" => Field::Key_policy_types,
    56                            _ => Field::Other,
    57                        })
    58                    }
    59                }
    60
    61                deserializer.deserialize_identifier(Visitor)
    62            }
    63        }
    64
    65        struct Visitor;
    66
    67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    68            type Value = NetworkPolicySpec;
    69
    70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    71                f.write_str("NetworkPolicySpec")
    72            }
    73
    74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    75                let mut value_egress: Option<std::vec::Vec<crate::api::networking::v1::NetworkPolicyEgressRule>> = None;
    76                let mut value_ingress: Option<std::vec::Vec<crate::api::networking::v1::NetworkPolicyIngressRule>> = None;
    77                let mut value_pod_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
    78                let mut value_policy_types: Option<std::vec::Vec<std::string::String>> = None;
    79
    80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    81                    match key {
    82                        Field::Key_egress => value_egress = crate::serde::de::MapAccess::next_value(&mut map)?,
    83                        Field::Key_ingress => value_ingress = crate::serde::de::MapAccess::next_value(&mut map)?,
    84                        Field::Key_pod_selector => value_pod_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
    85                        Field::Key_policy_types => value_policy_types = crate::serde::de::MapAccess::next_value(&mut map)?,
    86                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    87                    }
    88                }
    89
    90                Ok(NetworkPolicySpec {
    91                    egress: value_egress,
    92                    ingress: value_ingress,
    93                    pod_selector: value_pod_selector,
    94                    policy_types: value_policy_types,
    95                })
    96            }
    97        }
    98
    99        deserializer.deserialize_struct(
    100            "NetworkPolicySpec",
    101            &[
    102                "egress",
    103                "ingress",
    104                "podSelector",
    105                "policyTypes",
    106            ],
    107            Visitor,
    108        )
    109    }
    110}
    111
    112impl crate::serde::Serialize for NetworkPolicySpec {
    113    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    114        let mut state = serializer.serialize_struct(
    115            "NetworkPolicySpec",
    116            self.egress.as_ref().map_or(0, |_| 1) +
    117            self.ingress.as_ref().map_or(0, |_| 1) +
    118            self.pod_selector.as_ref().map_or(0, |_| 1) +
    119            self.policy_types.as_ref().map_or(0, |_| 1),
    120        )?;
    121        if let Some(value) = &self.egress {
    122            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "egress", value)?;
    123        }
    124        if let Some(value) = &self.ingress {
    125            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ingress", value)?;
    126        }
    127        if let Some(value) = &self.pod_selector {
    128            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "podSelector", value)?;
    129        }
    130        if let Some(value) = &self.policy_types {
    131            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "policyTypes", value)?;
    132        }
    133        crate::serde::ser::SerializeStruct::end(state)
    134    }
    135}
    136
    137#[cfg(feature = "schemars")]
    138impl crate::schemars::JsonSchema for NetworkPolicySpec {
    139    fn schema_name() -> std::borrow::Cow<'static, str> {
    140        "io.k8s.api.networking.v1.NetworkPolicySpec".into()
    141    }
    142
    143    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    144        crate::schemars::json_schema!({
    145            "description": "NetworkPolicySpec provides the specification of a NetworkPolicy",
    146            "type": "object",
    147            "properties": {
    148                "egress": {
    149                    "description": "egress is a list of egress rules to be applied to the selected pods. Outgoing traffic is allowed if there are no NetworkPolicies selecting the pod (and cluster policy otherwise allows the traffic), OR if the traffic matches at least one egress rule across all of the NetworkPolicy objects whose podSelector matches the pod. If this field is empty then this NetworkPolicy limits all outgoing traffic (and serves solely to ensure that the pods it selects are isolated by default). This field is beta-level in 1.8",
    150                    "type": "array",
    151                    "items": (__gen.subschema_for::<crate::api::networking::v1::NetworkPolicyEgressRule>()),
    152                },
    153                "ingress": {
    154                    "description": "ingress is a list of ingress rules to be applied to the selected pods. Traffic is allowed to a pod if there are no NetworkPolicies selecting the pod (and cluster policy otherwise allows the traffic), OR if the traffic source is the pod's local node, OR if the traffic matches at least one ingress rule across all of the NetworkPolicy objects whose podSelector matches the pod. If this field is empty then this NetworkPolicy does not allow any traffic (and serves solely to ensure that the pods it selects are isolated by default)",
    155                    "type": "array",
    156                    "items": (__gen.subschema_for::<crate::api::networking::v1::NetworkPolicyIngressRule>()),
    157                },
    158                "podSelector": ({
    159                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>();
    160                    schema_obj.ensure_object().insert("description".into(), "podSelector selects the pods to which this NetworkPolicy object applies. The array of rules is applied to any pods selected by this field. An empty selector matches all pods in the policy's namespace. Multiple network policies can select the same set of pods. In this case, the ingress rules for each are combined additively. This field is optional. If it is not specified, it defaults to an empty selector.".into());
    161                    schema_obj
    162                }),
    163                "policyTypes": {
    164                    "description": "policyTypes is a list of rule types that the NetworkPolicy relates to. Valid options are [\"Ingress\"], [\"Egress\"], or [\"Ingress\", \"Egress\"]. If this field is not specified, it will default based on the existence of ingress or egress rules; policies that contain an egress section are assumed to affect egress, and all policies (whether or not they contain an ingress section) are assumed to affect ingress. If you want to write an egress-only policy, you must explicitly specify policyTypes [ \"Egress\" ]. Likewise, if you want to write a policy that specifies that no egress is allowed, you must specify a policyTypes value that include \"Egress\" (since such a policy would not include an egress section and would otherwise default to just [ \"Ingress\" ]). This field is beta-level in 1.8",
    165                    "type": "array",
    166                    "items": {
    167                        "type": "string",
    168                    },
    169                },
    170            },
    171        })
    172    }
    173}