Skip to content

Commit 00034a0

Browse files
committed
Merge remote-tracking branch 'origin/main' into ignoring_configuration_fields_for_istio -- fixing post merge problems with endpoint addresses
1 parent 2b2d50d commit 00034a0

File tree

18 files changed

+135
-941
lines changed

18 files changed

+135
-941
lines changed

orion-configuration/src/config/bootstrap.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ pub struct Admin {
8686
}
8787

8888
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
89-
89+
#[serde(tag = "name")]
9090
pub enum BootstrapExtension {
91+
#[serde(rename = "internal_listener")]
9192
InternalListener(InternalListenerBootstrap),
9293
}
9394

@@ -113,7 +114,7 @@ mod envoy_conversions {
113114
use super::{
114115
Admin, Bootstrap, BootstrapExtension, DynamicResources, InternalListenerBootstrap, Node, StaticResources,
115116
};
116-
use crate::config::{common::*, core::envoy_conversions::SocketAddressWrapper, grpc::Duration, metrics::StatsSink};
117+
use crate::config::{common::*, grpc::Duration, metrics::StatsSink};
117118
use compact_str::CompactString;
118119
use orion_data_plane_api::envoy_data_plane_api::{
119120
envoy::{
@@ -405,17 +406,14 @@ mod envoy_conversions {
405406
.address
406407
.ok_or(GenericError::MissingField("address is mandatory to setup admin interface"))?
407408
{
408-
address::Address::SocketAddress(sa) => {
409-
let wrapper: SocketAddressWrapper = sa.try_into()?;
410-
wrapper.0
411-
},
409+
address::Address::SocketAddress(sa) => sa.try_into()?,
412410
_ => {
413411
return Err(GenericError::UnsupportedVariant(std::borrow::Cow::Borrowed(
414412
"Only SocketAddress is supported",
415413
)));
416414
},
417415
};
418-
Ok(Self { address: crate::config::core::Address::Socket(address) })
416+
Ok(Self { address })
419417
}
420418
}
421419

orion-configuration/src/config/cluster.rs

Lines changed: 26 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ pub use http_protocol_options::HttpProtocolOptions;
2222
pub mod cluster_specifier;
2323
pub use cluster_specifier::ClusterSpecifier;
2424

25-
use crate::config::{core::Address, transport::BindDeviceOptions, ConfigSource};
25+
use crate::config::{
26+
core::{Address, InternalAddress},
27+
transport::BindDeviceOptions,
28+
ConfigSource,
29+
};
2630

2731
use super::{
2832
common::{is_default, MetadataKey},
@@ -32,8 +36,8 @@ use super::{
3236

3337
use compact_str::CompactString;
3438
use http::HeaderName;
35-
use serde::{Deserialize, Deserializer, Serialize, Serializer};
36-
use std::{fmt::Display, net::SocketAddr, num::NonZeroU32, time::Duration};
39+
use serde::{Deserialize, Serialize};
40+
use std::{fmt::Display, num::NonZeroU32, time::Duration};
3741
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
3842
pub struct Cluster {
3943
pub name: CompactString,
@@ -75,102 +79,16 @@ pub struct EdsClusterConfig {
7579
pub config_source: Option<ConfigSource>,
7680
}
7781

78-
fn simplify_locality_lb_endpoints<S: Serializer>(
79-
value: &Vec<LocalityLbEndpoints>,
80-
serializer: S,
81-
) -> Result<S::Ok, S::Error> {
82-
if value.len() == 1 && value[0].priority == 0 {
83-
simplify_lb_endpoints(&value[0].lb_endpoints, serializer)
84-
} else {
85-
value.serialize(serializer)
86-
}
87-
}
88-
89-
// #[derive(Serialize, Deserialize)]
90-
// #[serde(untagged)]
91-
// enum LocalityLbEndpointsDeser {
92-
// LocalityLbEndpoints(Vec<LocalityLbEndpoints>),
93-
// Simplified(LbEndpointVecDeser),
94-
// }
95-
96-
// impl From<LocalityLbEndpointsDeser> for Vec<LocalityLbEndpoints> {
97-
// fn from(value: LocalityLbEndpointsDeser) -> Self {
98-
// match value {
99-
// LocalityLbEndpointsDeser::Simplified(simple) => {
100-
// vec![LocalityLbEndpoints { priority: 0, lb_endpoints: simple.into() }]
101-
// },
102-
// LocalityLbEndpointsDeser::LocalityLbEndpoints(vec) => vec,
103-
// }
104-
// }
105-
// }
106-
10782
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
10883
pub struct LocalityLbEndpoints {
10984
pub priority: u32,
11085
//#[serde(serialize_with = "simplify_lb_endpoints", deserialize_with = "deser_through::<LbEndpointVecDeser,_,_>")]
11186
pub lb_endpoints: Vec<LbEndpoint>,
11287
}
11388

114-
fn simplify_lb_endpoints<S: Serializer>(value: &Vec<LbEndpoint>, serializer: S) -> Result<S::Ok, S::Error> {
115-
if value.iter().all(|s| is_default(&s.health_status) && s.load_balancing_weight == NonZeroU32::MIN) {
116-
value.iter().map(|endpoint| endpoint.address.clone()).collect::<Vec<_>>().serialize(serializer)
117-
} else {
118-
value.serialize(serializer)
119-
}
120-
}
121-
122-
// #[derive(Serialize, Deserialize)]
123-
// #[serde(untagged)]
124-
// enum LbEndpointVecDeser {
125-
// LbEndpoints(Vec<LbEndpoint>),
126-
// SocketAddr(Vec<SocketAddr>),
127-
// Address(Vec<Address>),
128-
// }
129-
130-
// impl From<LbEndpointVecDeser> for Vec<LbEndpoint> {
131-
// fn from(value: LbEndpointVecDeser) -> Self {
132-
// match value {
133-
// LbEndpointVecDeser::SocketAddr(socket_addrs) => socket_addrs
134-
// .into_iter()
135-
// .map(|socket_addr| LbEndpoint {
136-
// address: EndpointAddress::Socket(socket_addr),
137-
// health_status: HealthStatus::default(),
138-
// load_balancing_weight: NonZeroU32::MIN,
139-
// })
140-
// .collect(),
141-
// LbEndpointVecDeser::Address(address) => address
142-
// .into_iter()
143-
// .filter_map(|address| match address {
144-
// Address::Socket(socket_addr) => Some(LbEndpoint {
145-
// address: EndpointAddress::Socket(socket_addr),
146-
// health_status: HealthStatus::default(),
147-
// load_balancing_weight: NonZeroU32::MIN,
148-
// }),
149-
// Address::Internal(internal_addr) => Some(LbEndpoint {
150-
// address: EndpointAddress::Internal(InternalEndpointAddress {
151-
// server_listener_name: internal_addr.server_listener_name.into(),
152-
// endpoint_id: internal_addr.endpoint_id.map(std::convert::Into::into),
153-
// }),
154-
// health_status: HealthStatus::default(),
155-
// load_balancing_weight: NonZeroU32::MIN,
156-
// }),
157-
// Address::Pipe(_, _) => None, // Skip pipe addresses
158-
// })
159-
// .collect(),
160-
// LbEndpointVecDeser::LbEndpoints(vec) => vec,
161-
// }
162-
// }
163-
// }
164-
165-
// fn deser_through<'de, In: Deserialize<'de>, Out: From<In>, D: Deserializer<'de>>(
166-
// deserializer: D,
167-
// ) -> Result<Out, D::Error> {
168-
// In::deserialize(deserializer).map(Out::from)
169-
// }
170-
17189
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
17290
pub struct LbEndpoint {
173-
pub address: EndpointAddress,
91+
pub address: Address,
17492
#[serde(skip_serializing_if = "is_default", default)]
17593
pub health_status: HealthStatus,
17694
pub load_balancing_weight: NonZeroU32,
@@ -182,46 +100,18 @@ impl Display for LbEndpoint {
182100
}
183101
}
184102

185-
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
186-
#[serde(untagged)]
187-
pub enum EndpointAddress {
188-
Socket(SocketAddr),
189-
Internal(InternalEndpointAddress),
190-
Pipe(String, u32),
191-
}
192-
193-
impl EndpointAddress {
194-
pub fn into_addr(self) -> Result<SocketAddr, String> {
195-
match self {
196-
EndpointAddress::Socket(addr) => Ok(addr),
197-
EndpointAddress::Internal(_) => Err("Cannot convert internal address to socket address".to_owned()),
198-
EndpointAddress::Pipe(_, _) => Err("Cannot convert pipe to socket address".to_owned()),
199-
}
200-
}
201-
}
202-
203-
impl Display for EndpointAddress {
204-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
205-
match self {
206-
EndpointAddress::Socket(socket_addr) => {
207-
f.write_str(format!("EndpointAddress::Socket {socket_addr:?}").as_str())
208-
},
209-
EndpointAddress::Pipe(name, options) => {
210-
f.write_str(format!("EndpointAddress::Pipe {name} {options}").as_str())
211-
},
212-
EndpointAddress::Internal(internal_endpoint_address) => {
213-
f.write_str(format!("EndpointAddress::Internal {internal_endpoint_address:?}").as_str())
214-
},
215-
}
216-
}
217-
}
218-
219103
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
220104
pub struct InternalEndpointAddress {
221105
pub server_listener_name: CompactString,
222106
pub endpoint_id: Option<CompactString>,
223107
}
224108

109+
impl From<InternalAddress> for InternalEndpointAddress {
110+
fn from(value: InternalAddress) -> Self {
111+
InternalEndpointAddress { server_listener_name: value.server_listener_name, endpoint_id: value.endpoint_id }
112+
}
113+
}
114+
225115
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
226116
#[serde(tag = "name")]
227117
pub enum TransportSocket {
@@ -356,14 +246,14 @@ mod envoy_conversions {
356246
#![allow(deprecated)]
357247
use super::{
358248
health_check::{ClusterHostnameError, HealthCheck, HealthCheckProtocol},
359-
Cluster, ClusterDiscoveryType, ClusterLoadAssignment, EndpointAddress, HealthStatus, HttpProtocolOptions,
360-
InternalEndpointAddress, InternalUpstreamTransport, LbEndpoint, LbPolicy, LocalityLbEndpoints, MetadataKind,
361-
MetadataValueSource, OriginalDstConfig, OriginalDstRoutingMethod, TlsConfig, TlsSecret, TransportSocket,
249+
Cluster, ClusterDiscoveryType, ClusterLoadAssignment, HealthStatus, HttpProtocolOptions,
250+
InternalUpstreamTransport, LbEndpoint, LbPolicy, LocalityLbEndpoints, MetadataKind, MetadataValueSource,
251+
OriginalDstConfig, OriginalDstRoutingMethod, TlsConfig, TlsSecret, TransportSocket,
362252
};
363253
use crate::config::{
364254
cluster::EdsClusterConfig,
365255
common::*,
366-
core::{Address, SocketAddressWrapper},
256+
core::Address,
367257
transport::{
368258
BindAddress, BindDeviceOptions, CommonTlsContext, Secrets, SupportedEnvoyTransportSocket,
369259
UpstreamTransportSocketConfig,
@@ -820,17 +710,9 @@ mod envoy_conversions {
820710
health_check_config,
821711
hostname,
822712
additional_addresses,
823-
}) => (|| -> Result<EndpointAddress, GenericError> {
713+
}) => (|| -> Result<Address, GenericError> {
824714
unsupported_field!(health_check_config, hostname, additional_addresses)?;
825-
let address: Address = convert_opt!(address)?;
826-
match address {
827-
Address::Socket(socket_addr) => Ok(EndpointAddress::Socket(socket_addr)),
828-
Address::Internal(internal_addr) => Ok(EndpointAddress::Internal(InternalEndpointAddress {
829-
server_listener_name: internal_addr.server_listener_name.into(),
830-
endpoint_id: internal_addr.endpoint_id.map(std::convert::Into::into),
831-
})),
832-
Address::Pipe(name, options) => Ok(EndpointAddress::Pipe(name, options)),
833-
}
715+
convert_opt!(address)
834716
})(),
835717
EnvoyHostIdentifier::EndpointName(_) => Err(GenericError::unsupported_variant("EndpointName")),
836718
}
@@ -870,9 +752,11 @@ mod envoy_conversions {
870752
e.lb_endpoints
871753
.iter()
872754
.map(|e| match e.address {
873-
EndpointAddress::Socket(_) => e.address.clone().into_addr().and(Ok(())),
874-
EndpointAddress::Pipe(_, _) => Ok(()),
875-
EndpointAddress::Internal(_) => Err("Internal not supported yet".to_owned()),
755+
Address::Socket(_, _) => e.address.clone().into_socket_addr().and(Ok(())),
756+
Address::Pipe(_, _) => Ok(()),
757+
Address::Internal(_) => {
758+
Err(GenericError::from_msg("Internal not supported yet".to_owned()))
759+
},
876760
})
877761
.collect::<Vec<_>>()
878762
})
@@ -939,11 +823,7 @@ mod envoy_conversions {
939823
)?;
940824
let bind_device = convert_vec!(socket_options)?;
941825

942-
let address = if let Some(address) = source_address {
943-
Some(Address::Socket(SocketAddressWrapper::try_from(address)?.0))
944-
} else {
945-
None
946-
};
826+
let address = if let Some(address) = source_address { Some(TryFrom::try_from(address)?) } else { None };
947827
let bind_address = address.map(|a| BindAddress { address: a });
948828

949829
if bind_device.len() > 1 {

0 commit comments

Comments
 (0)