Skip to content

Commit

Permalink
Update xDS APIs (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky authored Mar 21, 2022
1 parent f9ddf69 commit f016bc5
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 310 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
url = https://github.com/envoyproxy/data-plane-api.git
[submodule "proto/udpa"]
path = proto/udpa
url = https://github.com/cncf/udpa.git
url = https://github.com/cncf/xds.git
[submodule "proto/protoc-gen-validate"]
path = proto/protoc-gen-validate
url = https://github.com/envoyproxy/protoc-gen-validate.git
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// we need for XDS GRPC communication.
fn main() -> Result<(), Box<dyn std::error::Error>> {
let proto_files = vec![
"proto/data-plane-api/envoy/config/common/matcher/v3/matcher.proto",
"proto/data-plane-api/envoy/config/accesslog/v3/accesslog.proto",
"proto/data-plane-api/envoy/config/cluster/v3/cluster.proto",
"proto/data-plane-api/envoy/config/listener/v3/listener.proto",
Expand Down
2 changes: 1 addition & 1 deletion proto/data-plane-api
Submodule data-plane-api updated 855 files
2 changes: 1 addition & 1 deletion proto/googleapis
Submodule googleapis updated 6674 files
2 changes: 1 addition & 1 deletion proto/udpa
Submodule udpa updated from bff43e to 4a2b9f
4 changes: 2 additions & 2 deletions src/endpoint/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::{

use serde::{Deserialize, Serialize};

use crate::xds::envoy::config::core::v3::{
use crate::xds::config::core::v3::{
address::Address as EnvoyAddress, SocketAddress as EnvoySocketAddress,
};

Expand Down Expand Up @@ -162,7 +162,7 @@ impl TryFrom<EnvoySocketAddress> for EndpointAddress {
type Error = eyre::Error;

fn try_from(value: EnvoySocketAddress) -> Result<Self, Self::Error> {
use crate::xds::envoy::config::core::v3::socket_address::PortSpecifier;
use crate::xds::config::core::v3::socket_address::PortSpecifier;

let address = Self {
host: value.address.parse()?,
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ mod proxy;
mod runner;
pub(crate) mod ttl_map;
pub(crate) mod utils;
pub(crate) mod xds;

pub mod config;
pub mod endpoint;
pub mod filters;

#[doc(hidden)]
pub mod test_utils;
#[doc(hidden)]
pub mod xds;

pub type Result<T, E = eyre::Error> = std::result::Result<T, E>;

Expand Down
2 changes: 1 addition & 1 deletion src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::{collections::HashMap, convert::TryFrom, sync::Arc};

use crate::xds::envoy::config::core::v3::Metadata as ProtoMetadata;
use crate::xds::config::core::v3::Metadata as ProtoMetadata;

/// Shared state between [`Filter`][crate::filters::Filter]s during processing for a single packet.
pub type DynamicMetadata = HashMap<Arc<String>, Value>;
Expand Down
13 changes: 10 additions & 3 deletions src/xds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ mod xds {
tonic::include_proto!("xds.core.v3");
}
}
}

#[allow(warnings)]
pub(crate) mod envoy {
pub mod r#type {
pub mod matcher {
pub mod v3 {
pub use super::super::super::config::common::matcher::v3::*;
tonic::include_proto!("envoy.r#type.matcher.v3");
}
}
Expand Down Expand Up @@ -59,6 +57,13 @@ pub(crate) mod envoy {
tonic::include_proto!("envoy.config.cluster.v3");
}
}
pub mod common {
pub mod matcher {
pub mod v3 {
tonic::include_proto!("envoy.config.common.matcher.v3");
}
}
}
pub mod core {
pub mod v3 {
tonic::include_proto!("envoy.config.core.v3");
Expand Down Expand Up @@ -106,6 +111,8 @@ const ENDPOINT_TYPE: &str = "type.googleapis.com/envoy.config.endpoint.v3.Cluste
const CLUSTER_TYPE: &str = "type.googleapis.com/envoy.config.cluster.v3.Cluster";
const LISTENER_TYPE: &str = "type.googleapis.com/envoy.config.listener.v3.Listener";

pub use xds::*;

pub(crate) mod ads_client;
pub(crate) mod cluster;
pub(crate) mod listener;
Expand Down
18 changes: 8 additions & 10 deletions src/xds/ads_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@ use crate::{
config::ManagementServer,
xds::{
cluster::ClusterManager,
envoy::{
config::core::v3::Node,
service::discovery::v3::{
aggregated_discovery_service_client::AggregatedDiscoveryServiceClient,
DiscoveryRequest, DiscoveryResponse,
},
},
config::core::v3::Node,
google::rpc::Status as GrpcStatus,
listener::ListenerManager,
metrics::Metrics,
service::discovery::v3::{
aggregated_discovery_service_client::AggregatedDiscoveryServiceClient,
DiscoveryRequest, DiscoveryResponse,
},
CLUSTER_TYPE, ENDPOINT_TYPE, LISTENER_TYPE,
},
Result,
Expand Down Expand Up @@ -457,9 +455,9 @@ pub(super) async fn send_discovery_req(
mod tests {
use super::AdsClient;
use crate::config::ManagementServer;
use crate::xds::envoy::service::discovery::v3::DiscoveryRequest;
use crate::xds::google::rpc::Status as GrpcStatus;
use crate::xds::CLUSTER_TYPE;
use crate::xds::{
google::rpc::Status as GrpcStatus, service::discovery::v3::DiscoveryRequest, CLUSTER_TYPE,
};

use std::time::Duration;

Expand Down
78 changes: 17 additions & 61 deletions src/xds/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ use crate::{
metadata::MetadataView,
xds::{
ads_client::send_discovery_req,
envoy::{
config::{
cluster::v3::{cluster, Cluster},
endpoint::v3::{lb_endpoint, ClusterLoadAssignment},
},
service::discovery::v3::{DiscoveryRequest, DiscoveryResponse},
config::{
cluster::v3::{cluster, Cluster},
endpoint::v3::{lb_endpoint, ClusterLoadAssignment},
},
service::discovery::v3::{DiscoveryRequest, DiscoveryResponse},
CLUSTER_TYPE, ENDPOINT_TYPE,
},
};
Expand Down Expand Up @@ -351,22 +349,21 @@ mod tests {
cluster::SharedCluster,
endpoint::{Endpoint as ProxyEndpoint, EndpointAddress},
xds::{
envoy::{
config::{
cluster::v3::{cluster::ClusterDiscoveryType, Cluster},
core::v3::{
address, socket_address::PortSpecifier, Address, Metadata, SocketAddress,
},
endpoint::v3::{
lb_endpoint::HostIdentifier, ClusterLoadAssignment, Endpoint, LbEndpoint,
LocalityLbEndpoints,
},
config::{
cluster::v3::{cluster::ClusterDiscoveryType, Cluster},
core::v3::{
address, socket_address::PortSpecifier, Address, Metadata, SocketAddress,
},
endpoint::v3::{
lb_endpoint::HostIdentifier, ClusterLoadAssignment, Endpoint, LbEndpoint,
LocalityLbEndpoints,
},
service::discovery::v3::{DiscoveryRequest, DiscoveryResponse},
},
service::discovery::v3::{DiscoveryRequest, DiscoveryResponse},
CLUSTER_TYPE, ENDPOINT_TYPE,
},
};

use prost::Message;
use prost_types::value::Kind;
use prost_types::Struct as ProstStruct;
Expand Down Expand Up @@ -768,6 +765,7 @@ mod tests {
)]
.into_iter()
.collect(),
..<_>::default()
})
};

Expand Down Expand Up @@ -800,7 +798,6 @@ mod tests {
ClusterLoadAssignment {
cluster_name: cluster_name.into(),
endpoints: vec![LocalityLbEndpoints {
locality: None,
lb_endpoints: vec![LbEndpoint {
health_status: 0,
metadata: None,
Expand All @@ -819,9 +816,7 @@ mod tests {
hostname: "".into(),
})),
}],
load_balancing_weight: None,
priority: 0,
proximity: None,
..<_>::default()
}],
named_endpoints: HashMap::new(),
policy: None,
Expand All @@ -832,48 +827,9 @@ mod tests {
fn create_cluster_resource(name: &str) -> Cluster {
Cluster {
name: name.into(),
transport_socket_matches: vec![],
alt_stat_name: "".into(),
eds_cluster_config: None,
connect_timeout: None,
per_connection_buffer_limit_bytes: None,
lb_policy: 0,
load_balancing_policy: None,
load_assignment: Some(create_endpoint_resource(name)),
health_checks: vec![],
max_requests_per_connection: None,
circuit_breakers: None,
upstream_http_protocol_options: None,
common_http_protocol_options: None,
http_protocol_options: None,
http2_protocol_options: None,
typed_extension_protocol_options: HashMap::new(),
dns_refresh_rate: None,
dns_failure_refresh_rate: None,
respect_dns_ttl: false,
dns_lookup_family: 0,
dns_resolvers: vec![],
use_tcp_for_dns_lookups: false,
outlier_detection: None,
cleanup_interval: None,
upstream_bind_config: None,
lb_subset_config: None,
common_lb_config: None,
transport_socket: None,
metadata: None,
protocol_selection: 0,
upstream_connection_options: None,
close_connections_on_host_health_failure: false,
ignore_health_on_host_removal: false,
filters: vec![],
lrs_server: None,
track_timeout_budgets: false,
upstream_config: None,
track_cluster_stats: None,
preconnect_policy: None,
connection_pool_per_downstream_connection: false,
cluster_discovery_type: Some(ClusterDiscoveryType::Type(0)),
lb_config: None,
..<_>::default()
}
}

Expand Down
38 changes: 8 additions & 30 deletions src/xds/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
use crate::filters::{
CreateFilterArgs, FilterChain as ProxyFilterChain, FilterRegistry, SharedFilterChain,
};
use crate::xds::envoy::config::listener::v3::{
use crate::xds::config::listener::v3::{
filter::ConfigType as LdsConfigType, FilterChain, Listener,
};
use crate::xds::envoy::service::discovery::v3::{DiscoveryRequest, DiscoveryResponse};
use crate::xds::service::discovery::v3::{DiscoveryRequest, DiscoveryResponse};
use crate::xds::LISTENER_TYPE;

use crate::xds::ads_client::send_discovery_req;
Expand Down Expand Up @@ -161,10 +161,12 @@ impl ListenerManager {
mod tests {
use super::ListenerManager;
use crate::filters::prelude::*;
use crate::xds::envoy::config::listener::v3::{
filter::ConfigType, Filter as LdsFilter, FilterChain as LdsFilterChain, Listener,
use crate::xds::{
config::listener::v3::{
filter::ConfigType, Filter as LdsFilter, FilterChain as LdsFilterChain, Listener,
},
service::discovery::v3::{DiscoveryRequest, DiscoveryResponse},
};
use crate::xds::envoy::service::discovery::v3::{DiscoveryRequest, DiscoveryResponse};

use std::time::Duration;

Expand Down Expand Up @@ -605,35 +607,11 @@ mod tests {
}
}

#[allow(deprecated)]
fn create_lds_listener(name: String, filter_chains: Vec<LdsFilterChain>) -> Listener {
Listener {
name,
address: None,
filter_chains,
default_filter_chain: None,
use_original_dst: None,
per_connection_buffer_limit_bytes: None,
metadata: None,
deprecated_v1: None,
drain_type: 0,
listener_filters: vec![],
listener_filters_timeout: None,
continue_on_listener_filters_timeout: false,
transparent: None,
freebind: None,
socket_options: vec![],
tcp_fast_open_queue_length: None,
traffic_direction: 0,
udp_listener_config: None,
api_listener: None,
connection_balance_config: None,
reuse_port: false,
access_log: vec![],
udp_writer_config: None,
tcp_backlog_size: None,
bind_to_port: None,
listener_specifier: None,
..<_>::default()
}
}
}
Loading

0 comments on commit f016bc5

Please sign in to comment.