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

1// Generated from definition io.k8s.api.core.v1.EndpointPort
2
3/// EndpointPort is a tuple that describes a single port.
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.
16    pub app_protocol: Option<String>,
17
18    /// The name of this port.  This must match the 'name' field in the corresponding ServicePort. Must be a DNS_LABEL. Optional only if one port is defined.
19    pub name: Option<String>,
20
21    /// The port number of the endpoint.
22    pub port: i32,
23
24    /// The IP protocol for this port. Must be UDP, TCP, or SCTP. Default is TCP.
25    pub protocol: Option<String>,
26}
27
28impl crate::DeepMerge for EndpointPort {
29    fn merge_from(&mut self, other: Self) {
30        crate::DeepMerge::merge_from(&mut self.app_protocol, other.app_protocol);
31        crate::DeepMerge::merge_from(&mut self.name, other.name);
32        crate::DeepMerge::merge_from(&mut self.port, other.port);
33        crate::DeepMerge::merge_from(&mut self.protocol, other.protocol);
34    }
35}
36
37impl<'de> crate::serde::Deserialize<'de> for EndpointPort {
38    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
39        #[allow(non_camel_case_types)]
40        enum Field {
41            Key_app_protocol,
42            Key_name,
43            Key_port,
44            Key_protocol,
45            Other,
46        }
47
48        impl<'de> crate::serde::Deserialize<'de> for Field {
49            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
50                struct Visitor;
51
52                impl crate::serde::de::Visitor<'_> for Visitor {
53                    type Value = Field;
54
55                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56                        f.write_str("field identifier")
57                    }
58
59                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
60                        Ok(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                }
69
70                deserializer.deserialize_identifier(Visitor)
71            }
72        }
73
74        struct Visitor;
75
76        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
77            type Value = EndpointPort;
78
79            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80                f.write_str("EndpointPort")
81            }
82
83            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
84                let mut value_app_protocol: Option<String> = None;
85                let mut value_name: Option<String> = None;
86                let mut value_port: Option<i32> = None;
87                let mut value_protocol: Option<String> = None;
88
89                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
90                    match 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                }
98
99                Ok(EndpointPort {
100                    app_protocol: value_app_protocol,
101                    name: value_name,
102                    port: value_port.unwrap_or_default(),
103                    protocol: value_protocol,
104                })
105            }
106        }
107
108        deserializer.deserialize_struct(
109            "EndpointPort",
110            &[
111                "appProtocol",
112                "name",
113                "port",
114                "protocol",
115            ],
116            Visitor,
117        )
118    }
119}
120
121impl crate::serde::Serialize for EndpointPort {
122    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
123        let mut state = serializer.serialize_struct(
124            "EndpointPort",
125            1 +
126            self.app_protocol.as_ref().map_or(0, |_| 1) +
127            self.name.as_ref().map_or(0, |_| 1) +
128            self.protocol.as_ref().map_or(0, |_| 1),
129        )?;
130        if let Some(value) = &self.app_protocol {
131            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "appProtocol", value)?;
132        }
133        if let Some(value) = &self.name {
134            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
135        }
136        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "port", &self.port)?;
137        if let Some(value) = &self.protocol {
138            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "protocol", value)?;
139        }
140        crate::serde::ser::SerializeStruct::end(state)
141    }
142}
143
144#[cfg(feature = "schemars")]
145impl crate::schemars::JsonSchema for EndpointPort {
146    fn schema_name() -> String {
147        "io.k8s.api.core.v1.EndpointPort".to_owned()
148    }
149
150    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
151        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
152            metadata: Some(Box::new(crate::schemars::schema::Metadata {
153                description: Some("EndpointPort is a tuple that describes a single port.".to_owned()),
154                ..Default::default()
155            })),
156            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
157            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
158                properties: [
159                    (
160                        "appProtocol".to_owned(),
161                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
162                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
163                                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.".to_owned()),
164                                ..Default::default()
165                            })),
166                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
167                            ..Default::default()
168                        }),
169                    ),
170                    (
171                        "name".to_owned(),
172                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
173                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
174                                description: Some("The name of this port.  This must match the 'name' field in the corresponding ServicePort. Must be a DNS_LABEL. Optional only if one port is defined.".to_owned()),
175                                ..Default::default()
176                            })),
177                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
178                            ..Default::default()
179                        }),
180                    ),
181                    (
182                        "port".to_owned(),
183                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
184                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
185                                description: Some("The port number of the endpoint.".to_owned()),
186                                ..Default::default()
187                            })),
188                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
189                            format: Some("int32".to_owned()),
190                            ..Default::default()
191                        }),
192                    ),
193                    (
194                        "protocol".to_owned(),
195                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
196                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
197                                description: Some("The IP protocol for this port. Must be UDP, TCP, or SCTP. Default is TCP.".to_owned()),
198                                ..Default::default()
199                            })),
200                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
201                            ..Default::default()
202                        }),
203                    ),
204                ].into(),
205                required: [
206                    "port".to_owned(),
207                ].into(),
208                ..Default::default()
209            })),
210            ..Default::default()
211        })
212    }
213}