Skip to main content

k8s_openapi/v1_36/api/discovery/v1/
endpoint_slice.rs

1// Generated from definition io.k8s.api.discovery.v1.EndpointSlice
2
3/// EndpointSlice represents a set of service endpoints. Most EndpointSlices are created by the EndpointSlice controller to represent the Pods selected by Service objects. For a given service there may be multiple EndpointSlice objects which must be joined to produce the full set of endpoints; you can find all of the slices for a given service by listing EndpointSlices in the service's namespace whose `kubernetes.io/service-name` label contains the service's name.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct EndpointSlice {
6    /// addressType specifies the type of address carried by this EndpointSlice. All addresses in this slice must be the same type. This field is immutable after creation. The following address types are currently supported: * IPv4: Represents an IPv4 Address. * IPv6: Represents an IPv6 Address. * FQDN: Represents a Fully Qualified Domain Name. (Deprecated) The EndpointSlice controller only generates, and kube-proxy only processes, slices of addressType "IPv4" and "IPv6". No semantics are defined for the "FQDN" type.
7    pub address_type: std::string::String,
8
9    /// endpoints is a list of unique endpoints in this slice. Each slice may include a maximum of 1000 endpoints.
10    pub endpoints: Option<std::vec::Vec<crate::api::discovery::v1::Endpoint>>,
11
12    /// Standard object's metadata.
13    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
14
15    /// ports specifies the list of network ports exposed by each endpoint in this slice. Each port must have a unique name. Each slice may include a maximum of 100 ports. Services always have at least 1 port, so EndpointSlices generated by the EndpointSlice controller will likewise always have at least 1 port. EndpointSlices used for other purposes may have an empty ports list.
16    pub ports: Option<std::vec::Vec<crate::api::discovery::v1::EndpointPort>>,
17}
18
19impl crate::Resource for EndpointSlice {
20    const API_VERSION: &'static str = "discovery.k8s.io/v1";
21    const GROUP: &'static str = "discovery.k8s.io";
22    const KIND: &'static str = "EndpointSlice";
23    const VERSION: &'static str = "v1";
24    const URL_PATH_SEGMENT: &'static str = "endpointslices";
25    type Scope = crate::NamespaceResourceScope;
26}
27
28impl crate::ListableResource for EndpointSlice {
29    const LIST_KIND: &'static str = "EndpointSliceList";
30}
31
32impl crate::Metadata for EndpointSlice {
33    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
34
35    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
36        &self.metadata
37    }
38
39    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
40        &mut self.metadata
41    }
42}
43
44impl crate::DeepMerge for EndpointSlice {
45    fn merge_from(&mut self, other: Self) {
46        crate::DeepMerge::merge_from(&mut self.address_type, other.address_type);
47        crate::merge_strategies::list::atomic(&mut self.endpoints, other.endpoints);
48        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
49        crate::merge_strategies::list::atomic(&mut self.ports, other.ports);
50    }
51}
52
53impl<'de> crate::serde::Deserialize<'de> for EndpointSlice {
54    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
55        #[allow(non_camel_case_types)]
56        enum Field {
57            Key_api_version,
58            Key_kind,
59            Key_address_type,
60            Key_endpoints,
61            Key_metadata,
62            Key_ports,
63            Other,
64        }
65
66        impl<'de> crate::serde::Deserialize<'de> for Field {
67            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
68                struct Visitor;
69
70                impl crate::serde::de::Visitor<'_> for Visitor {
71                    type Value = Field;
72
73                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
74                        f.write_str("field identifier")
75                    }
76
77                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
78                        Ok(match v {
79                            "apiVersion" => Field::Key_api_version,
80                            "kind" => Field::Key_kind,
81                            "addressType" => Field::Key_address_type,
82                            "endpoints" => Field::Key_endpoints,
83                            "metadata" => Field::Key_metadata,
84                            "ports" => Field::Key_ports,
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 = EndpointSlice;
98
99            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::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_address_type: Option<std::string::String> = None;
105                let mut value_endpoints: Option<std::vec::Vec<crate::api::discovery::v1::Endpoint>> = None;
106                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
107                let mut value_ports: Option<std::vec::Vec<crate::api::discovery::v1::EndpointPort>> = None;
108
109                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
110                    match key {
111                        Field::Key_api_version => {
112                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
113                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
114                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
115                            }
116                        },
117                        Field::Key_kind => {
118                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
119                            if value_kind != <Self::Value as crate::Resource>::KIND {
120                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
121                            }
122                        },
123                        Field::Key_address_type => value_address_type = crate::serde::de::MapAccess::next_value(&mut map)?,
124                        Field::Key_endpoints => value_endpoints = crate::serde::de::MapAccess::next_value(&mut map)?,
125                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
126                        Field::Key_ports => value_ports = crate::serde::de::MapAccess::next_value(&mut map)?,
127                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
128                    }
129                }
130
131                Ok(EndpointSlice {
132                    address_type: value_address_type.unwrap_or_default(),
133                    endpoints: value_endpoints,
134                    metadata: value_metadata.unwrap_or_default(),
135                    ports: value_ports,
136                })
137            }
138        }
139
140        deserializer.deserialize_struct(
141            <Self as crate::Resource>::KIND,
142            &[
143                "apiVersion",
144                "kind",
145                "addressType",
146                "endpoints",
147                "metadata",
148                "ports",
149            ],
150            Visitor,
151        )
152    }
153}
154
155impl crate::serde::Serialize for EndpointSlice {
156    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
157        let mut state = serializer.serialize_struct(
158            <Self as crate::Resource>::KIND,
159            4 +
160            self.endpoints.as_ref().map_or(0, |_| 1) +
161            self.ports.as_ref().map_or(0, |_| 1),
162        )?;
163        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
164        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
165        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "addressType", &self.address_type)?;
166        if let Some(value) = &self.endpoints {
167            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "endpoints", value)?;
168        }
169        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
170        if let Some(value) = &self.ports {
171            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ports", value)?;
172        }
173        crate::serde::ser::SerializeStruct::end(state)
174    }
175}
176
177#[cfg(feature = "schemars")]
178impl crate::schemars::JsonSchema for EndpointSlice {
179    fn schema_name() -> std::borrow::Cow<'static, str> {
180        "io.k8s.api.discovery.v1.EndpointSlice".into()
181    }
182
183    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
184        crate::schemars::json_schema!({
185            "description": "EndpointSlice represents a set of service endpoints. Most EndpointSlices are created by the EndpointSlice controller to represent the Pods selected by Service objects. For a given service there may be multiple EndpointSlice objects which must be joined to produce the full set of endpoints; you can find all of the slices for a given service by listing EndpointSlices in the service's namespace whose `kubernetes.io/service-name` label contains the service's name.",
186            "type": "object",
187            "properties": {
188                "addressType": {
189                    "description": "addressType specifies the type of address carried by this EndpointSlice. All addresses in this slice must be the same type. This field is immutable after creation. The following address types are currently supported: * IPv4: Represents an IPv4 Address. * IPv6: Represents an IPv6 Address. * FQDN: Represents a Fully Qualified Domain Name. (Deprecated) The EndpointSlice controller only generates, and kube-proxy only processes, slices of addressType \"IPv4\" and \"IPv6\". No semantics are defined for the \"FQDN\" type.",
190                    "type": "string",
191                },
192                "apiVersion": {
193                    "description": "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",
194                    "type": "string",
195                },
196                "endpoints": {
197                    "description": "endpoints is a list of unique endpoints in this slice. Each slice may include a maximum of 1000 endpoints.",
198                    "type": "array",
199                    "items": (__gen.subschema_for::<crate::api::discovery::v1::Endpoint>()),
200                },
201                "kind": {
202                    "description": "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",
203                    "type": "string",
204                },
205                "metadata": ({
206                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
207                    schema_obj.ensure_object().insert("description".into(), "Standard object's metadata.".into());
208                    schema_obj
209                }),
210                "ports": {
211                    "description": "ports specifies the list of network ports exposed by each endpoint in this slice. Each port must have a unique name. Each slice may include a maximum of 100 ports. Services always have at least 1 port, so EndpointSlices generated by the EndpointSlice controller will likewise always have at least 1 port. EndpointSlices used for other purposes may have an empty ports list.",
212                    "type": "array",
213                    "items": (__gen.subschema_for::<crate::api::discovery::v1::EndpointPort>()),
214                },
215            },
216            "required": [
217                "addressType",
218                "metadata",
219            ],
220        })
221    }
222}
223
224#[cfg(feature = "schemars08")]
225impl crate::schemars08::JsonSchema for EndpointSlice {
226    fn schema_name() -> std::string::String {
227        "io.k8s.api.discovery.v1.EndpointSlice".into()
228    }
229
230    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
231        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
232            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
233                description: Some("EndpointSlice represents a set of service endpoints. Most EndpointSlices are created by the EndpointSlice controller to represent the Pods selected by Service objects. For a given service there may be multiple EndpointSlice objects which must be joined to produce the full set of endpoints; you can find all of the slices for a given service by listing EndpointSlices in the service's namespace whose `kubernetes.io/service-name` label contains the service's name.".into()),
234                ..Default::default()
235            })),
236            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
237            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
238                properties: [
239                    (
240                        "addressType".into(),
241                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
242                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
243                                description: Some("addressType specifies the type of address carried by this EndpointSlice. All addresses in this slice must be the same type. This field is immutable after creation. The following address types are currently supported: * IPv4: Represents an IPv4 Address. * IPv6: Represents an IPv6 Address. * FQDN: Represents a Fully Qualified Domain Name. (Deprecated) The EndpointSlice controller only generates, and kube-proxy only processes, slices of addressType \"IPv4\" and \"IPv6\". No semantics are defined for the \"FQDN\" type.".into()),
244                                ..Default::default()
245                            })),
246                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
247                            ..Default::default()
248                        }),
249                    ),
250                    (
251                        "apiVersion".into(),
252                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
253                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
254                                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".into()),
255                                ..Default::default()
256                            })),
257                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
258                            ..Default::default()
259                        }),
260                    ),
261                    (
262                        "endpoints".into(),
263                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
264                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
265                                description: Some("endpoints is a list of unique endpoints in this slice. Each slice may include a maximum of 1000 endpoints.".into()),
266                                ..Default::default()
267                            })),
268                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
269                            array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
270                                items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::discovery::v1::Endpoint>()))),
271                                ..Default::default()
272                            })),
273                            ..Default::default()
274                        }),
275                    ),
276                    (
277                        "kind".into(),
278                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
279                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
280                                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".into()),
281                                ..Default::default()
282                            })),
283                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
284                            ..Default::default()
285                        }),
286                    ),
287                    (
288                        "metadata".into(),
289                        {
290                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>().into_object();
291                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
292                                description: Some("Standard object's metadata.".into()),
293                                ..Default::default()
294                            }));
295                            crate::schemars08::schema::Schema::Object(schema_obj)
296                        },
297                    ),
298                    (
299                        "ports".into(),
300                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
301                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
302                                description: Some("ports specifies the list of network ports exposed by each endpoint in this slice. Each port must have a unique name. Each slice may include a maximum of 100 ports. Services always have at least 1 port, so EndpointSlices generated by the EndpointSlice controller will likewise always have at least 1 port. EndpointSlices used for other purposes may have an empty ports list.".into()),
303                                ..Default::default()
304                            })),
305                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
306                            array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
307                                items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::discovery::v1::EndpointPort>()))),
308                                ..Default::default()
309                            })),
310                            ..Default::default()
311                        }),
312                    ),
313                ].into(),
314                required: [
315                    "addressType".into(),
316                    "metadata".into(),
317                ].into(),
318                ..Default::default()
319            })),
320            ..Default::default()
321        })
322    }
323}