1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct Endpoint {
6 pub addresses: Vec<String>,
8
9 pub conditions: Option<crate::api::discovery::v1::EndpointConditions>,
11
12 pub deprecated_topology: Option<std::collections::BTreeMap<String, String>>,
14
15 pub hints: Option<crate::api::discovery::v1::EndpointHints>,
17
18 pub hostname: Option<String>,
20
21 pub node_name: Option<String>,
23
24 pub target_ref: Option<crate::api::core::v1::ObjectReference>,
26
27 pub zone: Option<String>,
29}
30
31impl crate::DeepMerge for Endpoint {
32 fn merge_from(&mut self, other: Self) {
33 crate::merge_strategies::list::set(&mut self.addresses, other.addresses);
34 crate::DeepMerge::merge_from(&mut self.conditions, other.conditions);
35 crate::merge_strategies::map::granular(&mut self.deprecated_topology, other.deprecated_topology, |current_item, other_item| {
36 crate::DeepMerge::merge_from(current_item, other_item);
37 });
38 crate::DeepMerge::merge_from(&mut self.hints, other.hints);
39 crate::DeepMerge::merge_from(&mut self.hostname, other.hostname);
40 crate::DeepMerge::merge_from(&mut self.node_name, other.node_name);
41 crate::DeepMerge::merge_from(&mut self.target_ref, other.target_ref);
42 crate::DeepMerge::merge_from(&mut self.zone, other.zone);
43 }
44}
45
46impl<'de> crate::serde::Deserialize<'de> for Endpoint {
47 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
48 #[allow(non_camel_case_types)]
49 enum Field {
50 Key_addresses,
51 Key_conditions,
52 Key_deprecated_topology,
53 Key_hints,
54 Key_hostname,
55 Key_node_name,
56 Key_target_ref,
57 Key_zone,
58 Other,
59 }
60
61 impl<'de> crate::serde::Deserialize<'de> for Field {
62 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
63 struct Visitor;
64
65 impl crate::serde::de::Visitor<'_> for Visitor {
66 type Value = Field;
67
68 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69 f.write_str("field identifier")
70 }
71
72 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
73 Ok(match v {
74 "addresses" => Field::Key_addresses,
75 "conditions" => Field::Key_conditions,
76 "deprecatedTopology" => Field::Key_deprecated_topology,
77 "hints" => Field::Key_hints,
78 "hostname" => Field::Key_hostname,
79 "nodeName" => Field::Key_node_name,
80 "targetRef" => Field::Key_target_ref,
81 "zone" => Field::Key_zone,
82 _ => Field::Other,
83 })
84 }
85 }
86
87 deserializer.deserialize_identifier(Visitor)
88 }
89 }
90
91 struct Visitor;
92
93 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
94 type Value = Endpoint;
95
96 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
97 f.write_str("Endpoint")
98 }
99
100 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
101 let mut value_addresses: Option<Vec<String>> = None;
102 let mut value_conditions: Option<crate::api::discovery::v1::EndpointConditions> = None;
103 let mut value_deprecated_topology: Option<std::collections::BTreeMap<String, String>> = None;
104 let mut value_hints: Option<crate::api::discovery::v1::EndpointHints> = None;
105 let mut value_hostname: Option<String> = None;
106 let mut value_node_name: Option<String> = None;
107 let mut value_target_ref: Option<crate::api::core::v1::ObjectReference> = None;
108 let mut value_zone: Option<String> = None;
109
110 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
111 match key {
112 Field::Key_addresses => value_addresses = crate::serde::de::MapAccess::next_value(&mut map)?,
113 Field::Key_conditions => value_conditions = crate::serde::de::MapAccess::next_value(&mut map)?,
114 Field::Key_deprecated_topology => value_deprecated_topology = crate::serde::de::MapAccess::next_value(&mut map)?,
115 Field::Key_hints => value_hints = crate::serde::de::MapAccess::next_value(&mut map)?,
116 Field::Key_hostname => value_hostname = crate::serde::de::MapAccess::next_value(&mut map)?,
117 Field::Key_node_name => value_node_name = crate::serde::de::MapAccess::next_value(&mut map)?,
118 Field::Key_target_ref => value_target_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
119 Field::Key_zone => value_zone = crate::serde::de::MapAccess::next_value(&mut map)?,
120 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
121 }
122 }
123
124 Ok(Endpoint {
125 addresses: value_addresses.unwrap_or_default(),
126 conditions: value_conditions,
127 deprecated_topology: value_deprecated_topology,
128 hints: value_hints,
129 hostname: value_hostname,
130 node_name: value_node_name,
131 target_ref: value_target_ref,
132 zone: value_zone,
133 })
134 }
135 }
136
137 deserializer.deserialize_struct(
138 "Endpoint",
139 &[
140 "addresses",
141 "conditions",
142 "deprecatedTopology",
143 "hints",
144 "hostname",
145 "nodeName",
146 "targetRef",
147 "zone",
148 ],
149 Visitor,
150 )
151 }
152}
153
154impl crate::serde::Serialize for Endpoint {
155 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
156 let mut state = serializer.serialize_struct(
157 "Endpoint",
158 1 +
159 self.conditions.as_ref().map_or(0, |_| 1) +
160 self.deprecated_topology.as_ref().map_or(0, |_| 1) +
161 self.hints.as_ref().map_or(0, |_| 1) +
162 self.hostname.as_ref().map_or(0, |_| 1) +
163 self.node_name.as_ref().map_or(0, |_| 1) +
164 self.target_ref.as_ref().map_or(0, |_| 1) +
165 self.zone.as_ref().map_or(0, |_| 1),
166 )?;
167 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "addresses", &self.addresses)?;
168 if let Some(value) = &self.conditions {
169 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "conditions", value)?;
170 }
171 if let Some(value) = &self.deprecated_topology {
172 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deprecatedTopology", value)?;
173 }
174 if let Some(value) = &self.hints {
175 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "hints", value)?;
176 }
177 if let Some(value) = &self.hostname {
178 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "hostname", value)?;
179 }
180 if let Some(value) = &self.node_name {
181 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeName", value)?;
182 }
183 if let Some(value) = &self.target_ref {
184 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "targetRef", value)?;
185 }
186 if let Some(value) = &self.zone {
187 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "zone", value)?;
188 }
189 crate::serde::ser::SerializeStruct::end(state)
190 }
191}
192
193#[cfg(feature = "schemars")]
194impl crate::schemars::JsonSchema for Endpoint {
195 fn schema_name() -> String {
196 "io.k8s.api.discovery.v1.Endpoint".to_owned()
197 }
198
199 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
200 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
201 metadata: Some(Box::new(crate::schemars::schema::Metadata {
202 description: Some("Endpoint represents a single logical \"backend\" implementing a service.".to_owned()),
203 ..Default::default()
204 })),
205 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
206 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
207 properties: [
208 (
209 "addresses".to_owned(),
210 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
211 metadata: Some(Box::new(crate::schemars::schema::Metadata {
212 description: Some("addresses of this endpoint. The contents of this field are interpreted according to the corresponding EndpointSlice addressType field. Consumers must handle different types of addresses in the context of their own capabilities. This must contain at least one address but no more than 100. These are all assumed to be fungible and clients may choose to only use the first element. Refer to: https://issue.k8s.io/106267".to_owned()),
213 ..Default::default()
214 })),
215 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
216 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
217 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
218 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
219 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
220 ..Default::default()
221 })
222 ))),
223 ..Default::default()
224 })),
225 ..Default::default()
226 }),
227 ),
228 (
229 "conditions".to_owned(),
230 {
231 let mut schema_obj = __gen.subschema_for::<crate::api::discovery::v1::EndpointConditions>().into_object();
232 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
233 description: Some("conditions contains information about the current status of the endpoint.".to_owned()),
234 ..Default::default()
235 }));
236 crate::schemars::schema::Schema::Object(schema_obj)
237 },
238 ),
239 (
240 "deprecatedTopology".to_owned(),
241 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
242 metadata: Some(Box::new(crate::schemars::schema::Metadata {
243 description: Some("deprecatedTopology contains topology information part of the v1beta1 API. This field is deprecated, and will be removed when the v1beta1 API is removed (no sooner than kubernetes v1.24). While this field can hold values, it is not writable through the v1 API, and any attempts to write to it will be silently ignored. Topology information can be found in the zone and nodeName fields instead.".to_owned()),
244 ..Default::default()
245 })),
246 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
247 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
248 additional_properties: Some(Box::new(
249 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
250 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
251 ..Default::default()
252 })
253 )),
254 ..Default::default()
255 })),
256 ..Default::default()
257 }),
258 ),
259 (
260 "hints".to_owned(),
261 {
262 let mut schema_obj = __gen.subschema_for::<crate::api::discovery::v1::EndpointHints>().into_object();
263 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
264 description: Some("hints contains information associated with how an endpoint should be consumed.".to_owned()),
265 ..Default::default()
266 }));
267 crate::schemars::schema::Schema::Object(schema_obj)
268 },
269 ),
270 (
271 "hostname".to_owned(),
272 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
273 metadata: Some(Box::new(crate::schemars::schema::Metadata {
274 description: Some("hostname of this endpoint. This field may be used by consumers of endpoints to distinguish endpoints from each other (e.g. in DNS names). Multiple endpoints which use the same hostname should be considered fungible (e.g. multiple A values in DNS). Must be lowercase and pass DNS Label (RFC 1123) validation.".to_owned()),
275 ..Default::default()
276 })),
277 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
278 ..Default::default()
279 }),
280 ),
281 (
282 "nodeName".to_owned(),
283 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
284 metadata: Some(Box::new(crate::schemars::schema::Metadata {
285 description: Some("nodeName represents the name of the Node hosting this endpoint. This can be used to determine endpoints local to a Node.".to_owned()),
286 ..Default::default()
287 })),
288 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
289 ..Default::default()
290 }),
291 ),
292 (
293 "targetRef".to_owned(),
294 {
295 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ObjectReference>().into_object();
296 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
297 description: Some("targetRef is a reference to a Kubernetes object that represents this endpoint.".to_owned()),
298 ..Default::default()
299 }));
300 crate::schemars::schema::Schema::Object(schema_obj)
301 },
302 ),
303 (
304 "zone".to_owned(),
305 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
306 metadata: Some(Box::new(crate::schemars::schema::Metadata {
307 description: Some("zone is the name of the Zone this endpoint exists in.".to_owned()),
308 ..Default::default()
309 })),
310 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
311 ..Default::default()
312 }),
313 ),
314 ].into(),
315 required: [
316 "addresses".to_owned(),
317 ].into(),
318 ..Default::default()
319 })),
320 ..Default::default()
321 })
322 }
323}