diff --git a/api/envoy/api/v2/core/config_source.proto b/api/envoy/api/v2/core/config_source.proto index 627df30a48a71..5a082d8bc793c 100644 --- a/api/envoy/api/v2/core/config_source.proto +++ b/api/envoy/api/v2/core/config_source.proto @@ -17,9 +17,24 @@ option (udpa.annotations.file_migrate).move_to_package = "envoy.config.core.v3al // [#protodoc-title: Configuration sources] +// xDS API version. This is used to describe both resource and transport +// protocol versions (in distinct configuration fields). +enum ApiVersion { + // When not specified, we assume v2, to ease migration to Envoy's stable API + // versioning. If a client does not support v2 (e.g. due to deprecation), this + // is an invalid value. + AUTO = 0; + + // Use xDS v2 API. + V2 = 1; + + // Use xDS v3alpha API. + V3ALPHA = 2; +} + // API configuration source. This identifies the API type and cluster that Envoy // will use to fetch an xDS API. -// [#next-free-field: 8] +// [#next-free-field: 9] message ApiConfigSource { // APIs may be fetched via either REST or gRPC. enum ApiType { @@ -45,8 +60,13 @@ message ApiConfigSource { DELTA_GRPC = 3; } + // API type (gRPC, REST, delta gRPC) ApiType api_type = 1 [(validate.rules).enum = {defined_only: true}]; + // API version for xDS transport protocol. This describes the xDS gRPC/REST + // endpoint and version of [Delta]DiscoveryRequest/Response used on the wire. + ApiVersion transport_api_version = 8 [(validate.rules).enum = {defined_only: true}]; + // Cluster names should be used only with REST. If > 1 // cluster is defined, clusters will be cycled through if any kind of failure // occurs. @@ -107,18 +127,6 @@ message RateLimitSettings { // inotify for updates. // [#next-free-field: 7] message ConfigSource { - enum XdsApiVersion { - // use for describing explicitly that xDS API version is set automatically. In default, xDS API - // version is V2 - AUTO = 0; - - // use xDS v2 API - V2 = 1; - - // use xDS v3alpha API - V3ALPHA = 2; - } - oneof config_source_specifier { option (validate.required) = true; @@ -165,6 +173,8 @@ message ConfigSource { // timeout applies). The default is 15s. google.protobuf.Duration initial_fetch_timeout = 4; - // API version for xDS endpoint - XdsApiVersion xds_api_version = 6; + // API version for xDS resources. This implies the type URLs that the client + // will request for resources and the resource type that the client will in + // turn expect to be delivered. + ApiVersion resource_api_version = 6 [(validate.rules).enum = {defined_only: true}]; } diff --git a/api/envoy/config/core/v3alpha/config_source.proto b/api/envoy/config/core/v3alpha/config_source.proto index b2e4d5557f1aa..718ca6cc191b7 100644 --- a/api/envoy/config/core/v3alpha/config_source.proto +++ b/api/envoy/config/core/v3alpha/config_source.proto @@ -17,9 +17,24 @@ option java_multiple_files = true; // [#protodoc-title: Configuration sources] +// xDS API version. This is used to describe both resource and transport +// protocol versions (in distinct configuration fields). +enum ApiVersion { + // When not specified, we assume v2, to ease migration to Envoy's stable API + // versioning. If a client does not support v2 (e.g. due to deprecation), this + // is an invalid value. + AUTO = 0; + + // Use xDS v2 API. + V2 = 1; + + // Use xDS v3alpha API. + V3ALPHA = 2; +} + // API configuration source. This identifies the API type and cluster that Envoy // will use to fetch an xDS API. -// [#next-free-field: 8] +// [#next-free-field: 9] message ApiConfigSource { option (udpa.annotations.versioning).previous_message_type = "envoy.api.v2.core.ApiConfigSource"; @@ -47,8 +62,13 @@ message ApiConfigSource { DELTA_GRPC = 3; } + // API type (gRPC, REST, delta gRPC) ApiType api_type = 1 [(validate.rules).enum = {defined_only: true}]; + // API version for xDS transport protocol. This describes the xDS gRPC/REST + // endpoint and version of [Delta]DiscoveryRequest/Response used on the wire. + ApiVersion transport_api_version = 8 [(validate.rules).enum = {defined_only: true}]; + // Cluster names should be used only with REST. If > 1 // cluster is defined, clusters will be cycled through if any kind of failure // occurs. @@ -117,18 +137,6 @@ message RateLimitSettings { message ConfigSource { option (udpa.annotations.versioning).previous_message_type = "envoy.api.v2.core.ConfigSource"; - enum XdsApiVersion { - // use for describing explicitly that xDS API version is set automatically. In default, xDS API - // version is V2 - AUTO = 0; - - // use xDS v2 API - V2 = 1; - - // use xDS v3alpha API - V3ALPHA = 2; - } - oneof config_source_specifier { option (validate.required) = true; @@ -175,6 +183,8 @@ message ConfigSource { // timeout applies). The default is 15s. google.protobuf.Duration initial_fetch_timeout = 4; - // API version for xDS endpoint - XdsApiVersion xds_api_version = 6; + // API version for xDS resources. This implies the type URLs that the client + // will request for resources and the resource type that the client will in + // turn expect to be delivered. + ApiVersion resource_api_version = 6 [(validate.rules).enum = {defined_only: true}]; } diff --git a/generated_api_shadow/envoy/api/v2/core/config_source.proto b/generated_api_shadow/envoy/api/v2/core/config_source.proto index 627df30a48a71..5a082d8bc793c 100644 --- a/generated_api_shadow/envoy/api/v2/core/config_source.proto +++ b/generated_api_shadow/envoy/api/v2/core/config_source.proto @@ -17,9 +17,24 @@ option (udpa.annotations.file_migrate).move_to_package = "envoy.config.core.v3al // [#protodoc-title: Configuration sources] +// xDS API version. This is used to describe both resource and transport +// protocol versions (in distinct configuration fields). +enum ApiVersion { + // When not specified, we assume v2, to ease migration to Envoy's stable API + // versioning. If a client does not support v2 (e.g. due to deprecation), this + // is an invalid value. + AUTO = 0; + + // Use xDS v2 API. + V2 = 1; + + // Use xDS v3alpha API. + V3ALPHA = 2; +} + // API configuration source. This identifies the API type and cluster that Envoy // will use to fetch an xDS API. -// [#next-free-field: 8] +// [#next-free-field: 9] message ApiConfigSource { // APIs may be fetched via either REST or gRPC. enum ApiType { @@ -45,8 +60,13 @@ message ApiConfigSource { DELTA_GRPC = 3; } + // API type (gRPC, REST, delta gRPC) ApiType api_type = 1 [(validate.rules).enum = {defined_only: true}]; + // API version for xDS transport protocol. This describes the xDS gRPC/REST + // endpoint and version of [Delta]DiscoveryRequest/Response used on the wire. + ApiVersion transport_api_version = 8 [(validate.rules).enum = {defined_only: true}]; + // Cluster names should be used only with REST. If > 1 // cluster is defined, clusters will be cycled through if any kind of failure // occurs. @@ -107,18 +127,6 @@ message RateLimitSettings { // inotify for updates. // [#next-free-field: 7] message ConfigSource { - enum XdsApiVersion { - // use for describing explicitly that xDS API version is set automatically. In default, xDS API - // version is V2 - AUTO = 0; - - // use xDS v2 API - V2 = 1; - - // use xDS v3alpha API - V3ALPHA = 2; - } - oneof config_source_specifier { option (validate.required) = true; @@ -165,6 +173,8 @@ message ConfigSource { // timeout applies). The default is 15s. google.protobuf.Duration initial_fetch_timeout = 4; - // API version for xDS endpoint - XdsApiVersion xds_api_version = 6; + // API version for xDS resources. This implies the type URLs that the client + // will request for resources and the resource type that the client will in + // turn expect to be delivered. + ApiVersion resource_api_version = 6 [(validate.rules).enum = {defined_only: true}]; } diff --git a/generated_api_shadow/envoy/config/core/v3alpha/config_source.proto b/generated_api_shadow/envoy/config/core/v3alpha/config_source.proto index 7d315050d6c33..b9c58a30ae8d0 100644 --- a/generated_api_shadow/envoy/config/core/v3alpha/config_source.proto +++ b/generated_api_shadow/envoy/config/core/v3alpha/config_source.proto @@ -17,9 +17,24 @@ option java_multiple_files = true; // [#protodoc-title: Configuration sources] +// xDS API version. This is used to describe both resource and transport +// protocol versions (in distinct configuration fields). +enum ApiVersion { + // When not specified, we assume v2, to ease migration to Envoy's stable API + // versioning. If a client does not support v2 (e.g. due to deprecation), this + // is an invalid value. + AUTO = 0; + + // Use xDS v2 API. + V2 = 1; + + // Use xDS v3alpha API. + V3ALPHA = 2; +} + // API configuration source. This identifies the API type and cluster that Envoy // will use to fetch an xDS API. -// [#next-free-field: 8] +// [#next-free-field: 9] message ApiConfigSource { option (udpa.annotations.versioning).previous_message_type = "envoy.api.v2.core.ApiConfigSource"; @@ -47,8 +62,13 @@ message ApiConfigSource { DELTA_GRPC = 3; } + // API type (gRPC, REST, delta gRPC) ApiType api_type = 1 [(validate.rules).enum = {defined_only: true}]; + // API version for xDS transport protocol. This describes the xDS gRPC/REST + // endpoint and version of [Delta]DiscoveryRequest/Response used on the wire. + ApiVersion transport_api_version = 8 [(validate.rules).enum = {defined_only: true}]; + // Cluster names should be used only with REST. If > 1 // cluster is defined, clusters will be cycled through if any kind of failure // occurs. @@ -117,18 +137,6 @@ message RateLimitSettings { message ConfigSource { option (udpa.annotations.versioning).previous_message_type = "envoy.api.v2.core.ConfigSource"; - enum XdsApiVersion { - // use for describing explicitly that xDS API version is set automatically. In default, xDS API - // version is V2 - AUTO = 0; - - // use xDS v2 API - V2 = 1; - - // use xDS v3alpha API - V3ALPHA = 2; - } - oneof config_source_specifier { option (validate.required) = true; @@ -175,6 +183,8 @@ message ConfigSource { // timeout applies). The default is 15s. google.protobuf.Duration initial_fetch_timeout = 4; - // API version for xDS endpoint - XdsApiVersion xds_api_version = 6; + // API version for xDS resources. This implies the type URLs that the client + // will request for resources and the resource type that the client will in + // turn expect to be delivered. + ApiVersion resource_api_version = 6 [(validate.rules).enum = {defined_only: true}]; } diff --git a/source/common/config/BUILD b/source/common/config/BUILD index ec0b8600c5181..2f9bdca0ce5a8 100644 --- a/source/common/config/BUILD +++ b/source/common/config/BUILD @@ -64,6 +64,7 @@ envoy_cc_library( srcs = ["delta_subscription_impl.cc"], hdrs = ["delta_subscription_impl.h"], deps = [ + ":api_version_lib", ":grpc_stream_lib", ":new_grpc_mux_lib", ":utility_lib", @@ -84,6 +85,7 @@ envoy_cc_library( srcs = ["delta_subscription_state.cc"], hdrs = ["delta_subscription_state.h"], deps = [ + ":api_version_lib", ":pausable_ack_queue_lib", "//include/envoy/config:subscription_interface", "//include/envoy/event:dispatcher_interface", @@ -93,6 +95,7 @@ envoy_cc_library( "//source/common/common:token_bucket_impl_lib", "//source/common/grpc:common_lib", "//source/common/protobuf", + "@envoy_api//envoy/api/v2:pkg_cc_proto", "@envoy_api//envoy/service/discovery/v3alpha:pkg_cc_proto", ], ) @@ -136,6 +139,7 @@ envoy_cc_library( srcs = ["grpc_mux_impl.cc"], hdrs = ["grpc_mux_impl.h"], deps = [ + ":api_version_lib", ":grpc_stream_lib", ":utility_lib", "//include/envoy/config:grpc_mux_interface", @@ -143,6 +147,7 @@ envoy_cc_library( "//include/envoy/upstream:cluster_manager_interface", "//source/common/common:minimal_logger_lib", "//source/common/protobuf", + "@envoy_api//envoy/api/v2:pkg_cc_proto", "@envoy_api//envoy/service/discovery/v3alpha:pkg_cc_proto", ], ) @@ -185,6 +190,7 @@ envoy_cc_library( ":watch_map_lib", "//include/envoy/event:dispatcher_interface", "//include/envoy/grpc:async_client_interface", + "@envoy_api//envoy/api/v2:pkg_cc_proto", "@envoy_api//envoy/service/discovery/v3alpha:pkg_cc_proto", ], ) @@ -197,6 +203,7 @@ envoy_cc_library( "http_api_protos", ], deps = [ + ":api_version_lib", "//include/envoy/config:subscription_interface", "//include/envoy/event:dispatcher_interface", "//source/common/buffer:buffer_lib", @@ -206,6 +213,7 @@ envoy_cc_library( "//source/common/http:rest_api_fetcher_lib", "//source/common/protobuf", "//source/common/protobuf:utility_lib", + "@envoy_api//envoy/api/v2:pkg_cc_proto", "@envoy_api//envoy/service/discovery/v3alpha:pkg_cc_proto", ], ) @@ -239,8 +247,15 @@ envoy_cc_library( name = "protobuf_link_hacks", hdrs = ["protobuf_link_hacks.h"], deps = [ + "@envoy_api//envoy/api/v2:pkg_cc_proto", + "@envoy_api//envoy/service/cluster/v3alpha:pkg_cc_proto", + "@envoy_api//envoy/service/discovery/v2:pkg_cc_proto", "@envoy_api//envoy/service/discovery/v3alpha:pkg_cc_proto", + "@envoy_api//envoy/service/endpoint/v3alpha:pkg_cc_proto", + "@envoy_api//envoy/service/listener/v3alpha:pkg_cc_proto", + "@envoy_api//envoy/service/ratelimit/v2:pkg_cc_proto", "@envoy_api//envoy/service/ratelimit/v3alpha:pkg_cc_proto", + "@envoy_api//envoy/service/route/v3alpha:pkg_cc_proto", "@envoy_api//envoy/service/runtime/v3alpha:pkg_cc_proto", "@envoy_api//envoy/service/secret/v3alpha:pkg_cc_proto", ], @@ -300,6 +315,7 @@ envoy_cc_library( "//source/common/grpc:common_lib", "//source/common/protobuf", "@envoy_api//envoy/annotations:pkg_cc_proto", + "@envoy_api//envoy/config/core/v3alpha:pkg_cc_proto", ], ) diff --git a/source/common/config/delta_subscription_state.h b/source/common/config/delta_subscription_state.h index 3a275e169f372..2d0d53b7fa4fd 100644 --- a/source/common/config/delta_subscription_state.h +++ b/source/common/config/delta_subscription_state.h @@ -1,5 +1,6 @@ #pragma once +#include "envoy/api/v2/discovery.pb.h" #include "envoy/config/subscription.h" #include "envoy/event/dispatcher.h" #include "envoy/grpc/status.h" @@ -8,6 +9,7 @@ #include "common/common/assert.h" #include "common/common/logger.h" +#include "common/config/api_version.h" #include "common/config/pausable_ack_queue.h" namespace Envoy { diff --git a/source/common/config/grpc_mux_impl.h b/source/common/config/grpc_mux_impl.h index 075943a604e56..4cf797c3ade1c 100644 --- a/source/common/config/grpc_mux_impl.h +++ b/source/common/config/grpc_mux_impl.h @@ -3,6 +3,7 @@ #include #include +#include "envoy/api/v2/discovery.pb.h" #include "envoy/common/time.h" #include "envoy/config/grpc_mux.h" #include "envoy/config/subscription.h" @@ -13,6 +14,7 @@ #include "common/common/cleanup.h" #include "common/common/logger.h" +#include "common/config/api_version.h" #include "common/config/grpc_stream.h" #include "common/config/utility.h" diff --git a/source/common/config/http_subscription_impl.cc b/source/common/config/http_subscription_impl.cc index 75b0e4f426e4d..57bc59407657e 100644 --- a/source/common/config/http_subscription_impl.cc +++ b/source/common/config/http_subscription_impl.cc @@ -22,7 +22,7 @@ HttpSubscriptionImpl::HttpSubscriptionImpl( const std::string& remote_cluster_name, Event::Dispatcher& dispatcher, Runtime::RandomGenerator& random, std::chrono::milliseconds refresh_interval, std::chrono::milliseconds request_timeout, const Protobuf::MethodDescriptor& service_method, - SubscriptionCallbacks& callbacks, SubscriptionStats stats, + absl::string_view type_url, SubscriptionCallbacks& callbacks, SubscriptionStats stats, std::chrono::milliseconds init_fetch_timeout, ProtobufMessage::ValidationVisitor& validation_visitor) : Http::RestApiFetcher(cm, remote_cluster_name, dispatcher, random, refresh_interval, @@ -30,6 +30,7 @@ HttpSubscriptionImpl::HttpSubscriptionImpl( callbacks_(callbacks), stats_(stats), dispatcher_(dispatcher), init_fetch_timeout_(init_fetch_timeout), validation_visitor_(validation_visitor) { request_.mutable_node()->CopyFrom(local_info.node()); + request_.set_type_url(std::string(type_url)); ASSERT(service_method.options().HasExtension(google::api::http)); const auto& http_rule = service_method.options().GetExtension(google::api::http); path_ = http_rule.post(); diff --git a/source/common/config/http_subscription_impl.h b/source/common/config/http_subscription_impl.h index 00861e5de5773..ef2a61569fa4e 100644 --- a/source/common/config/http_subscription_impl.h +++ b/source/common/config/http_subscription_impl.h @@ -1,9 +1,11 @@ #pragma once +#include "envoy/api/v2/discovery.pb.h" #include "envoy/config/subscription.h" #include "envoy/event/dispatcher.h" #include "envoy/service/discovery/v3alpha/discovery.pb.h" +#include "common/config/api_version.h" #include "common/http/rest_api_fetcher.h" namespace Envoy { @@ -24,7 +26,7 @@ class HttpSubscriptionImpl : public Http::RestApiFetcher, const std::string& remote_cluster_name, Event::Dispatcher& dispatcher, Runtime::RandomGenerator& random, std::chrono::milliseconds refresh_interval, std::chrono::milliseconds request_timeout, - const Protobuf::MethodDescriptor& service_method, + const Protobuf::MethodDescriptor& service_method, absl::string_view type_url, SubscriptionCallbacks& callbacks, SubscriptionStats stats, std::chrono::milliseconds init_fetch_timeout, ProtobufMessage::ValidationVisitor& validation_visitor); diff --git a/source/common/config/new_grpc_mux_impl.h b/source/common/config/new_grpc_mux_impl.h index b0e0f6c505427..8f52d8c463800 100644 --- a/source/common/config/new_grpc_mux_impl.h +++ b/source/common/config/new_grpc_mux_impl.h @@ -1,11 +1,13 @@ #pragma once +#include "envoy/api/v2/discovery.pb.h" #include "envoy/common/token_bucket.h" #include "envoy/config/grpc_mux.h" #include "envoy/config/subscription.h" #include "envoy/service/discovery/v3alpha/discovery.pb.h" #include "common/common/logger.h" +#include "common/config/api_version.h" #include "common/config/delta_subscription_state.h" #include "common/config/grpc_stream.h" #include "common/config/pausable_ack_queue.h" diff --git a/source/common/config/protobuf_link_hacks.h b/source/common/config/protobuf_link_hacks.h index d1e4a915b8c36..9ba49faf13746 100644 --- a/source/common/config/protobuf_link_hacks.h +++ b/source/common/config/protobuf_link_hacks.h @@ -1,16 +1,47 @@ #pragma once +#include "envoy/api/v2/cds.pb.h" +#include "envoy/api/v2/eds.pb.h" +#include "envoy/api/v2/lds.pb.h" +#include "envoy/api/v2/rds.pb.h" +#include "envoy/api/v2/srds.pb.h" +#include "envoy/service/cluster/v3alpha/cds.pb.h" +#include "envoy/service/discovery/v2/ads.pb.h" +#include "envoy/service/discovery/v2/rtds.pb.h" +#include "envoy/service/discovery/v2/sds.pb.h" #include "envoy/service/discovery/v3alpha/ads.pb.h" +#include "envoy/service/endpoint/v3alpha/eds.pb.h" +#include "envoy/service/listener/v3alpha/lds.pb.h" +#include "envoy/service/ratelimit/v2/rls.pb.h" #include "envoy/service/ratelimit/v3alpha/rls.pb.h" +#include "envoy/service/route/v3alpha/rds.pb.h" +#include "envoy/service/route/v3alpha/srds.pb.h" #include "envoy/service/runtime/v3alpha/rtds.pb.h" #include "envoy/service/secret/v3alpha/sds.pb.h" +// API_NO_BOOST_FILE + namespace Envoy { // Hack to force linking of the service: https://github.com/google/protobuf/issues/4221. // This file should be included ONLY if this hack is required. -const envoy::service::discovery::v3alpha::AdsDummy _ads_dummy; -const envoy::service::ratelimit::v3alpha::RateLimitRequest _rls_dummy; -const envoy::service::secret::v3alpha::SdsDummy _sds_dummy; -const envoy::service::runtime::v3alpha::RtdsDummy _tds_dummy; +const envoy::service::discovery::v2::AdsDummy _ads_dummy_v2; +const envoy::service::ratelimit::v2::RateLimitRequest _rls_dummy_v2; +const envoy::service::discovery::v2::SdsDummy _sds_dummy_v2; +const envoy::service::discovery::v2::RtdsDummy _tds_dummy_v2; +const envoy::api::v2::LdsDummy _lds_dummy_v2; +const envoy::api::v2::RdsDummy _rds_dummy_v2; +const envoy::api::v2::CdsDummy _cds_dummy_v2; +const envoy::api::v2::EdsDummy _eds_dummy_v2; +const envoy::api::v2::SrdsDummy _srds_dummy_v2; + +const envoy::service::discovery::v3alpha::AdsDummy _ads_dummy_v3; +const envoy::service::ratelimit::v3alpha::RateLimitRequest _rls_dummy_v3; +const envoy::service::secret::v3alpha::SdsDummy _sds_dummy_v3; +const envoy::service::runtime::v3alpha::RtdsDummy _tds_dummy_v3; +const envoy::service::listener::v3alpha::LdsDummy _lds_dummy_v3; +const envoy::service::route::v3alpha::RdsDummy _rds_dummy_v3; +const envoy::service::cluster::v3alpha::CdsDummy _cds_dummy_v3; +const envoy::service::endpoint::v3alpha::EdsDummy _eds_dummy_v3; +const envoy::service::route::v3alpha::SrdsDummy _srds_dummy_v4; } // namespace Envoy diff --git a/source/common/config/subscription_factory_impl.cc b/source/common/config/subscription_factory_impl.cc index 891888cd2c06e..a625ece74830a 100644 --- a/source/common/config/subscription_factory_impl.cc +++ b/source/common/config/subscription_factory_impl.cc @@ -50,7 +50,7 @@ SubscriptionPtr SubscriptionFactoryImpl::subscriptionFromConfigSource( result = std::make_unique( local_info_, cm_, api_config_source.cluster_names()[0], dispatcher_, random_, Utility::apiConfigSourceRefreshDelay(api_config_source), - Utility::apiConfigSourceRequestTimeout(api_config_source), restMethod(type_url), + Utility::apiConfigSourceRequestTimeout(api_config_source), restMethod(type_url), type_url, callbacks, stats, Utility::configSourceInitialFetchTimeout(config), validation_visitor_); break; case envoy::config::core::v3alpha::ApiConfigSource::GRPC: diff --git a/source/common/config/type_to_endpoint.cc b/source/common/config/type_to_endpoint.cc index 60cfd65755e0c..1d0285a8ca4d7 100644 --- a/source/common/config/type_to_endpoint.cc +++ b/source/common/config/type_to_endpoint.cc @@ -46,9 +46,7 @@ TypeUrlToServiceMap* buildTypeUrlToServiceMap() { const auto* service_desc = Protobuf::DescriptorPool::generated_pool()->FindServiceByName(service_name); // TODO(htuch): this should become an ASSERT once all v3 descriptors are linked in. - if (service_desc == nullptr) { - continue; - } + ASSERT(service_desc != nullptr, fmt::format("{} missing", service_name)); ASSERT(service_desc->options().HasExtension(envoy::annotations::resource)); const std::string resource_type_url = Grpc::Common::typeUrl( service_desc->options().GetExtension(envoy::annotations::resource).type()); diff --git a/source/common/config/type_to_endpoint.h b/source/common/config/type_to_endpoint.h index c5ef2d7e7e013..0eb56f5bfacd1 100644 --- a/source/common/config/type_to_endpoint.h +++ b/source/common/config/type_to_endpoint.h @@ -1,5 +1,7 @@ #pragma once +#include "envoy/config/core/v3alpha/config_source.pb.h" + #include "common/protobuf/protobuf.h" #include "absl/strings/string_view.h" @@ -8,12 +10,12 @@ namespace Envoy { namespace Config { // Translates an xDS resource type_url to the name of the delta gRPC service that carries it. -const Protobuf::MethodDescriptor& deltaGrpcMethod(absl::string_view type_url); +const Protobuf::MethodDescriptor& deltaGrpcMethod(absl::string_view resource_type_url); // Translates an xDS resource type_url to the name of the state-of-the-world gRPC service that // carries it. -const Protobuf::MethodDescriptor& sotwGrpcMethod(absl::string_view type_url); +const Protobuf::MethodDescriptor& sotwGrpcMethod(absl::string_view resource_type_url); // Translates an xDS resource type_url to the name of the REST service that carries it. -const Protobuf::MethodDescriptor& restMethod(absl::string_view type_url); +const Protobuf::MethodDescriptor& restMethod(absl::string_view resource_type_url); } // namespace Config } // namespace Envoy diff --git a/source/common/router/rds_impl.cc b/source/common/router/rds_impl.cc index 066adfdd7be30..154cd5e83a7a6 100644 --- a/source/common/router/rds_impl.cc +++ b/source/common/router/rds_impl.cc @@ -65,8 +65,7 @@ RdsRouteConfigSubscription::RdsRouteConfigSubscription( const uint64_t manager_identifier, Server::Configuration::ServerFactoryContext& factory_context, ProtobufMessage::ValidationVisitor& validator, Init::Manager& init_manager, const std::string& stat_prefix, - Envoy::Router::RouteConfigProviderManagerImpl& route_config_provider_manager, - envoy::config::core::v3alpha::ConfigSource::XdsApiVersion xds_api_version) + Envoy::Router::RouteConfigProviderManagerImpl& route_config_provider_manager) : route_config_name_(rds.route_config_name()), factory_context_(factory_context), validator_(validator), init_manager_(init_manager), init_target_(fmt::format("RdsRouteConfigSubscription {}", route_config_name_), @@ -74,11 +73,12 @@ RdsRouteConfigSubscription::RdsRouteConfigSubscription( scope_(factory_context.scope().createScope(stat_prefix + "rds." + route_config_name_ + ".")), stat_prefix_(stat_prefix), stats_({ALL_RDS_STATS(POOL_COUNTER(*scope_))}), route_config_provider_manager_(route_config_provider_manager), - manager_identifier_(manager_identifier), xds_api_version_(xds_api_version) { + manager_identifier_(manager_identifier) { subscription_ = factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource( - rds.config_source(), loadTypeUrl(), *scope_, *this); + rds.config_source(), loadTypeUrl(rds.config_source().resource_api_version()), *scope_, + *this); config_update_info_ = std::make_unique(factory_context.timeSource(), validator); } @@ -126,7 +126,7 @@ void RdsRouteConfigSubscription::onConfigUpdate( // the listener might have been torn down, need to remove this. vhds_subscription_ = std::make_unique( config_update_info_, factory_context_, stat_prefix_, route_config_providers_, - config_update_info_->routeConfiguration().vhds().config_source().xds_api_version()); + config_update_info_->routeConfiguration().vhds().config_source().resource_api_version()); vhds_subscription_->registerInitTargetWithInitManager( noop_init_manager == nullptr ? getRdsConfigInitManager() : *noop_init_manager); } else { @@ -205,18 +205,19 @@ bool RdsRouteConfigSubscription::validateUpdateSize(int num_resources) { return true; } -std::string RdsRouteConfigSubscription::loadTypeUrl() { - switch (xds_api_version_) { +std::string RdsRouteConfigSubscription::loadTypeUrl( + envoy::config::core::v3alpha::ApiVersion resource_api_version) { + switch (resource_api_version) { // automatically set api version as V2 - case envoy::config::core::v3alpha::ConfigSource::AUTO: - case envoy::config::core::v3alpha::ConfigSource::V2: + case envoy::config::core::v3alpha::ApiVersion::AUTO: + case envoy::config::core::v3alpha::ApiVersion::V2: return Grpc::Common::typeUrl( API_NO_BOOST(envoy::api::v2::RouteConfiguration().GetDescriptor()->full_name())); - case envoy::config::core::v3alpha::ConfigSource::V3ALPHA: + case envoy::config::core::v3alpha::ApiVersion::V3ALPHA: return Grpc::Common::typeUrl(API_NO_BOOST( envoy::config::route::v3alpha::RouteConfiguration().GetDescriptor()->full_name())); default: - throw EnvoyException(fmt::format("type {} is not supported", xds_api_version_)); + NOT_REACHED_GCOVR_EXCL_LINE; } } @@ -293,7 +294,7 @@ Router::RouteConfigProviderSharedPtr RouteConfigProviderManagerImpl::createRdsRo RdsRouteConfigSubscriptionSharedPtr subscription(new RdsRouteConfigSubscription( rds, manager_identifier, factory_context.getServerFactoryContext(), factory_context.messageValidationVisitor(), factory_context.initManager(), stat_prefix, - *this, rds.config_source().xds_api_version())); + *this)); init_manager.add(subscription->init_target_); std::shared_ptr new_provider{ new RdsRouteConfigProviderImpl(std::move(subscription), factory_context)}; diff --git a/source/common/router/rds_impl.h b/source/common/router/rds_impl.h index b2d568d8fd828..8601c4194b093 100644 --- a/source/common/router/rds_impl.h +++ b/source/common/router/rds_impl.h @@ -143,12 +143,11 @@ class RdsRouteConfigSubscription : Envoy::Config::SubscriptionCallbacks, const uint64_t manager_identifier, Server::Configuration::ServerFactoryContext& factory_context, ProtobufMessage::ValidationVisitor& validator, Init::Manager& init_manager, - const std::string& stat_prefix, RouteConfigProviderManagerImpl& route_config_provider_manager, - const envoy::config::core::v3alpha::ConfigSource::XdsApiVersion xds_api_version = - envoy::config::core::v3alpha::ConfigSource::AUTO); + const std::string& stat_prefix, + RouteConfigProviderManagerImpl& route_config_provider_manager); bool validateUpdateSize(int num_resources); - std::string loadTypeUrl(); + static std::string loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version); Init::Manager& getRdsConfigInitManager() { return init_manager_; } @@ -168,7 +167,6 @@ class RdsRouteConfigSubscription : Envoy::Config::SubscriptionCallbacks, VhdsSubscriptionPtr vhds_subscription_; RouteConfigUpdatePtr config_update_info_; Common::CallbackManager<> update_callback_manager_; - envoy::config::core::v3alpha::ConfigSource::XdsApiVersion xds_api_version_; friend class RouteConfigProviderManagerImpl; // Access to addUpdateCallback diff --git a/source/common/router/scoped_rds.cc b/source/common/router/scoped_rds.cc index 2ac24e4f5df5f..5acae3ff004d0 100644 --- a/source/common/router/scoped_rds.cc +++ b/source/common/router/scoped_rds.cc @@ -103,11 +103,11 @@ ScopedRdsConfigSubscription::ScopedRdsConfigSubscription( stats_({ALL_SCOPED_RDS_STATS(POOL_COUNTER(*scope_))}), rds_config_source_(std::move(rds_config_source)), validation_visitor_(factory_context.messageValidationVisitor()), stat_prefix_(stat_prefix), - route_config_provider_manager_(route_config_provider_manager), - xds_api_version_(rds_config_source_.xds_api_version()) { + route_config_provider_manager_(route_config_provider_manager) { subscription_ = factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource( - scoped_rds.scoped_rds_config_source(), loadTypeUrl(), *scope_, *this); + scoped_rds.scoped_rds_config_source(), + loadTypeUrl(rds_config_source_.resource_api_version()), *scope_, *this); initialize([scope_key_builder]() -> Envoy::Config::ConfigProvider::ConfigConstSharedPtr { return std::make_shared( @@ -349,18 +349,19 @@ void ScopedRdsConfigSubscription::onConfigUpdate( onConfigUpdate(to_add_repeated, to_remove_repeated, version_info); } -std::string ScopedRdsConfigSubscription::loadTypeUrl() { - switch (xds_api_version_) { +std::string ScopedRdsConfigSubscription::loadTypeUrl( + envoy::config::core::v3alpha::ApiVersion resource_api_version) { + switch (resource_api_version) { // automatically set api version as V2 - case envoy::config::core::v3alpha::ConfigSource::AUTO: - case envoy::config::core::v3alpha::ConfigSource::V2: + case envoy::config::core::v3alpha::ApiVersion::AUTO: + case envoy::config::core::v3alpha::ApiVersion::V2: return Grpc::Common::typeUrl( API_NO_BOOST(envoy::api::v2::ScopedRouteConfiguration().GetDescriptor()->full_name())); - case envoy::config::core::v3alpha::ConfigSource::V3ALPHA: + case envoy::config::core::v3alpha::ApiVersion::V3ALPHA: return Grpc::Common::typeUrl(API_NO_BOOST( envoy::config::route::v3alpha::ScopedRouteConfiguration().GetDescriptor()->full_name())); default: - throw EnvoyException(fmt::format("type {} is not supported", xds_api_version_)); + NOT_REACHED_GCOVR_EXCL_LINE; } } diff --git a/source/common/router/scoped_rds.h b/source/common/router/scoped_rds.h index 9b4481f0b7321..49e801fffe42b 100644 --- a/source/common/router/scoped_rds.h +++ b/source/common/router/scoped_rds.h @@ -166,7 +166,7 @@ class ScopedRdsConfigSubscription : public Envoy::Config::DeltaConfigSubscriptio resource) .name(); } - std::string loadTypeUrl(); + static std::string loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version); // Propagate RDS updates to ScopeConfigImpl in workers. void onRdsConfigUpdate(const std::string& scope_name, RdsRouteConfigSubscription& rds_subscription); @@ -190,7 +190,6 @@ class ScopedRdsConfigSubscription : public Envoy::Config::DeltaConfigSubscriptio ProtobufMessage::ValidationVisitor& validation_visitor_; const std::string stat_prefix_; RouteConfigProviderManager& route_config_provider_manager_; - envoy::config::core::v3alpha::ConfigSource::XdsApiVersion xds_api_version_; }; using ScopedRdsConfigSubscriptionSharedPtr = std::shared_ptr; diff --git a/source/common/router/vhds.cc b/source/common/router/vhds.cc index 31adde7b33cf8..fdd6f042c018e 100644 --- a/source/common/router/vhds.cc +++ b/source/common/router/vhds.cc @@ -20,18 +20,18 @@ namespace Envoy { namespace Router { // Implements callbacks to handle DeltaDiscovery protocol for VirtualHostDiscoveryService -VhdsSubscription::VhdsSubscription( - RouteConfigUpdatePtr& config_update_info, - Server::Configuration::ServerFactoryContext& factory_context, const std::string& stat_prefix, - std::unordered_set& route_config_providers, - envoy::config::core::v3alpha::ConfigSource::XdsApiVersion xds_api_version) +VhdsSubscription::VhdsSubscription(RouteConfigUpdatePtr& config_update_info, + Server::Configuration::ServerFactoryContext& factory_context, + const std::string& stat_prefix, + std::unordered_set& route_config_providers, + envoy::config::core::v3alpha::ApiVersion resource_api_version) : config_update_info_(config_update_info), scope_(factory_context.scope().createScope(stat_prefix + "vhds." + config_update_info_->routeConfigName() + ".")), stats_({ALL_VHDS_STATS(POOL_COUNTER(*scope_))}), init_target_(fmt::format("VhdsConfigSubscription {}", config_update_info_->routeConfigName()), [this]() { subscription_->start({}); }), - route_config_providers_(route_config_providers), xds_api_version_(xds_api_version) { + route_config_providers_(route_config_providers) { const auto& config_source = config_update_info_->routeConfiguration() .vhds() .config_source() @@ -43,8 +43,8 @@ VhdsSubscription::VhdsSubscription( subscription_ = factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource( - config_update_info_->routeConfiguration().vhds().config_source(), loadTypeUrl(), *scope_, - *this); + config_update_info_->routeConfiguration().vhds().config_source(), + loadTypeUrl(resource_api_version), *scope_, *this); } void VhdsSubscription::onConfigUpdateFailed(Envoy::Config::ConfigUpdateFailureReason reason, @@ -71,18 +71,19 @@ void VhdsSubscription::onConfigUpdate( init_target_.ready(); } -std::string VhdsSubscription::loadTypeUrl() { - switch (xds_api_version_) { +std::string +VhdsSubscription::loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version) { + switch (resource_api_version) { // automatically set api version as V2 - case envoy::config::core::v3alpha::ConfigSource::AUTO: - case envoy::config::core::v3alpha::ConfigSource::V2: + case envoy::config::core::v3alpha::ApiVersion::AUTO: + case envoy::config::core::v3alpha::ApiVersion::V2: return Grpc::Common::typeUrl( API_NO_BOOST(envoy::api::v2::route::VirtualHost().GetDescriptor()->full_name())); - case envoy::config::core::v3alpha::ConfigSource::V3ALPHA: + case envoy::config::core::v3alpha::ApiVersion::V3ALPHA: return Grpc::Common::typeUrl( API_NO_BOOST(envoy::api::v2::route::VirtualHost().GetDescriptor()->full_name())); default: - throw EnvoyException(fmt::format("type {} is not supported", xds_api_version_)); + NOT_REACHED_GCOVR_EXCL_LINE; } } } // namespace Router diff --git a/source/common/router/vhds.h b/source/common/router/vhds.h index 1c34a02dca2b2..5f1f9d466b4a4 100644 --- a/source/common/router/vhds.h +++ b/source/common/router/vhds.h @@ -41,8 +41,8 @@ class VhdsSubscription : Envoy::Config::SubscriptionCallbacks, Server::Configuration::ServerFactoryContext& factory_context, const std::string& stat_prefix, std::unordered_set& route_config_providers, - const envoy::config::core::v3alpha::ConfigSource::XdsApiVersion xds_api_version = - envoy::config::core::v3alpha::ConfigSource::AUTO); + const envoy::config::core::v3alpha::ApiVersion resource_api_version = + envoy::config::core::v3alpha::ApiVersion::AUTO); ~VhdsSubscription() override { init_target_.ready(); } void registerInitTargetWithInitManager(Init::Manager& m) { m.add(init_target_); } @@ -61,7 +61,7 @@ class VhdsSubscription : Envoy::Config::SubscriptionCallbacks, std::string resourceName(const ProtobufWkt::Any& resource) override { return MessageUtil::anyConvert(resource).name(); } - std::string loadTypeUrl(); + static std::string loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version); RouteConfigUpdatePtr& config_update_info_; Stats::ScopePtr scope_; @@ -69,7 +69,6 @@ class VhdsSubscription : Envoy::Config::SubscriptionCallbacks, std::unique_ptr subscription_; Init::TargetImpl init_target_; std::unordered_set& route_config_providers_; - envoy::config::core::v3alpha::ConfigSource::XdsApiVersion xds_api_version_; }; using VhdsSubscriptionPtr = std::unique_ptr; diff --git a/source/common/runtime/runtime_impl.cc b/source/common/runtime/runtime_impl.cc index 93c59564d88db..66aed326f0f16 100644 --- a/source/common/runtime/runtime_impl.cc +++ b/source/common/runtime/runtime_impl.cc @@ -554,7 +554,7 @@ RtdsSubscription::RtdsSubscription( : parent_(parent), config_source_(rtds_layer.rtds_config()), store_(store), resource_name_(rtds_layer.name()), init_target_("RTDS " + resource_name_, [this]() { start(); }), - validation_visitor_(validation_visitor), xds_api_version_(config_source_.xds_api_version()) {} + validation_visitor_(validation_visitor) {} void RtdsSubscription::onConfigUpdate(const Protobuf::RepeatedPtrField& resources, const std::string&) { @@ -593,7 +593,7 @@ void RtdsSubscription::start() { // cluster manager resources are not available in the constructor when // instantiated in the server instance. subscription_ = parent_.cm_->subscriptionFactory().subscriptionFromConfigSource( - config_source_, loadTypeUrl(), store_, *this); + config_source_, loadTypeUrl(config_source_.resource_api_version()), store_, *this); subscription_->start({resource_name_}); } @@ -605,18 +605,19 @@ void RtdsSubscription::validateUpdateSize(uint32_t num_resources) { } } -std::string RtdsSubscription::loadTypeUrl() { - switch (xds_api_version_) { +std::string +RtdsSubscription::loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version) { + switch (resource_api_version) { // automatically set api version as V2 - case envoy::config::core::v3alpha::ConfigSource::AUTO: - case envoy::config::core::v3alpha::ConfigSource::V2: + case envoy::config::core::v3alpha::ApiVersion::AUTO: + case envoy::config::core::v3alpha::ApiVersion::V2: return Grpc::Common::typeUrl( API_NO_BOOST(envoy::service::discovery::v2::Runtime().GetDescriptor()->full_name())); - case envoy::config::core::v3alpha::ConfigSource::V3ALPHA: + case envoy::config::core::v3alpha::ApiVersion::V3ALPHA: return Grpc::Common::typeUrl( API_NO_BOOST(envoy::service::runtime::v3alpha::Runtime().GetDescriptor()->full_name())); default: - throw EnvoyException(fmt::format("type {} is not supported", xds_api_version_)); + NOT_REACHED_GCOVR_EXCL_LINE; } } diff --git a/source/common/runtime/runtime_impl.h b/source/common/runtime/runtime_impl.h index e6cc0a80f7457..8737793f120c1 100644 --- a/source/common/runtime/runtime_impl.h +++ b/source/common/runtime/runtime_impl.h @@ -223,7 +223,7 @@ struct RtdsSubscription : Config::SubscriptionCallbacks, Logger::Loggable; diff --git a/source/common/secret/sds_api.cc b/source/common/secret/sds_api.cc index d2031b3f6e36b..87a7b66199cc9 100644 --- a/source/common/secret/sds_api.cc +++ b/source/common/secret/sds_api.cc @@ -8,6 +8,7 @@ #include "envoy/extensions/transport_sockets/tls/v3alpha/cert.pb.validate.h" #include "envoy/service/discovery/v3alpha/discovery.pb.h" +#include "common/common/assert.h" #include "common/config/api_version.h" #include "common/config/resources.h" #include "common/protobuf/utility.h" @@ -25,8 +26,7 @@ SdsApi::SdsApi(envoy::config::core::v3alpha::ConfigSource sds_config, secret_hash_(0), clean_up_(std::move(destructor_cb)), validation_visitor_(validation_visitor), subscription_factory_(subscription_factory), time_source_(time_source), secret_data_{sds_config_name_, "uninitialized", - time_source_.systemTime()}, - xds_api_version_(sds_config_.xds_api_version()) { + time_source_.systemTime()} { // TODO(JimmyCYJ): Implement chained_init_manager, so that multiple init_manager // can be chained together to behave as one init_manager. In that way, we let // two listeners which share same SdsApi to register at separate init managers, and @@ -85,23 +85,23 @@ void SdsApi::validateUpdateSize(int num_resources) { } void SdsApi::initialize() { - subscription_ = - subscription_factory_.subscriptionFromConfigSource(sds_config_, loadTypeUrl(), stats_, *this); + subscription_ = subscription_factory_.subscriptionFromConfigSource( + sds_config_, loadTypeUrl(sds_config_.resource_api_version()), stats_, *this); subscription_->start({sds_config_name_}); } -std::string SdsApi::loadTypeUrl() { - switch (xds_api_version_) { +std::string SdsApi::loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version) { + switch (resource_api_version) { // automatically set api version as V2 - case envoy::config::core::v3alpha::ConfigSource::AUTO: - case envoy::config::core::v3alpha::ConfigSource::V2: - return Grpc::Common::typeUrl( - API_NO_BOOST(envoy::api::v2::auth::Secret().GetDescriptor()->full_name())); - case envoy::config::core::v3alpha::ConfigSource::V3ALPHA: + case envoy::config::core::v3alpha::ApiVersion::AUTO: + case envoy::config::core::v3alpha::ApiVersion::V2: return Grpc::Common::typeUrl( API_NO_BOOST(envoy::api::v2::auth::Secret().GetDescriptor()->full_name())); + case envoy::config::core::v3alpha::ApiVersion::V3ALPHA: + return Grpc::Common::typeUrl(API_NO_BOOST( + envoy::extensions::transport_sockets::tls::v3alpha::Secret().GetDescriptor()->full_name())); default: - throw EnvoyException(fmt::format("type {} is not supported", xds_api_version_)); + NOT_REACHED_GCOVR_EXCL_LINE; } } diff --git a/source/common/secret/sds_api.h b/source/common/secret/sds_api.h index 6ba44f60ada99..66be2d4664109 100644 --- a/source/common/secret/sds_api.h +++ b/source/common/secret/sds_api.h @@ -66,7 +66,7 @@ class SdsApi : public Config::SubscriptionCallbacks { resource) .name(); } - std::string loadTypeUrl(); + static std::string loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version); private: void validateUpdateSize(int num_resources); @@ -84,7 +84,6 @@ class SdsApi : public Config::SubscriptionCallbacks { Config::SubscriptionFactory& subscription_factory_; TimeSource& time_source_; SecretData secret_data_; - envoy::config::core::v3alpha::ConfigSource::XdsApiVersion xds_api_version_; }; class TlsCertificateSdsApi; diff --git a/source/common/upstream/cds_api_impl.cc b/source/common/upstream/cds_api_impl.cc index e3403eb99060b..b4bc4ac87e48f 100644 --- a/source/common/upstream/cds_api_impl.cc +++ b/source/common/upstream/cds_api_impl.cc @@ -9,6 +9,7 @@ #include "envoy/service/discovery/v3alpha/discovery.pb.h" #include "envoy/stats/scope.h" +#include "common/common/assert.h" #include "common/common/cleanup.h" #include "common/common/utility.h" #include "common/config/api_version.h" @@ -31,9 +32,9 @@ CdsApiImpl::CdsApiImpl(const envoy::config::core::v3alpha::ConfigSource& cds_con ClusterManager& cm, Stats::Scope& scope, ProtobufMessage::ValidationVisitor& validation_visitor) : cm_(cm), scope_(scope.createScope("cluster_manager.cds.")), - validation_visitor_(validation_visitor), xds_api_version_(cds_config.xds_api_version()) { - subscription_ = cm_.subscriptionFactory().subscriptionFromConfigSource(cds_config, loadTypeUrl(), - *scope_, *this); + validation_visitor_(validation_visitor) { + subscription_ = cm_.subscriptionFactory().subscriptionFromConfigSource( + cds_config, loadTypeUrl(cds_config.resource_api_version()), *scope_, *this); } void CdsApiImpl::onConfigUpdate(const Protobuf::RepeatedPtrField& resources, @@ -128,18 +129,18 @@ void CdsApiImpl::runInitializeCallbackIfAny() { } } -std::string CdsApiImpl::loadTypeUrl() { - switch (xds_api_version_) { +std::string CdsApiImpl::loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version) { + switch (resource_api_version) { // automatically set api version as V2 - case envoy::config::core::v3alpha::ConfigSource::AUTO: - case envoy::config::core::v3alpha::ConfigSource::V2: + case envoy::config::core::v3alpha::ApiVersion::AUTO: + case envoy::config::core::v3alpha::ApiVersion::V2: return Grpc::Common::typeUrl( API_NO_BOOST(envoy::api::v2::Cluster().GetDescriptor()->full_name())); - case envoy::config::core::v3alpha::ConfigSource::V3ALPHA: + case envoy::config::core::v3alpha::ApiVersion::V3ALPHA: return Grpc::Common::typeUrl( API_NO_BOOST(envoy::config::cluster::v3alpha::Cluster().GetDescriptor()->full_name())); default: - throw EnvoyException(fmt::format("type {} is not supported", xds_api_version_)); + NOT_REACHED_GCOVR_EXCL_LINE; } } diff --git a/source/common/upstream/cds_api_impl.h b/source/common/upstream/cds_api_impl.h index b0ced7adc4248..3a54e1526b195 100644 --- a/source/common/upstream/cds_api_impl.h +++ b/source/common/upstream/cds_api_impl.h @@ -49,7 +49,7 @@ class CdsApiImpl : public CdsApi, std::string resourceName(const ProtobufWkt::Any& resource) override { return MessageUtil::anyConvert(resource).name(); } - std::string loadTypeUrl(); + static std::string loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version); CdsApiImpl(const envoy::config::core::v3alpha::ConfigSource& cds_config, ClusterManager& cm, Stats::Scope& scope, ProtobufMessage::ValidationVisitor& validation_visitor); void runInitializeCallbackIfAny(); @@ -60,7 +60,6 @@ class CdsApiImpl : public CdsApi, std::function initialize_callback_; Stats::ScopePtr scope_; ProtobufMessage::ValidationVisitor& validation_visitor_; - envoy::config::core::v3alpha::ConfigSource::XdsApiVersion xds_api_version_; }; } // namespace Upstream diff --git a/source/common/upstream/cluster_manager_impl.cc b/source/common/upstream/cluster_manager_impl.cc index 9b696325c6bd7..8293d42d935a4 100644 --- a/source/common/upstream/cluster_manager_impl.cc +++ b/source/common/upstream/cluster_manager_impl.cc @@ -281,7 +281,12 @@ ClusterManagerImpl::ClusterManagerImpl( ->create(), main_thread_dispatcher, *Protobuf::DescriptorPool::generated_pool()->FindMethodByName( - "envoy.service.discovery.v2.AggregatedDiscoveryService.StreamAggregatedResources"), + dyn_resources.ads_config().transport_api_version() == + envoy::config::core::v3alpha::ApiVersion::V3ALPHA + ? "envoy.service.discovery.v3alpha.AggregatedDiscoveryService." + "StreamAggregatedResources" + : "envoy.service.discovery.v2.AggregatedDiscoveryService." + "StreamAggregatedResources"), random_, stats_, Envoy::Config::Utility::parseRateLimitSettings(dyn_resources.ads_config()), bootstrap.dynamic_resources().ads_config().set_node_on_first_message_only()); diff --git a/source/common/upstream/eds.cc b/source/common/upstream/eds.cc index 93cf9ee19a2d6..849eb177313cc 100644 --- a/source/common/upstream/eds.cc +++ b/source/common/upstream/eds.cc @@ -8,6 +8,7 @@ #include "envoy/config/endpoint/v3alpha/endpoint.pb.validate.h" #include "envoy/service/discovery/v3alpha/discovery.pb.h" +#include "common/common/assert.h" #include "common/common/utility.h" #include "common/config/api_version.h" @@ -24,8 +25,7 @@ EdsClusterImpl::EdsClusterImpl( cluster_name_(cluster.eds_cluster_config().service_name().empty() ? cluster.name() : cluster.eds_cluster_config().service_name()), - validation_visitor_(factory_context.messageValidationVisitor()), - xds_api_version_(cluster.eds_cluster_config().eds_config().xds_api_version()) { + validation_visitor_(factory_context.messageValidationVisitor()) { Event::Dispatcher& dispatcher = factory_context.dispatcher(); assignment_timeout_ = dispatcher.createTimer([this]() -> void { onAssignmentTimeout(); }); const auto& eds_config = cluster.eds_cluster_config().eds_config(); @@ -37,7 +37,8 @@ EdsClusterImpl::EdsClusterImpl( } subscription_ = factory_context.clusterManager().subscriptionFactory().subscriptionFromConfigSource( - eds_config, loadTypeUrl(), info_->statsScope(), *this); + eds_config, loadTypeUrl(cluster.eds_cluster_config().eds_config().resource_api_version()), + info_->statsScope(), *this); } void EdsClusterImpl::startPreInit() { subscription_->start({cluster_name_}); } @@ -223,18 +224,19 @@ void EdsClusterImpl::reloadHealthyHostsHelper(const HostSharedPtr& host) { } } -std::string EdsClusterImpl::loadTypeUrl() { - switch (xds_api_version_) { +std::string +EdsClusterImpl::loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version) { + switch (resource_api_version) { // automatically set api version as V2 - case envoy::config::core::v3alpha::ConfigSource::AUTO: - case envoy::config::core::v3alpha::ConfigSource::V2: + case envoy::config::core::v3alpha::ApiVersion::AUTO: + case envoy::config::core::v3alpha::ApiVersion::V2: return Grpc::Common::typeUrl( API_NO_BOOST(envoy::api::v2::ClusterLoadAssignment().GetDescriptor()->full_name())); - case envoy::config::core::v3alpha::ConfigSource::V3ALPHA: + case envoy::config::core::v3alpha::ApiVersion::V3ALPHA: return Grpc::Common::typeUrl(API_NO_BOOST( envoy::config::endpoint::v3alpha::ClusterLoadAssignment().GetDescriptor()->full_name())); default: - throw EnvoyException(fmt::format("type {} is not supported", xds_api_version_)); + NOT_REACHED_GCOVR_EXCL_LINE; } } diff --git a/source/common/upstream/eds.h b/source/common/upstream/eds.h index 8f36b090d7619..a872eaefe2b6d 100644 --- a/source/common/upstream/eds.h +++ b/source/common/upstream/eds.h @@ -46,7 +46,7 @@ class EdsClusterImpl : public BaseDynamicClusterImpl, Config::SubscriptionCallba resource) .cluster_name(); } - std::string loadTypeUrl(); + static std::string loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version); using LocalityWeightsMap = std::unordered_map; bool updateHostsPerLocality(const uint32_t priority, const uint32_t overprovisioning_factor, @@ -84,7 +84,6 @@ class EdsClusterImpl : public BaseDynamicClusterImpl, Config::SubscriptionCallba Event::TimerPtr assignment_timeout_; ProtobufMessage::ValidationVisitor& validation_visitor_; InitializePhase initialize_phase_; - envoy::config::core::v3alpha::ConfigSource::XdsApiVersion xds_api_version_; }; class EdsClusterFactory : public ClusterFactoryImplBase { diff --git a/source/server/lds_api.cc b/source/server/lds_api.cc index 462b5071ec56a..97477a00b5544 100644 --- a/source/server/lds_api.cc +++ b/source/server/lds_api.cc @@ -10,6 +10,7 @@ #include "envoy/service/discovery/v3alpha/discovery.pb.h" #include "envoy/stats/scope.h" +#include "common/common/assert.h" #include "common/common/cleanup.h" #include "common/config/api_version.h" #include "common/config/resources.h" @@ -27,9 +28,9 @@ LdsApiImpl::LdsApiImpl(const envoy::config::core::v3alpha::ConfigSource& lds_con ProtobufMessage::ValidationVisitor& validation_visitor) : listener_manager_(lm), scope_(scope.createScope("listener_manager.lds.")), cm_(cm), init_target_("LDS", [this]() { subscription_->start({}); }), - validation_visitor_(validation_visitor), xds_api_version_(lds_config.xds_api_version()) { - subscription_ = cm.subscriptionFactory().subscriptionFromConfigSource(lds_config, loadTypeUrl(), - *scope_, *this); + validation_visitor_(validation_visitor) { + subscription_ = cm.subscriptionFactory().subscriptionFromConfigSource( + lds_config, loadTypeUrl(lds_config.resource_api_version()), *scope_, *this); init_manager.add(init_target_); } @@ -132,18 +133,18 @@ void LdsApiImpl::onConfigUpdateFailed(Envoy::Config::ConfigUpdateFailureReason r init_target_.ready(); } -std::string LdsApiImpl::loadTypeUrl() { - switch (xds_api_version_) { +std::string LdsApiImpl::loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version) { + switch (resource_api_version) { // automatically set api version as V2 - case envoy::config::core::v3alpha::ConfigSource::AUTO: - case envoy::config::core::v3alpha::ConfigSource::V2: + case envoy::config::core::v3alpha::ApiVersion::AUTO: + case envoy::config::core::v3alpha::ApiVersion::V2: return Grpc::Common::typeUrl( API_NO_BOOST(envoy::api::v2::Listener().GetDescriptor()->full_name())); - case envoy::config::core::v3alpha::ConfigSource::V3ALPHA: + case envoy::config::core::v3alpha::ApiVersion::V3ALPHA: return Grpc::Common::typeUrl( API_NO_BOOST(envoy::config::listener::v3alpha::Listener().GetDescriptor()->full_name())); default: - throw EnvoyException(fmt::format("type {} is not supported", xds_api_version_)); + NOT_REACHED_GCOVR_EXCL_LINE; } } } // namespace Server diff --git a/source/server/lds_api.h b/source/server/lds_api.h index d0222e7955487..44d2e581818a7 100644 --- a/source/server/lds_api.h +++ b/source/server/lds_api.h @@ -45,7 +45,7 @@ class LdsApiImpl : public LdsApi, std::string resourceName(const ProtobufWkt::Any& resource) override { return MessageUtil::anyConvert(resource).name(); } - std::string loadTypeUrl(); + static std::string loadTypeUrl(envoy::config::core::v3alpha::ApiVersion resource_api_version); std::unique_ptr subscription_; std::string system_version_info_; @@ -54,7 +54,6 @@ class LdsApiImpl : public LdsApi, Upstream::ClusterManager& cm_; Init::TargetImpl init_target_; ProtobufMessage::ValidationVisitor& validation_visitor_; - envoy::config::core::v3alpha::ConfigSource::XdsApiVersion xds_api_version_; }; } // namespace Server diff --git a/test/common/config/delta_subscription_test_harness.h b/test/common/config/delta_subscription_test_harness.h index 8a69277d1f1e9..a21b50aad3275 100644 --- a/test/common/config/delta_subscription_test_harness.h +++ b/test/common/config/delta_subscription_test_harness.h @@ -88,8 +88,8 @@ class DeltaSubscriptionTestHarness : public SubscriptionTestHarness { const std::set& unsubscribe, const Protobuf::int32 error_code, const std::string& error_message, std::map initial_resource_versions) { - envoy::service::discovery::v3alpha::DeltaDiscoveryRequest expected_request; - expected_request.mutable_node()->CopyFrom(node_); + API_NO_BOOST(envoy::api::v2::DeltaDiscoveryRequest) expected_request; + expected_request.mutable_node()->CopyFrom(API_DOWNGRADE(node_)); std::copy( subscribe.begin(), subscribe.end(), Protobuf::RepeatedFieldBackInserter(expected_request.mutable_resource_names_subscribe())); @@ -115,7 +115,7 @@ class DeltaSubscriptionTestHarness : public SubscriptionTestHarness { sendMessageRaw_( Grpc::ProtoBufferEqIgnoringField(expected_request, "response_nonce"), false)) .WillOnce([this](Buffer::InstancePtr& buffer, bool) { - envoy::service::discovery::v3alpha::DeltaDiscoveryRequest message; + API_NO_BOOST(envoy::api::v2::DeltaDiscoveryRequest) message; EXPECT_TRUE(Grpc::Common::parseBufferInstance(std::move(buffer), message)); const std::string nonce = message.response_nonce(); if (!nonce.empty()) { diff --git a/test/common/config/http_subscription_test_harness.h b/test/common/config/http_subscription_test_harness.h index 7796664edc728..cc76247ce8e8c 100644 --- a/test/common/config/http_subscription_test_harness.h +++ b/test/common/config/http_subscription_test_harness.h @@ -49,8 +49,9 @@ class HttpSubscriptionTestHarness : public SubscriptionTestHarness { })); subscription_ = std::make_unique( local_info_, cm_, "eds_cluster", dispatcher_, random_gen_, std::chrono::milliseconds(1), - std::chrono::milliseconds(1000), *method_descriptor_, callbacks_, stats_, - init_fetch_timeout, validation_visitor_); + std::chrono::milliseconds(1000), *method_descriptor_, + Config::TypeUrl::get().ClusterLoadAssignment, callbacks_, stats_, init_fetch_timeout, + validation_visitor_); } ~HttpSubscriptionTestHarness() override { @@ -92,6 +93,8 @@ class HttpSubscriptionTestHarness : public SubscriptionTestHarness { } expected_request += "\"resource_names\":[\"" + joined_cluster_names + "\"]"; } + expected_request += + ",\"type_url\":\"type.googleapis.com/envoy.api.v2.ClusterLoadAssignment\""; expected_request += "}"; EXPECT_EQ(expected_request, request->bodyAsString()); EXPECT_EQ(fmt::format_int(expected_request.size()).str(), diff --git a/test/integration/BUILD b/test/integration/BUILD index 850dc0d0bbe09..462771c71184b 100644 --- a/test/integration/BUILD +++ b/test/integration/BUILD @@ -64,6 +64,15 @@ envoy_cc_test( ], ) +envoy_cc_test( + name = "api_version_integration_test", + srcs = ["api_version_integration_test.cc"], + deps = [ + ":http_integration_lib", + "@envoy_api//envoy/api/v2/core:pkg_cc_proto", + ], +) + py_binary( name = "capture_fuzz_gen", srcs = ["capture_fuzz_gen.py"], diff --git a/test/integration/README.md b/test/integration/README.md index f7577409ca569..bd5283ee1c84c 100644 --- a/test/integration/README.md +++ b/test/integration/README.md @@ -79,7 +79,7 @@ config_helper_.addConfigModifier([&](envoy::config::bootstrap::v2::Bootstrap& bo An example of modifying `HttpConnectionManager` to change Envoy’s HTTP/1.1 processing: ```c++ -config_helper_.addConfigModifier([&](envoy::config::filter::network::http_connection_manager::v2::HttpConnectionManager& hcm) -> void { +config_helper_.addConfigModifier([&](envoy::extensions::filters::network::http_connection_manager::v3alpha::HttpConnectionManager& hcm) -> void { envoy::api::v2::core::Http1ProtocolOptions options; options.mutable_allow_absolute_url()->set_value(true); hcm.mutable_http_protocol_options()->CopyFrom(options); diff --git a/test/integration/api_version_integration_test.cc b/test/integration/api_version_integration_test.cc new file mode 100644 index 0000000000000..ecb0f9126b8d1 --- /dev/null +++ b/test/integration/api_version_integration_test.cc @@ -0,0 +1,406 @@ +#include "envoy/api/v2/core/config_source.pb.h" + +#include "common/common/assert.h" + +#include "test/integration/http_integration.h" + +namespace Envoy { +namespace { + +using Params = + std::tuple; + +class ApiVersionIntegrationTest : public testing::TestWithParam, + public HttpIntegrationTest { +public: + ApiVersionIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP2, ipVersion()) { + use_lds_ = false; + create_xds_upstream_ = true; + tls_xds_upstream_ = false; + defer_listener_finalization_ = true; + skipPortUsageValidation(); + } + + static std::string paramsToString(const testing::TestParamInfo& p) { + return fmt::format( + "{}_{}_{}_Resource_{}_Transport_{}", + std::get<0>(p.param) == Network::Address::IpVersion::v4 ? "IPv4" : "IPv6", + std::get<1>(p.param) ? "ADS" : "SingletonXds", + envoy::config::core::v3alpha::ApiConfigSource::ApiType_Name(std::get<2>(p.param)), + envoy::config::core::v3alpha::ApiVersion_Name(std::get<3>(p.param)), + envoy::config::core::v3alpha::ApiVersion_Name(std::get<4>(p.param))); + } + + Network::Address::IpVersion ipVersion() const { return std::get<0>(GetParam()); } + bool ads() const { return std::get<1>(GetParam()); } + envoy::config::core::v3alpha::ApiConfigSource::ApiType apiType() const { + return std::get<2>(GetParam()); + } + envoy::config::core::v3alpha::ApiVersion resourceApiVersion() const { + return std::get<3>(GetParam()); + } + envoy::config::core::v3alpha::ApiVersion transportApiVersion() const { + return std::get<4>(GetParam()); + } + + void initialize() override { + config_helper_.addConfigModifier( + [this](envoy::config::bootstrap::v3alpha::Bootstrap& bootstrap) { + auto* xds_cluster = bootstrap.mutable_static_resources()->add_clusters(); + xds_cluster->MergeFrom(bootstrap.static_resources().clusters()[0]); + xds_cluster->set_name("xds_cluster"); + xds_cluster->mutable_http2_protocol_options(); + if (ads()) { + auto* api_config_source = bootstrap.mutable_dynamic_resources()->mutable_ads_config(); + api_config_source->set_transport_api_version(transportApiVersion()); + api_config_source->set_api_type(apiType()); + auto* grpc_service = api_config_source->add_grpc_services(); + grpc_service->mutable_envoy_grpc()->set_cluster_name("xds_cluster"); + } + }); + setUpstreamProtocol(FakeHttpConnection::Type::HTTP2); + HttpIntegrationTest::initialize(); + if (xds_stream_ == nullptr) { + createXdsConnection(); + AssertionResult result = xds_connection_->waitForNewStream(*dispatcher_, xds_stream_); + RELEASE_ASSERT(result, result.message()); + result = xds_stream_->waitForHeadersComplete(); + RELEASE_ASSERT(result, result.message()); + endpoint_ = std::string(xds_stream_->headers().Path()->value().getStringView()); + ENVOY_LOG_MISC(debug, "xDS endpoint {}", endpoint_); + } + } + + void setupConfigSource(envoy::config::core::v3alpha::ConfigSource& config_source) { + config_source.set_resource_api_version(resourceApiVersion()); + if (ads()) { + config_source.mutable_ads(); + return; + } + auto* api_config_source = config_source.mutable_api_config_source(); + api_config_source->set_transport_api_version(transportApiVersion()); + api_config_source->set_api_type(apiType()); + if (apiType() == envoy::config::core::v3alpha::ApiConfigSource::REST) { + api_config_source->add_cluster_names("xds_cluster"); + api_config_source->mutable_refresh_delay()->set_seconds(1); + } else { + auto* grpc_service = api_config_source->add_grpc_services(); + grpc_service->mutable_envoy_grpc()->set_cluster_name("xds_cluster"); + } + } + + AssertionResult validateDiscoveryRequest(const std::string& expected_v2_sotw_endpoint, + const std::string& expected_v2_delta_endpoint, + const std::string& expected_v2_rest_endpoint, + const std::string& expected_v3alpha_sotw_endpoint, + const std::string& expected_v3alpha_delta_endpoint, + const std::string& expected_v3alpha_rest_endpoint, + const std::string& expected_v2_type_url, + const std::string& expected_v3alpha_type_url) { + // Only with ADS do we allow mixed transport/resource versions. + if (!ads() && resourceApiVersion() != transportApiVersion()) { + return AssertionSuccess(); + } + std::string expected_endpoint; + std::string expected_type_url; + std::string actual_type_url; + const char ads_v2_sotw_endpoint[] = + "/envoy.service.discovery.v2.AggregatedDiscoveryService/StreamAggregatedResources"; + const char ads_v3alpha_delta_endpoint[] = + "/envoy.service.discovery.v3alpha.AggregatedDiscoveryService/StreamAggregatedResources"; + switch (transportApiVersion()) { + case envoy::config::core::v3alpha::ApiVersion::AUTO: + case envoy::config::core::v3alpha::ApiVersion::V2: { + switch (apiType()) { + case envoy::config::core::v3alpha::ApiConfigSource::GRPC: { + API_NO_BOOST(envoy::api::v2::DiscoveryRequest) discovery_request; + VERIFY_ASSERTION(xds_stream_->waitForGrpcMessage(*dispatcher_, discovery_request)); + xds_stream_->startGrpcStream(); + actual_type_url = discovery_request.type_url(); + expected_endpoint = ads() ? ads_v2_sotw_endpoint : expected_v2_sotw_endpoint; + break; + } + case envoy::config::core::v3alpha::ApiConfigSource::DELTA_GRPC: { + API_NO_BOOST(envoy::api::v2::DeltaDiscoveryRequest) delta_discovery_request; + VERIFY_ASSERTION(xds_stream_->waitForGrpcMessage(*dispatcher_, delta_discovery_request)); + xds_stream_->startGrpcStream(); + actual_type_url = delta_discovery_request.type_url(); + expected_endpoint = expected_v2_delta_endpoint; + break; + } + case envoy::config::core::v3alpha::ApiConfigSource::REST: { + API_NO_BOOST(envoy::api::v2::DiscoveryRequest) discovery_request; + VERIFY_ASSERTION(xds_stream_->waitForEndStream(*dispatcher_)); + MessageUtil::loadFromJson(xds_stream_->body().toString(), discovery_request, + ProtobufMessage::getStrictValidationVisitor()); + actual_type_url = discovery_request.type_url(); + expected_endpoint = expected_v2_rest_endpoint; + break; + } + default: + NOT_REACHED_GCOVR_EXCL_LINE; + break; + } + break; + } + case envoy::config::core::v3alpha::ApiVersion::V3ALPHA: { + switch (apiType()) { + case envoy::config::core::v3alpha::ApiConfigSource::GRPC: { + API_NO_BOOST(envoy::api::v2::DiscoveryRequest) discovery_request; + VERIFY_ASSERTION(xds_stream_->waitForGrpcMessage(*dispatcher_, discovery_request)); + actual_type_url = discovery_request.type_url(); + expected_endpoint = ads() ? ads_v3alpha_delta_endpoint : expected_v3alpha_sotw_endpoint; + break; + } + case envoy::config::core::v3alpha::ApiConfigSource::DELTA_GRPC: { + API_NO_BOOST(envoy::api::v2::DeltaDiscoveryRequest) delta_discovery_request; + VERIFY_ASSERTION(xds_stream_->waitForGrpcMessage(*dispatcher_, delta_discovery_request)); + actual_type_url = delta_discovery_request.type_url(); + expected_endpoint = expected_v3alpha_delta_endpoint; + break; + } + case envoy::config::core::v3alpha::ApiConfigSource::REST: { + API_NO_BOOST(envoy::api::v2::DiscoveryRequest) discovery_request; + VERIFY_ASSERTION(xds_stream_->waitForEndStream(*dispatcher_)); + MessageUtil::loadFromJson(xds_stream_->body().toString(), discovery_request, + ProtobufMessage::getStrictValidationVisitor()); + actual_type_url = discovery_request.type_url(); + expected_endpoint = expected_v3alpha_rest_endpoint; + break; + } + default: + NOT_REACHED_GCOVR_EXCL_LINE; + break; + } + break; + } + default: + NOT_REACHED_GCOVR_EXCL_LINE; + } + switch (resourceApiVersion()) { + case envoy::config::core::v3alpha::ApiVersion::AUTO: + case envoy::config::core::v3alpha::ApiVersion::V2: + expected_type_url = expected_v2_type_url; + break; + case envoy::config::core::v3alpha::ApiVersion::V3ALPHA: + expected_type_url = expected_v3alpha_type_url; + break; + default: + NOT_REACHED_GCOVR_EXCL_LINE; + } + if (endpoint_ != expected_endpoint) { + return AssertionFailure() << "Expected endpoint " << expected_endpoint << ", got " + << endpoint_; + } + if (expected_type_url != actual_type_url) { + return AssertionFailure() << "Expected type URL " << expected_type_url << ", got " + << actual_type_url; + } + return AssertionSuccess(); + } + + void TearDown() override { + if (xds_stream_ != nullptr) { + cleanUpXdsConnection(); + } + test_server_.reset(); + fake_upstreams_.clear(); + } + + std::string endpoint_; +}; + +// We manage the permutations below to reduce combinatorial explosion: +// - We only care about testing on one IP version, there should be no +// material difference between v4/v6. +// - We do care about all the different ApiConfigSource variations. +// - We explicitly give the AUTO versions their own independent test suite, +// since they are equivalent to v2, so we want to test them once but they are +// mostly redundant. +// - We treat ADS and singleton xDS differently. ADS doesn't care about REST and +// doesn't currently support delta xDS. +INSTANTIATE_TEST_SUITE_P( + SingletonApiConfigSourcesExplicitApiVersions, ApiVersionIntegrationTest, + testing::Combine(testing::Values(TestEnvironment::getIpVersionsForTest()[0]), + testing::Values(false), + testing::Values(envoy::config::core::v3alpha::ApiConfigSource::REST, + envoy::config::core::v3alpha::ApiConfigSource::GRPC, + envoy::config::core::v3alpha::ApiConfigSource::DELTA_GRPC), + testing::Values(envoy::config::core::v3alpha::ApiVersion::V2, + envoy::config::core::v3alpha::ApiVersion::V3ALPHA), + testing::Values(envoy::config::core::v3alpha::ApiVersion::V2, + envoy::config::core::v3alpha::ApiVersion::V3ALPHA)), + ApiVersionIntegrationTest::paramsToString); + +INSTANTIATE_TEST_SUITE_P( + SingletonApiConfigSourcesAutoApiVersions, ApiVersionIntegrationTest, + testing::Combine(testing::Values(TestEnvironment::getIpVersionsForTest()[0]), + testing::Values(false), + testing::Values(envoy::config::core::v3alpha::ApiConfigSource::REST, + envoy::config::core::v3alpha::ApiConfigSource::GRPC, + envoy::config::core::v3alpha::ApiConfigSource::DELTA_GRPC), + testing::Values(envoy::config::core::v3alpha::ApiVersion::AUTO), + testing::Values(envoy::config::core::v3alpha::ApiVersion::AUTO)), + ApiVersionIntegrationTest::paramsToString); + +INSTANTIATE_TEST_SUITE_P( + AdsApiConfigSourcesExplicitApiVersions, ApiVersionIntegrationTest, + testing::Combine(testing::Values(TestEnvironment::getIpVersionsForTest()[0]), + testing::Values(true), + testing::Values(envoy::config::core::v3alpha::ApiConfigSource::GRPC), + testing::Values(envoy::config::core::v3alpha::ApiVersion::V2, + envoy::config::core::v3alpha::ApiVersion::V3ALPHA), + testing::Values(envoy::config::core::v3alpha::ApiVersion::V2, + envoy::config::core::v3alpha::ApiVersion::V3ALPHA)), + ApiVersionIntegrationTest::paramsToString); + +TEST_P(ApiVersionIntegrationTest, Lds) { + config_helper_.addConfigModifier([this](envoy::config::bootstrap::v3alpha::Bootstrap& bootstrap) { + setupConfigSource(*bootstrap.mutable_dynamic_resources()->mutable_lds_config()); + }); + initialize(); + ASSERT_TRUE(validateDiscoveryRequest( + "/envoy.api.v2.ListenerDiscoveryService/StreamListeners", + "/envoy.api.v2.ListenerDiscoveryService/DeltaListeners", "/v2/discovery:listeners", + "/envoy.service.listener.v3alpha.ListenerDiscoveryService/StreamListeners", + "/envoy.service.listener.v3alpha.ListenerDiscoveryService/DeltaListeners", + "/v3alpha/discovery:listeners", "type.googleapis.com/envoy.api.v2.Listener", + "type.googleapis.com/envoy.config.listener.v3alpha.Listener")); +} + +TEST_P(ApiVersionIntegrationTest, Cds) { + config_helper_.addConfigModifier([this](envoy::config::bootstrap::v3alpha::Bootstrap& bootstrap) { + setupConfigSource(*bootstrap.mutable_dynamic_resources()->mutable_cds_config()); + }); + initialize(); + ASSERT_TRUE(validateDiscoveryRequest( + "/envoy.api.v2.ClusterDiscoveryService/StreamClusters", + "/envoy.api.v2.ClusterDiscoveryService/DeltaClusters", "/v2/discovery:clusters", + "/envoy.service.cluster.v3alpha.ClusterDiscoveryService/StreamClusters", + "/envoy.service.cluster.v3alpha.ClusterDiscoveryService/DeltaClusters", + "/v3alpha/discovery:clusters", "type.googleapis.com/envoy.api.v2.Cluster", + "type.googleapis.com/envoy.config.cluster.v3alpha.Cluster")); +} + +TEST_P(ApiVersionIntegrationTest, Eds) { + config_helper_.addConfigModifier([this](envoy::config::bootstrap::v3alpha::Bootstrap& bootstrap) { + auto* cluster = bootstrap.mutable_static_resources()->add_clusters(); + cluster->MergeFrom(bootstrap.static_resources().clusters(0)); + cluster->set_name("some_cluster"); + cluster->set_type(envoy::config::cluster::v3alpha::Cluster::EDS); + setupConfigSource(*cluster->mutable_eds_cluster_config()->mutable_eds_config()); + }); + initialize(); + ASSERT_TRUE(validateDiscoveryRequest( + "/envoy.api.v2.EndpointDiscoveryService/StreamEndpoints", + "/envoy.api.v2.EndpointDiscoveryService/DeltaEndpoints", "/v2/discovery:endpoints", + "/envoy.service.endpoint.v3alpha.EndpointDiscoveryService/StreamEndpoints", + "/envoy.service.endpoint.v3alpha.EndpointDiscoveryService/DeltaEndpoints", + "/v3alpha/discovery:endpoints", "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment", + "type.googleapis.com/envoy.config.endpoint.v3alpha.ClusterLoadAssignment")); +} + +TEST_P(ApiVersionIntegrationTest, Rtds) { + config_helper_.addConfigModifier([this](envoy::config::bootstrap::v3alpha::Bootstrap& bootstrap) { + auto* admin_layer = bootstrap.mutable_layered_runtime()->add_layers(); + admin_layer->set_name("admin layer"); + admin_layer->mutable_admin_layer(); + auto* rtds_layer = bootstrap.mutable_layered_runtime()->add_layers(); + rtds_layer->set_name("rtds_layer"); + setupConfigSource(*rtds_layer->mutable_rtds_layer()->mutable_rtds_config()); + }); + initialize(); + ASSERT_TRUE(validateDiscoveryRequest( + "/envoy.service.discovery.v2.RuntimeDiscoveryService/StreamRuntime", + "/envoy.service.discovery.v2.RuntimeDiscoveryService/DeltaRuntime", "/v2/discovery:runtime", + "/envoy.service.runtime.v3alpha.RuntimeDiscoveryService/StreamRuntime", + "/envoy.service.runtime.v3alpha.RuntimeDiscoveryService/DeltaRuntime", + "/v3alpha/discovery:runtime", "type.googleapis.com/envoy.service.discovery.v2.Runtime", + "type.googleapis.com/envoy.service.runtime.v3alpha.Runtime")); +} + +TEST_P(ApiVersionIntegrationTest, Rds) { + // TODO(htuch): this segfaults, this is likely some untested existing issue. + if (apiType() == envoy::config::core::v3alpha::ApiConfigSource::DELTA_GRPC) { + return; + } + config_helper_.addConfigModifier( + [this](envoy::extensions::filters::network::http_connection_manager::v3alpha:: + HttpConnectionManager& http_connection_manager) { + auto* rds = http_connection_manager.mutable_rds(); + rds->set_route_config_name("rds"); + setupConfigSource(*rds->mutable_config_source()); + }); + initialize(); + ASSERT_TRUE(validateDiscoveryRequest( + "/envoy.api.v2.RouteDiscoveryService/StreamRoutes", + "/envoy.api.v2.RouteDiscoveryService/DeltaRoutes", "/v2/discovery:routes", + "/envoy.service.route.v3alpha.RouteDiscoveryService/StreamRoutes", + "/envoy.service.route.v3alpha.RouteDiscoveryService/DeltaRoutes", "/v3alpha/discovery:routes", + "type.googleapis.com/envoy.api.v2.RouteConfiguration", + "type.googleapis.com/envoy.config.route.v3alpha.RouteConfiguration")); +} + +// TODO(htuch): add VHDS tests once VHDS lands. +// TEST_P(ApiVersionIntegrationTest, Vhds) { +// } + +TEST_P(ApiVersionIntegrationTest, Srds) { + config_helper_.addConfigModifier( + [this](envoy::extensions::filters::network::http_connection_manager::v3alpha:: + HttpConnectionManager& http_connection_manager) { + auto* scoped_routes = http_connection_manager.mutable_scoped_routes(); + scoped_routes->set_name("scoped_routes"); + const std::string& scope_key_builder_config_yaml = R"EOF( +fragments: + - header_value_extractor: + name: Addr + element_separator: ; + element: + key: x-foo-key + separator: = +)EOF"; + envoy::extensions::filters::network::http_connection_manager::v3alpha::ScopedRoutes:: + ScopeKeyBuilder scope_key_builder; + TestUtility::loadFromYaml(scope_key_builder_config_yaml, + *scoped_routes->mutable_scope_key_builder()); + setupConfigSource(*scoped_routes->mutable_scoped_rds()->mutable_scoped_rds_config_source()); + setupConfigSource(*scoped_routes->mutable_rds_config_source()); + }); + initialize(); + ASSERT_TRUE(validateDiscoveryRequest( + "/envoy.api.v2.ScopedRoutesDiscoveryService/StreamScopedRoutes", + "/envoy.api.v2.ScopedRoutesDiscoveryService/DeltaScopedRoutes", "/v2/discovery:scoped-routes", + "/envoy.service.route.v3alpha.ScopedRoutesDiscoveryService/StreamScopedRoutes", + "/envoy.service.route.v3alpha.ScopedRoutesDiscoveryService/DeltaScopedRoutes", + "/v3alpha/discovery:scoped-routes", + "type.googleapis.com/envoy.api.v2.ScopedRouteConfiguration", + "type.googleapis.com/envoy.config.route.v3alpha.ScopedRouteConfiguration")); +} + +TEST_P(ApiVersionIntegrationTest, Sds) { + config_helper_.addConfigModifier([this](envoy::config::bootstrap::v3alpha::Bootstrap& bootstrap) { + auto* listener = bootstrap.mutable_static_resources()->mutable_listeners(0); + auto* transport_socket = listener->mutable_filter_chains(0)->mutable_transport_socket(); + envoy::extensions::transport_sockets::tls::v3alpha::DownstreamTlsContext tls_context; + auto* common_tls_context = tls_context.mutable_common_tls_context(); + auto* secret_config = common_tls_context->add_tls_certificate_sds_secret_configs(); + secret_config->set_name("sds"); + setupConfigSource(*secret_config->mutable_sds_config()); + transport_socket->set_name("envoy.transport_sockets.tls"); + transport_socket->mutable_typed_config()->PackFrom(tls_context); + }); + initialize(); + ASSERT_TRUE(validateDiscoveryRequest( + "/envoy.service.discovery.v2.SecretDiscoveryService/StreamSecrets", + "/envoy.service.discovery.v2.SecretDiscoveryService/DeltaSecrets", "/v2/discovery:secrets", + "/envoy.service.secret.v3alpha.SecretDiscoveryService/StreamSecrets", + "/envoy.service.secret.v3alpha.SecretDiscoveryService/DeltaSecrets", + "/v3alpha/discovery:secrets", "type.googleapis.com/envoy.api.v2.auth.Secret", + "type.googleapis.com/envoy.extensions.transport_sockets.tls.v3alpha.Secret")); +} + +} // namespace +} // namespace Envoy diff --git a/test/integration/cds_integration_test.cc b/test/integration/cds_integration_test.cc index 54418e70e1701..e9bb18187f7ed 100644 --- a/test/integration/cds_integration_test.cc +++ b/test/integration/cds_integration_test.cc @@ -248,7 +248,7 @@ TEST_P(CdsIntegrationTest, VersionsRememberedAfterReconnect) { acceptXdsConnection(); // Upon reconnecting, the Envoy should tell us its current resource versions. - envoy::service::discovery::v3alpha::DeltaDiscoveryRequest request; + API_NO_BOOST(envoy::api::v2::DeltaDiscoveryRequest) request; result = xds_stream_->waitForGrpcMessage(*dispatcher_, request); RELEASE_ASSERT(result, result.message()); const auto& initial_resource_versions = request.initial_resource_versions(); diff --git a/test/integration/load_stats_integration_test.cc b/test/integration/load_stats_integration_test.cc index e6036077511f4..94e107d711e40 100644 --- a/test/integration/load_stats_integration_test.cc +++ b/test/integration/load_stats_integration_test.cc @@ -270,9 +270,6 @@ class LoadStatsIntegrationTest : public testing::TestWithParamClear(); } mergeLoadStats(loadstats_request, local_loadstats_request); - if (!loadstats_request.cluster_stats().empty()) { - ENVOY_LOG_MISC(debug, "HTD {}", loadstats_request.cluster_stats()[0].DebugString()); - } EXPECT_EQ("POST", loadstats_stream_->headers().Method()->value().getStringView()); EXPECT_EQ("/envoy.service.load_stats.v2.LoadReportingService/StreamLoadStats",