k8s_openapi/v1_32/api/core/v1/
endpoints.rs

1// Generated from definition io.k8s.api.core.v1.Endpoints
2
3/// Endpoints is a collection of endpoints that implement the actual service. Example:
4///
5///   Name: "mysvc",
6///      Subsets: \[
7///        {
8///          Addresses: \[{"ip": "10.10.1.1"}, {"ip": "10.10.2.2"}\],
9///          Ports: \[{"name": "a", "port": 8675}, {"name": "b", "port": 309}\]
10///        },
11///        {
12///          Addresses: \[{"ip": "10.10.3.3"}\],
13///          Ports: \[{"name": "a", "port": 93}, {"name": "b", "port": 76}\]
14///        },
15///     \]
16#[derive(Clone, Debug, Default, PartialEq)]
17pub struct Endpoints {
18    /// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
19    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
20
21    /// The set of all endpoints is the union of all subsets. Addresses are placed into subsets according to the IPs they share. A single address with multiple ports, some of which are ready and some of which are not (because they come from different containers) will result in the address being displayed in different subsets for the different ports. No address will appear in both Addresses and NotReadyAddresses in the same subset. Sets of addresses and ports that comprise a service.
22    pub subsets: Option<Vec<crate::api::core::v1::EndpointSubset>>,
23}
24
25impl crate::Resource for Endpoints {
26    const API_VERSION: &'static str = "v1";
27    const GROUP: &'static str = "";
28    const KIND: &'static str = "Endpoints";
29    const VERSION: &'static str = "v1";
30    const URL_PATH_SEGMENT: &'static str = "endpoints";
31    type Scope = crate::NamespaceResourceScope;
32}
33
34impl crate::ListableResource for Endpoints {
35    const LIST_KIND: &'static str = "EndpointsList";
36}
37
38impl crate::Metadata for Endpoints {
39    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
40
41    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
42        &self.metadata
43    }
44
45    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
46        &mut self.metadata
47    }
48}
49
50impl crate::DeepMerge for Endpoints {
51    fn merge_from(&mut self, other: Self) {
52        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
53        crate::merge_strategies::list::atomic(&mut self.subsets, other.subsets);
54    }
55}
56
57impl<'de> crate::serde::Deserialize<'de> for Endpoints {
58    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
59        #[allow(non_camel_case_types)]
60        enum Field {
61            Key_api_version,
62            Key_kind,
63            Key_metadata,
64            Key_subsets,
65            Other,
66        }
67
68        impl<'de> crate::serde::Deserialize<'de> for Field {
69            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
70                struct Visitor;
71
72                impl crate::serde::de::Visitor<'_> for Visitor {
73                    type Value = Field;
74
75                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76                        f.write_str("field identifier")
77                    }
78
79                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
80                        Ok(match v {
81                            "apiVersion" => Field::Key_api_version,
82                            "kind" => Field::Key_kind,
83                            "metadata" => Field::Key_metadata,
84                            "subsets" => Field::Key_subsets,
85                            _ => Field::Other,
86                        })
87                    }
88                }
89
90                deserializer.deserialize_identifier(Visitor)
91            }
92        }
93
94        struct Visitor;
95
96        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
97            type Value = Endpoints;
98
99            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
100                f.write_str(<Self::Value as crate::Resource>::KIND)
101            }
102
103            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
104                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
105                let mut value_subsets: Option<Vec<crate::api::core::v1::EndpointSubset>> = None;
106
107                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
108                    match key {
109                        Field::Key_api_version => {
110                            let value_api_version: String = crate::serde::de::MapAccess::next_value(&mut map)?;
111                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
112                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
113                            }
114                        },
115                        Field::Key_kind => {
116                            let value_kind: String = crate::serde::de::MapAccess::next_value(&mut map)?;
117                            if value_kind != <Self::Value as crate::Resource>::KIND {
118                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
119                            }
120                        },
121                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
122                        Field::Key_subsets => value_subsets = crate::serde::de::MapAccess::next_value(&mut map)?,
123                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
124                    }
125                }
126
127                Ok(Endpoints {
128                    metadata: value_metadata.unwrap_or_default(),
129                    subsets: value_subsets,
130                })
131            }
132        }
133
134        deserializer.deserialize_struct(
135            <Self as crate::Resource>::KIND,
136            &[
137                "apiVersion",
138                "kind",
139                "metadata",
140                "subsets",
141            ],
142            Visitor,
143        )
144    }
145}
146
147impl crate::serde::Serialize for Endpoints {
148    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
149        let mut state = serializer.serialize_struct(
150            <Self as crate::Resource>::KIND,
151            3 +
152            self.subsets.as_ref().map_or(0, |_| 1),
153        )?;
154        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
155        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
156        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
157        if let Some(value) = &self.subsets {
158            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "subsets", value)?;
159        }
160        crate::serde::ser::SerializeStruct::end(state)
161    }
162}
163
164#[cfg(feature = "schemars")]
165impl crate::schemars::JsonSchema for Endpoints {
166    fn schema_name() -> String {
167        "io.k8s.api.core.v1.Endpoints".to_owned()
168    }
169
170    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
171        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
172            metadata: Some(Box::new(crate::schemars::schema::Metadata {
173                description: Some("Endpoints is a collection of endpoints that implement the actual service. Example:\n\n\t Name: \"mysvc\",\n\t Subsets: [\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\t   {\n\t     Addresses: [{\"ip\": \"10.10.3.3\"}],\n\t     Ports: [{\"name\": \"a\", \"port\": 93}, {\"name\": \"b\", \"port\": 76}]\n\t   },\n\t]".to_owned()),
174                ..Default::default()
175            })),
176            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
177            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
178                properties: [
179                    (
180                        "apiVersion".to_owned(),
181                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
182                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
183                                description: Some("APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources".to_owned()),
184                                ..Default::default()
185                            })),
186                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
187                            ..Default::default()
188                        }),
189                    ),
190                    (
191                        "kind".to_owned(),
192                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
193                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
194                                description: Some("Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds".to_owned()),
195                                ..Default::default()
196                            })),
197                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
198                            ..Default::default()
199                        }),
200                    ),
201                    (
202                        "metadata".to_owned(),
203                        {
204                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>().into_object();
205                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
206                                description: Some("Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".to_owned()),
207                                ..Default::default()
208                            }));
209                            crate::schemars::schema::Schema::Object(schema_obj)
210                        },
211                    ),
212                    (
213                        "subsets".to_owned(),
214                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
215                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
216                                description: Some("The set of all endpoints is the union of all subsets. Addresses are placed into subsets according to the IPs they share. A single address with multiple ports, some of which are ready and some of which are not (because they come from different containers) will result in the address being displayed in different subsets for the different ports. No address will appear in both Addresses and NotReadyAddresses in the same subset. Sets of addresses and ports that comprise a service.".to_owned()),
217                                ..Default::default()
218                            })),
219                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
220                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
221                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::core::v1::EndpointSubset>()))),
222                                ..Default::default()
223                            })),
224                            ..Default::default()
225                        }),
226                    ),
227                ].into(),
228                required: [
229                    "metadata".to_owned(),
230                ].into(),
231                ..Default::default()
232            })),
233            ..Default::default()
234        })
235    }
236}