1// Generated from definition io.k8s.api.discovery.v1.EndpointPort
23/// EndpointPort represents a Port used by an EndpointSlice
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct EndpointPort {
6/// The application protocol for this port. This is used as a hint for implementations to offer richer behavior for protocols that they understand. This field follows standard Kubernetes label syntax. Valid values are either:
7 ///
8 /// * Un-prefixed protocol names - reserved for IANA standard service names (as per RFC-6335 and https://www.iana.org/assignments/service-names).
9 ///
10 /// * Kubernetes-defined prefixed names:
11 /// * 'kubernetes.io/h2c' - HTTP/2 prior knowledge over cleartext as described in https://www.rfc-editor.org/rfc/rfc9113.html#name-starting-http-2-with-prior-
12 /// * 'kubernetes.io/ws' - WebSocket over cleartext as described in https://www.rfc-editor.org/rfc/rfc6455
13 /// * 'kubernetes.io/wss' - WebSocket over TLS as described in https://www.rfc-editor.org/rfc/rfc6455
14 ///
15 /// * Other protocols should use implementation-defined prefixed names such as mycompany.com/my-custom-protocol.
16pub app_protocol: Option<std::string::String>,
1718/// name represents the name of this port. All ports in an EndpointSlice must have a unique name. If the EndpointSlice is derived from a Kubernetes service, this corresponds to the Service.ports\[\].name. Name must either be an empty string or pass DNS_LABEL validation: * must be no more than 63 characters long. * must consist of lower case alphanumeric characters or '-'. * must start and end with an alphanumeric character. Default is empty string.
19pub name: Option<std::string::String>,
2021/// port represents the port number of the endpoint. If the EndpointSlice is derived from a Kubernetes service, this must be set to the service's target port. EndpointSlices used for other purposes may have a nil port.
22pub port: Option<i32>,
2324/// protocol represents the IP protocol for this port. Must be UDP, TCP, or SCTP. Default is TCP.
25pub protocol: Option<std::string::String>,
26}
2728impl crate::DeepMerge for EndpointPort {
29fn merge_from(&mut self, other: Self) {
30crate::DeepMerge::merge_from(&mut self.app_protocol, other.app_protocol);
31crate::DeepMerge::merge_from(&mut self.name, other.name);
32crate::DeepMerge::merge_from(&mut self.port, other.port);
33crate::DeepMerge::merge_from(&mut self.protocol, other.protocol);
34 }
35}
3637impl<'de> crate::serde::Deserialize<'de> for EndpointPort {
38fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
39#[allow(non_camel_case_types)]
40enum Field {
41 Key_app_protocol,
42 Key_name,
43 Key_port,
44 Key_protocol,
45 Other,
46 }
4748impl<'de> crate::serde::Deserialize<'de> for Field {
49fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
50struct Visitor;
5152impl crate::serde::de::Visitor<'_> for Visitor {
53type Value = Field;
5455fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
56 f.write_str("field identifier")
57 }
5859fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
60Ok(match v {
61"appProtocol" => Field::Key_app_protocol,
62"name" => Field::Key_name,
63"port" => Field::Key_port,
64"protocol" => Field::Key_protocol,
65_ => Field::Other,
66 })
67 }
68 }
6970 deserializer.deserialize_identifier(Visitor)
71 }
72 }
7374struct Visitor;
7576impl<'de> crate::serde::de::Visitor<'de> for Visitor {
77type Value = EndpointPort;
7879fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
80 f.write_str("EndpointPort")
81 }
8283fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
84let mut value_app_protocol: Option<std::string::String> = None;
85let mut value_name: Option<std::string::String> = None;
86let mut value_port: Option<i32> = None;
87let mut value_protocol: Option<std::string::String> = None;
8889while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
90match key {
91 Field::Key_app_protocol => value_app_protocol = crate::serde::de::MapAccess::next_value(&mut map)?,
92 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
93 Field::Key_port => value_port = crate::serde::de::MapAccess::next_value(&mut map)?,
94 Field::Key_protocol => value_protocol = crate::serde::de::MapAccess::next_value(&mut map)?,
95 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
96 }
97 }
9899Ok(EndpointPort {
100 app_protocol: value_app_protocol,
101 name: value_name,
102 port: value_port,
103 protocol: value_protocol,
104 })
105 }
106 }
107108 deserializer.deserialize_struct(
109"EndpointPort",
110&[
111"appProtocol",
112"name",
113"port",
114"protocol",
115 ],
116 Visitor,
117 )
118 }
119}
120121impl crate::serde::Serialize for EndpointPort {
122fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
123let mut state = serializer.serialize_struct(
124"EndpointPort",
125self.app_protocol.as_ref().map_or(0, |_| 1) +
126self.name.as_ref().map_or(0, |_| 1) +
127self.port.as_ref().map_or(0, |_| 1) +
128self.protocol.as_ref().map_or(0, |_| 1),
129 )?;
130if let Some(value) = &self.app_protocol {
131crate::serde::ser::SerializeStruct::serialize_field(&mut state, "appProtocol", value)?;
132 }
133if let Some(value) = &self.name {
134crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
135 }
136if let Some(value) = &self.port {
137crate::serde::ser::SerializeStruct::serialize_field(&mut state, "port", value)?;
138 }
139if let Some(value) = &self.protocol {
140crate::serde::ser::SerializeStruct::serialize_field(&mut state, "protocol", value)?;
141 }
142crate::serde::ser::SerializeStruct::end(state)
143 }
144}
145146#[cfg(feature = "schemars")]
147impl crate::schemars::JsonSchema for EndpointPort {
148fn schema_name() -> std::string::String {
149"io.k8s.api.discovery.v1.EndpointPort".into()
150 }
151152fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
153crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
154 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
155 description: Some("EndpointPort represents a Port used by an EndpointSlice".into()),
156 ..Default::default()
157 })),
158 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
159 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
160 properties: [
161 (
162"appProtocol".into(),
163crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
164 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
165 description: Some("The application protocol for this port. This is used as a hint for implementations to offer richer behavior for protocols that they understand. This field follows standard Kubernetes label syntax. Valid values are either:\n\n* Un-prefixed protocol names - reserved for IANA standard service names (as per RFC-6335 and https://www.iana.org/assignments/service-names).\n\n* Kubernetes-defined prefixed names:\n * 'kubernetes.io/h2c' - HTTP/2 prior knowledge over cleartext as described in https://www.rfc-editor.org/rfc/rfc9113.html#name-starting-http-2-with-prior-\n * 'kubernetes.io/ws' - WebSocket over cleartext as described in https://www.rfc-editor.org/rfc/rfc6455\n * 'kubernetes.io/wss' - WebSocket over TLS as described in https://www.rfc-editor.org/rfc/rfc6455\n\n* Other protocols should use implementation-defined prefixed names such as mycompany.com/my-custom-protocol.".into()),
166 ..Default::default()
167 })),
168 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
169 ..Default::default()
170 }),
171 ),
172 (
173"name".into(),
174crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
175 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
176 description: Some("name represents the name of this port. All ports in an EndpointSlice must have a unique name. If the EndpointSlice is derived from a Kubernetes service, this corresponds to the Service.ports[].name. Name must either be an empty string or pass DNS_LABEL validation: * must be no more than 63 characters long. * must consist of lower case alphanumeric characters or '-'. * must start and end with an alphanumeric character. Default is empty string.".into()),
177 ..Default::default()
178 })),
179 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
180 ..Default::default()
181 }),
182 ),
183 (
184"port".into(),
185crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
186 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
187 description: Some("port represents the port number of the endpoint. If the EndpointSlice is derived from a Kubernetes service, this must be set to the service's target port. EndpointSlices used for other purposes may have a nil port.".into()),
188 ..Default::default()
189 })),
190 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
191 format: Some("int32".into()),
192 ..Default::default()
193 }),
194 ),
195 (
196"protocol".into(),
197crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
198 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
199 description: Some("protocol represents the IP protocol for this port. Must be UDP, TCP, or SCTP. Default is TCP.".into()),
200 ..Default::default()
201 })),
202 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
203 ..Default::default()
204 }),
205 ),
206 ].into(),
207 ..Default::default()
208 })),
209 ..Default::default()
210 })
211 }
212}