k8s_openapi/v1_30/api/core/v1/
endpoint_subset.rs

1// Generated from definition io.k8s.api.core.v1.EndpointSubset
2
3/// EndpointSubset is a group of addresses with a common set of ports. The expanded set of endpoints is the Cartesian product of Addresses x Ports. For example, given:
4///
5///   {
6///       Addresses: \[{"ip": "10.10.1.1"}, {"ip": "10.10.2.2"}\],
7///       Ports:     \[{"name": "a", "port": 8675}, {"name": "b", "port": 309}\]
8///     }
9///
10/// The resulting set of endpoints can be viewed as:
11///
12///   a: \[ 10.10.1.1:8675, 10.10.2.2:8675 \],
13///     b: \[ 10.10.1.1:309, 10.10.2.2:309 \]
14#[derive(Clone, Debug, Default, PartialEq)]
15pub struct EndpointSubset {
16    /// IP addresses which offer the related ports that are marked as ready. These endpoints should be considered safe for load balancers and clients to utilize.
17    pub addresses: Option<std::vec::Vec<crate::api::core::v1::EndpointAddress>>,
18
19    /// IP addresses which offer the related ports but are not currently marked as ready because they have not yet finished starting, have recently failed a readiness check, or have recently failed a liveness check.
20    pub not_ready_addresses: Option<std::vec::Vec<crate::api::core::v1::EndpointAddress>>,
21
22    /// Port numbers available on the related IP addresses.
23    pub ports: Option<std::vec::Vec<crate::api::core::v1::EndpointPort>>,
24}
25
26impl crate::DeepMerge for EndpointSubset {
27    fn merge_from(&mut self, other: Self) {
28        crate::merge_strategies::list::atomic(&mut self.addresses, other.addresses);
29        crate::merge_strategies::list::atomic(&mut self.not_ready_addresses, other.not_ready_addresses);
30        crate::merge_strategies::list::atomic(&mut self.ports, other.ports);
31    }
32}
33
34impl<'de> crate::serde::Deserialize<'de> for EndpointSubset {
35    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36        #[allow(non_camel_case_types)]
37        enum Field {
38            Key_addresses,
39            Key_not_ready_addresses,
40            Key_ports,
41            Other,
42        }
43
44        impl<'de> crate::serde::Deserialize<'de> for Field {
45            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
46                struct Visitor;
47
48                impl crate::serde::de::Visitor<'_> for Visitor {
49                    type Value = Field;
50
51                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
52                        f.write_str("field identifier")
53                    }
54
55                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
56                        Ok(match v {
57                            "addresses" => Field::Key_addresses,
58                            "notReadyAddresses" => Field::Key_not_ready_addresses,
59                            "ports" => Field::Key_ports,
60                            _ => Field::Other,
61                        })
62                    }
63                }
64
65                deserializer.deserialize_identifier(Visitor)
66            }
67        }
68
69        struct Visitor;
70
71        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
72            type Value = EndpointSubset;
73
74            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
75                f.write_str("EndpointSubset")
76            }
77
78            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
79                let mut value_addresses: Option<std::vec::Vec<crate::api::core::v1::EndpointAddress>> = None;
80                let mut value_not_ready_addresses: Option<std::vec::Vec<crate::api::core::v1::EndpointAddress>> = None;
81                let mut value_ports: Option<std::vec::Vec<crate::api::core::v1::EndpointPort>> = None;
82
83                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
84                    match key {
85                        Field::Key_addresses => value_addresses = crate::serde::de::MapAccess::next_value(&mut map)?,
86                        Field::Key_not_ready_addresses => value_not_ready_addresses = crate::serde::de::MapAccess::next_value(&mut map)?,
87                        Field::Key_ports => value_ports = crate::serde::de::MapAccess::next_value(&mut map)?,
88                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
89                    }
90                }
91
92                Ok(EndpointSubset {
93                    addresses: value_addresses,
94                    not_ready_addresses: value_not_ready_addresses,
95                    ports: value_ports,
96                })
97            }
98        }
99
100        deserializer.deserialize_struct(
101            "EndpointSubset",
102            &[
103                "addresses",
104                "notReadyAddresses",
105                "ports",
106            ],
107            Visitor,
108        )
109    }
110}
111
112impl crate::serde::Serialize for EndpointSubset {
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            "EndpointSubset",
116            self.addresses.as_ref().map_or(0, |_| 1) +
117            self.not_ready_addresses.as_ref().map_or(0, |_| 1) +
118            self.ports.as_ref().map_or(0, |_| 1),
119        )?;
120        if let Some(value) = &self.addresses {
121            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "addresses", value)?;
122        }
123        if let Some(value) = &self.not_ready_addresses {
124            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "notReadyAddresses", value)?;
125        }
126        if let Some(value) = &self.ports {
127            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ports", value)?;
128        }
129        crate::serde::ser::SerializeStruct::end(state)
130    }
131}
132
133#[cfg(feature = "schemars")]
134impl crate::schemars::JsonSchema for EndpointSubset {
135    fn schema_name() -> std::borrow::Cow<'static, str> {
136        "io.k8s.api.core.v1.EndpointSubset".into()
137    }
138
139    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
140        crate::schemars::json_schema!({
141            "description": "EndpointSubset is a group of addresses with a common set of ports. The expanded set of endpoints is the Cartesian product of Addresses x Ports. For example, given:\n\n\t{\n\t  Addresses: [{\"ip\": \"10.10.1.1\"}, {\"ip\": \"10.10.2.2\"}],\n\t  Ports:     [{\"name\": \"a\", \"port\": 8675}, {\"name\": \"b\", \"port\": 309}]\n\t}\n\nThe resulting set of endpoints can be viewed as:\n\n\ta: [ 10.10.1.1:8675, 10.10.2.2:8675 ],\n\tb: [ 10.10.1.1:309, 10.10.2.2:309 ]",
142            "type": "object",
143            "properties": {
144                "addresses": {
145                    "description": "IP addresses which offer the related ports that are marked as ready. These endpoints should be considered safe for load balancers and clients to utilize.",
146                    "type": "array",
147                    "items": (__gen.subschema_for::<crate::api::core::v1::EndpointAddress>()),
148                },
149                "notReadyAddresses": {
150                    "description": "IP addresses which offer the related ports but are not currently marked as ready because they have not yet finished starting, have recently failed a readiness check, or have recently failed a liveness check.",
151                    "type": "array",
152                    "items": (__gen.subschema_for::<crate::api::core::v1::EndpointAddress>()),
153                },
154                "ports": {
155                    "description": "Port numbers available on the related IP addresses.",
156                    "type": "array",
157                    "items": (__gen.subschema_for::<crate::api::core::v1::EndpointPort>()),
158                },
159            },
160        })
161    }
162}