diff --git a/include/envoy/config/grpc_mux.h b/include/envoy/config/grpc_mux.h index 620b217b2216f..57befc93e01ca 100644 --- a/include/envoy/config/grpc_mux.h +++ b/include/envoy/config/grpc_mux.h @@ -105,9 +105,6 @@ class GrpcMux { virtual void requestOnDemandUpdate(const std::string& type_url, const absl::flat_hash_set& for_update) PURE; - - using TypeUrlMap = absl::flat_hash_map; - static TypeUrlMap& typeUrlMap() { MUTABLE_CONSTRUCT_ON_FIRST_USE(TypeUrlMap, {}); } }; using GrpcMuxPtr = std::unique_ptr; diff --git a/source/common/config/BUILD b/source/common/config/BUILD index de123c9f86c5b..e5e73d9e9d4da 100644 --- a/source/common/config/BUILD +++ b/source/common/config/BUILD @@ -14,7 +14,6 @@ envoy_cc_library( hdrs = ["api_type_oracle.h"], deps = [ "//source/common/protobuf", - "//source/common/protobuf:type_util_lib", "@com_github_cncf_udpa//udpa/annotations:pkg_cc_proto", ], ) diff --git a/source/common/config/api_type_oracle.cc b/source/common/config/api_type_oracle.cc index f6feba09828a1..8762392af5cbd 100644 --- a/source/common/config/api_type_oracle.cc +++ b/source/common/config/api_type_oracle.cc @@ -32,14 +32,5 @@ ApiTypeOracle::getEarlierVersionMessageTypeName(const std::string& message_type) return absl::nullopt; } -const absl::optional ApiTypeOracle::getEarlierTypeUrl(const std::string& type_url) { - const std::string type{TypeUtil::typeUrlToDescriptorFullName(type_url)}; - absl::optional old_type = ApiTypeOracle::getEarlierVersionMessageTypeName(type); - if (old_type.has_value()) { - return TypeUtil::descriptorFullNameToTypeUrl(old_type.value()); - } - return {}; -} - } // namespace Config } // namespace Envoy diff --git a/source/common/config/api_type_oracle.h b/source/common/config/api_type_oracle.h index ab5e75b113d78..bde8186fa555c 100644 --- a/source/common/config/api_type_oracle.h +++ b/source/common/config/api_type_oracle.h @@ -1,7 +1,6 @@ #pragma once #include "common/protobuf/protobuf.h" -#include "common/protobuf/type_util.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" @@ -24,8 +23,6 @@ class ApiTypeOracle { static const absl::optional getEarlierVersionMessageTypeName(const std::string& message_type); - - static const absl::optional getEarlierTypeUrl(const std::string& type_url); }; } // namespace Config diff --git a/source/common/config/grpc_mux_impl.cc b/source/common/config/grpc_mux_impl.cc index 66352fe9a0a20..eab59e846bdac 100644 --- a/source/common/config/grpc_mux_impl.cc +++ b/source/common/config/grpc_mux_impl.cc @@ -25,8 +25,6 @@ GrpcMuxImpl::GrpcMuxImpl(const LocalInfo::LocalInfo& local_info, local_info_(local_info), skip_subsequent_node_(skip_subsequent_node), first_stream_request_(true), transport_api_version_(transport_api_version), dispatcher_(dispatcher), - enable_type_url_downgrade_and_upgrade_(Runtime::runtimeFeatureEnabled( - "envoy.reloadable_features.enable_type_url_downgrade_and_upgrade")), dynamic_update_callback_handle_(local_info.contextProvider().addDynamicContextUpdateCallback( [this](absl::string_view resource_type_url) { onDynamicContextUpdate(resource_type_url); @@ -97,9 +95,6 @@ GrpcMuxWatchPtr GrpcMuxImpl::addWatch(const std::string& type_url, apiStateFor(type_url).request_.mutable_node()->MergeFrom(local_info_.node()); apiStateFor(type_url).subscribed_ = true; subscriptions_.emplace_back(type_url); - if (enable_type_url_downgrade_and_upgrade_) { - registerVersionedTypeUrl(type_url); - } } // This will send an updated request on each subscription. @@ -137,36 +132,15 @@ ScopedResume GrpcMuxImpl::pause(const std::vector type_urls) { }); } -void GrpcMuxImpl::registerVersionedTypeUrl(const std::string& type_url) { - TypeUrlMap& type_url_map = typeUrlMap(); - if (type_url_map.find(type_url) != type_url_map.end()) { - return; - } - // If type_url is v3, earlier_type_url will contain v2 type url. - const absl::optional earlier_type_url = ApiTypeOracle::getEarlierTypeUrl(type_url); - // Register v2 to v3 and v3 to v2 type_url mapping in the hash map. - if (earlier_type_url.has_value()) { - type_url_map[earlier_type_url.value()] = type_url; - type_url_map[type_url] = earlier_type_url.value(); - } -} - void GrpcMuxImpl::onDiscoveryResponse( std::unique_ptr&& message, ControlPlaneStats& control_plane_stats) { - std::string type_url = message->type_url(); + const std::string type_url = message->type_url(); ENVOY_LOG(debug, "Received gRPC message for {} at version {}", type_url, message->version_info()); if (message->has_control_plane()) { control_plane_stats.identifier_.set(message->control_plane().identifier()); } - // If this type url is not watched(no subscriber or no watcher), try another version of type url. - if (enable_type_url_downgrade_and_upgrade_ && api_state_.count(type_url) == 0) { - registerVersionedTypeUrl(type_url); - TypeUrlMap& type_url_map = typeUrlMap(); - if (type_url_map.find(type_url) != type_url_map.end()) { - type_url = type_url_map[type_url]; - } - } + if (api_state_.count(type_url) == 0) { // TODO(yuval-k): This should never happen. consider dropping the stream as this is a // protocol violation @@ -216,10 +190,10 @@ void GrpcMuxImpl::onDiscoveryResponse( for (const auto& resource : message->resources()) { // TODO(snowp): Check the underlying type when the resource is a Resource. if (!resource.Is() && - message->type_url() != resource.type_url()) { + type_url != resource.type_url()) { throw EnvoyException( fmt::format("{} does not match the message-wide type URL {} in DiscoveryResponse {}", - resource.type_url(), message->type_url(), message->DebugString())); + resource.type_url(), type_url, message->DebugString())); } auto decoded_resource = diff --git a/source/common/config/grpc_mux_impl.h b/source/common/config/grpc_mux_impl.h index 3600e78111aeb..3c4b973b8d9d1 100644 --- a/source/common/config/grpc_mux_impl.h +++ b/source/common/config/grpc_mux_impl.h @@ -21,7 +21,6 @@ #include "common/config/grpc_stream.h" #include "common/config/ttl.h" #include "common/config/utility.h" -#include "common/runtime/runtime_features.h" #include "absl/container/node_hash_map.h" @@ -62,7 +61,6 @@ class GrpcMuxImpl : public GrpcMux, // Config::GrpcStreamCallbacks void onStreamEstablished() override; void onEstablishmentFailure() override; - void registerVersionedTypeUrl(const std::string& type_url); void onDiscoveryResponse(std::unique_ptr&& message, ControlPlaneStats& control_plane_stats) override; @@ -177,7 +175,6 @@ class GrpcMuxImpl : public GrpcMux, const envoy::config::core::v3::ApiVersion transport_api_version_; Event::Dispatcher& dispatcher_; - bool enable_type_url_downgrade_and_upgrade_; Common::CallbackHandlePtr dynamic_update_callback_handle_; }; diff --git a/source/common/config/grpc_subscription_impl.cc b/source/common/config/grpc_subscription_impl.cc index 602b5df7dc91a..3b6412d111dc3 100644 --- a/source/common/config/grpc_subscription_impl.cc +++ b/source/common/config/grpc_subscription_impl.cc @@ -8,7 +8,6 @@ #include "common/config/xds_resource.h" #include "common/grpc/common.h" #include "common/protobuf/protobuf.h" -#include "common/protobuf/type_util.h" #include "common/protobuf/utility.h" namespace Envoy { diff --git a/source/common/config/new_grpc_mux_impl.cc b/source/common/config/new_grpc_mux_impl.cc index 75fb14f4c6f66..62a2ba950d155 100644 --- a/source/common/config/new_grpc_mux_impl.cc +++ b/source/common/config/new_grpc_mux_impl.cc @@ -30,9 +30,7 @@ NewGrpcMuxImpl::NewGrpcMuxImpl(Grpc::RawAsyncClientPtr&& async_client, [this](absl::string_view resource_type_url) { onDynamicContextUpdate(resource_type_url); })), - transport_api_version_(transport_api_version), dispatcher_(dispatcher), - enable_type_url_downgrade_and_upgrade_(Runtime::runtimeFeatureEnabled( - "envoy.reloadable_features.enable_type_url_downgrade_and_upgrade")) {} + transport_api_version_(transport_api_version), dispatcher_(dispatcher) {} void NewGrpcMuxImpl::onDynamicContextUpdate(absl::string_view resource_type_url) { auto sub = subscriptions_.find(resource_type_url); @@ -62,20 +60,6 @@ ScopedResume NewGrpcMuxImpl::pause(const std::vector type_urls) { }); } -void NewGrpcMuxImpl::registerVersionedTypeUrl(const std::string& type_url) { - TypeUrlMap& type_url_map = typeUrlMap(); - if (type_url_map.find(type_url) != type_url_map.end()) { - return; - } - // If type_url is v3, earlier_type_url will contain v2 type url. - absl::optional earlier_type_url = ApiTypeOracle::getEarlierTypeUrl(type_url); - // Register v2 to v3 and v3 to v2 type_url mapping in the hash map. - if (earlier_type_url.has_value()) { - type_url_map[earlier_type_url.value()] = type_url; - type_url_map[type_url] = earlier_type_url.value(); - } -} - void NewGrpcMuxImpl::onDiscoveryResponse( std::unique_ptr&& message, ControlPlaneStats& control_plane_stats) { @@ -85,15 +69,6 @@ void NewGrpcMuxImpl::onDiscoveryResponse( control_plane_stats.identifier_.set(message->control_plane().identifier()); } auto sub = subscriptions_.find(message->type_url()); - // If this type url is not watched, try another version type url. - if (enable_type_url_downgrade_and_upgrade_ && sub == subscriptions_.end()) { - const std::string& type_url = message->type_url(); - registerVersionedTypeUrl(type_url); - TypeUrlMap& type_url_map = typeUrlMap(); - if (type_url_map.find(type_url) != type_url_map.end()) { - sub = subscriptions_.find(type_url_map[type_url]); - } - } if (sub == subscriptions_.end()) { ENVOY_LOG(warn, "Dropping received DeltaDiscoveryResponse (with version {}) for non-existent " @@ -153,10 +128,6 @@ GrpcMuxWatchPtr NewGrpcMuxImpl::addWatch(const std::string& type_url, auto entry = subscriptions_.find(type_url); if (entry == subscriptions_.end()) { // We don't yet have a subscription for type_url! Make one! - if (enable_type_url_downgrade_and_upgrade_) { - registerVersionedTypeUrl(type_url); - } - // No resources implies that this is a wildcard request subscription. addSubscription(type_url, options.use_namespace_matching_, resources.empty()); return addWatch(type_url, resources, callbacks, resource_decoder, options); } diff --git a/source/common/config/new_grpc_mux_impl.h b/source/common/config/new_grpc_mux_impl.h index 71664cb30a13c..570cc7dfafc44 100644 --- a/source/common/config/new_grpc_mux_impl.h +++ b/source/common/config/new_grpc_mux_impl.h @@ -50,8 +50,6 @@ class NewGrpcMuxImpl ScopedResume pause(const std::string& type_url) override; ScopedResume pause(const std::vector type_urls) override; - void registerVersionedTypeUrl(const std::string& type_url); - void onDiscoveryResponse( std::unique_ptr&& message, ControlPlaneStats& control_plane_stats) override; @@ -171,8 +169,6 @@ class NewGrpcMuxImpl Common::CallbackHandlePtr dynamic_update_callback_handle_; const envoy::config::core::v3::ApiVersion transport_api_version_; Event::Dispatcher& dispatcher_; - - const bool enable_type_url_downgrade_and_upgrade_; }; using NewGrpcMuxImplPtr = std::unique_ptr; diff --git a/source/common/config/subscription_factory_impl.cc b/source/common/config/subscription_factory_impl.cc index cf53c93cfd53e..277a3524e7282 100644 --- a/source/common/config/subscription_factory_impl.cc +++ b/source/common/config/subscription_factory_impl.cc @@ -12,6 +12,7 @@ #include "common/config/xds_resource.h" #include "common/http/utility.h" #include "common/protobuf/protobuf.h" +#include "common/protobuf/utility.h" namespace Envoy { namespace Config { diff --git a/source/common/protobuf/BUILD b/source/common/protobuf/BUILD index 8fb417d7c5512..d8f3c67a06c95 100644 --- a/source/common/protobuf/BUILD +++ b/source/common/protobuf/BUILD @@ -61,7 +61,6 @@ envoy_cc_library( deps = [ ":message_validator_lib", ":protobuf", - ":type_util_lib", ":well_known_lib", "//include/envoy/api:api_interface", "//include/envoy/protobuf:message_validator_interface", @@ -81,16 +80,6 @@ envoy_cc_library( ], ) -envoy_cc_library( - name = "type_util_lib", - srcs = ["type_util.cc"], - hdrs = ["type_util.h"], - deps = [ - "//source/common/protobuf", - "@com_github_cncf_udpa//udpa/annotations:pkg_cc_proto", - ], -) - envoy_cc_library( name = "visitor_lib", srcs = ["visitor.cc"], diff --git a/source/common/protobuf/type_util.cc b/source/common/protobuf/type_util.cc deleted file mode 100644 index 03b5c1f01b343..0000000000000 --- a/source/common/protobuf/type_util.cc +++ /dev/null @@ -1,17 +0,0 @@ -#include "common/protobuf/type_util.h" - -namespace Envoy { - -absl::string_view TypeUtil::typeUrlToDescriptorFullName(absl::string_view type_url) { - const size_t pos = type_url.rfind('/'); - if (pos != absl::string_view::npos) { - type_url = type_url.substr(pos + 1); - } - return type_url; -} - -std::string TypeUtil::descriptorFullNameToTypeUrl(absl::string_view type) { - return "type.googleapis.com/" + std::string(type); -} - -} // namespace Envoy diff --git a/source/common/protobuf/type_util.h b/source/common/protobuf/type_util.h deleted file mode 100644 index 9bcfa0f8c2f62..0000000000000 --- a/source/common/protobuf/type_util.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "common/protobuf/protobuf.h" - -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" - -namespace Envoy { - -class TypeUtil { -public: - static absl::string_view typeUrlToDescriptorFullName(absl::string_view type_url); - - static std::string descriptorFullNameToTypeUrl(absl::string_view type); -}; - -} // namespace Envoy diff --git a/source/common/protobuf/utility.cc b/source/common/protobuf/utility.cc index 0b49ad7d92736..a194d72e2f146 100644 --- a/source/common/protobuf/utility.cc +++ b/source/common/protobuf/utility.cc @@ -1043,4 +1043,17 @@ void TimestampUtil::systemClockToTimestamp(const SystemTime system_clock_time, .time_since_epoch() .count())); } + +absl::string_view TypeUtil::typeUrlToDescriptorFullName(absl::string_view type_url) { + const size_t pos = type_url.rfind('/'); + if (pos != absl::string_view::npos) { + type_url = type_url.substr(pos + 1); + } + return type_url; +} + +std::string TypeUtil::descriptorFullNameToTypeUrl(absl::string_view type) { + return "type.googleapis.com/" + std::string(type); +} + } // namespace Envoy diff --git a/source/common/protobuf/utility.h b/source/common/protobuf/utility.h index 577a068581787..0b08d49458b9f 100644 --- a/source/common/protobuf/utility.h +++ b/source/common/protobuf/utility.h @@ -145,6 +145,13 @@ class MissingFieldException : public EnvoyException { MissingFieldException(const std::string& field_name, const Protobuf::Message& message); }; +class TypeUtil { +public: + static absl::string_view typeUrlToDescriptorFullName(absl::string_view type_url); + + static std::string descriptorFullNameToTypeUrl(absl::string_view type); +}; + class RepeatedPtrUtil { public: static std::string join(const Protobuf::RepeatedPtrField& source, diff --git a/source/common/runtime/runtime_features.cc b/source/common/runtime/runtime_features.cc index cbabc221f4b39..4f298ef8d4e64 100644 --- a/source/common/runtime/runtime_features.cc +++ b/source/common/runtime/runtime_features.cc @@ -105,9 +105,6 @@ constexpr const char* runtime_features[] = { constexpr const char* disabled_runtime_features[] = { // v2 is fatal-by-default. "envoy.test_only.broken_in_production.enable_deprecated_v2_api", - // Allow Envoy to upgrade or downgrade version of type url, should be removed when support for - // v2 url is removed from codebase. - "envoy.reloadable_features.enable_type_url_downgrade_and_upgrade", // TODO(alyssawilk) flip true after the release. "envoy.reloadable_features.new_tcp_connection_pool", // TODO(asraa) flip to true in a separate PR to enable the new JSON by default. diff --git a/test/common/config/api_type_oracle_test.cc b/test/common/config/api_type_oracle_test.cc index a2454953c3bb8..327d4dc32e541 100644 --- a/test/common/config/api_type_oracle_test.cc +++ b/test/common/config/api_type_oracle_test.cc @@ -27,9 +27,6 @@ TEST(ApiTypeOracleTest, All) { EXPECT_EQ(envoy::config::filter::http::ip_tagging::v2::IPTagging::descriptor()->full_name(), ApiTypeOracle::getEarlierVersionMessageTypeName(v3_config.GetDescriptor()->full_name()) .value()); - EXPECT_EQ("envoy.config.filter.http.ip_tagging.v2.IPTagging", - TypeUtil::typeUrlToDescriptorFullName( - "type.googleapis.com/envoy.config.filter.http.ip_tagging.v2.IPTagging")); } } // namespace diff --git a/test/common/config/grpc_mux_impl_test.cc b/test/common/config/grpc_mux_impl_test.cc index a3701c919fcca..8e1ac0945f698 100644 --- a/test/common/config/grpc_mux_impl_test.cc +++ b/test/common/config/grpc_mux_impl_test.cc @@ -24,7 +24,6 @@ #include "test/test_common/logging.h" #include "test/test_common/resources.h" #include "test/test_common/simulated_time_system.h" -#include "test/test_common/test_runtime.h" #include "test/test_common/test_time.h" #include "test/test_common/utility.h" @@ -870,89 +869,6 @@ TEST_F(GrpcMuxImplTest, BadLocalInfoEmptyNodeName) { "--service-node and --service-cluster options."); } -// Send discovery request with v2 resource type_url, receive discovery response with v3 resource -// type_url. -TEST_F(GrpcMuxImplTest, WatchV2ResourceV3) { - TestScopedRuntime scoped_runtime; - Runtime::LoaderSingleton::getExisting()->mergeValues( - {{"envoy.reloadable_features.enable_type_url_downgrade_and_upgrade", "true"}}); - setup(); - - InSequence s; - const std::string& v2_type_url = Config::TypeUrl::get().ClusterLoadAssignment; - const std::string& v3_type_url = - Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3); - TestUtility::TestOpaqueResourceDecoderImpl - resource_decoder("cluster_name"); - auto foo_sub = grpc_mux_->addWatch(v2_type_url, {}, callbacks_, resource_decoder, {}); - EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_)); - expectSendMessage(v2_type_url, {}, "", true); - grpc_mux_->start(); - - { - auto response = std::make_unique(); - response->set_type_url(v3_type_url); - response->set_version_info("1"); - envoy::config::endpoint::v3::ClusterLoadAssignment load_assignment; - load_assignment.set_cluster_name("x"); - response->add_resources()->PackFrom(load_assignment); - EXPECT_CALL(callbacks_, onConfigUpdate(_, "1")) - .WillOnce(Invoke([&load_assignment](const std::vector& resources, - const std::string&) { - EXPECT_EQ(1, resources.size()); - const auto& expected_assignment = - dynamic_cast( - resources[0].get().resource()); - EXPECT_TRUE(TestUtility::protoEqual(expected_assignment, load_assignment)); - })); - expectSendMessage(v2_type_url, {}, "1"); - grpc_mux_->grpcStreamForTest().onReceiveMessage(std::move(response)); - } -} - -// Send discovery request with v3 resource type_url, receive discovery response with v2 resource -// type_url. -TEST_F(GrpcMuxImplTest, WatchV3ResourceV2) { - TestScopedRuntime scoped_runtime; - Runtime::LoaderSingleton::getExisting()->mergeValues( - {{"envoy.reloadable_features.enable_type_url_downgrade_and_upgrade", "true"}}); - setup(); - - InSequence s; - const std::string& v2_type_url = Config::TypeUrl::get().ClusterLoadAssignment; - const std::string& v3_type_url = - Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3); - TestUtility::TestOpaqueResourceDecoderImpl - resource_decoder("cluster_name"); - auto foo_sub = grpc_mux_->addWatch(v3_type_url, {}, callbacks_, resource_decoder, {}); - EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_)); - expectSendMessage(v3_type_url, {}, "", true); - grpc_mux_->start(); - - { - - auto response = std::make_unique(); - response->set_type_url(v2_type_url); - response->set_version_info("1"); - envoy::config::endpoint::v3::ClusterLoadAssignment load_assignment; - load_assignment.set_cluster_name("x"); - response->add_resources()->PackFrom(load_assignment); - EXPECT_CALL(callbacks_, onConfigUpdate(_, "1")) - .WillOnce(Invoke([&load_assignment](const std::vector& resources, - const std::string&) { - EXPECT_EQ(1, resources.size()); - const auto& expected_assignment = - dynamic_cast( - resources[0].get().resource()); - EXPECT_TRUE(TestUtility::protoEqual(expected_assignment, load_assignment)); - })); - expectSendMessage(v3_type_url, {}, "1"); - grpc_mux_->grpcStreamForTest().onReceiveMessage(std::move(response)); - } -} - } // namespace } // namespace Config } // namespace Envoy diff --git a/test/common/config/new_grpc_mux_impl_test.cc b/test/common/config/new_grpc_mux_impl_test.cc index 00fb2770273a3..3240986c1075e 100644 --- a/test/common/config/new_grpc_mux_impl_test.cc +++ b/test/common/config/new_grpc_mux_impl_test.cc @@ -22,7 +22,6 @@ #include "test/test_common/logging.h" #include "test/test_common/resources.h" #include "test/test_common/simulated_time_system.h" -#include "test/test_common/test_runtime.h" #include "test/test_common/test_time.h" #include "test/test_common/utility.h" @@ -362,104 +361,6 @@ TEST_F(NewGrpcMuxImplTest, ConfigUpdateWithNotFoundResponse) { response->mutable_resources()->at(0).add_aliases("prefix/domain1.test"); } -// Watch v2 resource type_url, receive discovery response with v3 resource type_url. -TEST_F(NewGrpcMuxImplTest, V3ResourceResponseV2ResourceWatch) { - TestScopedRuntime scoped_runtime; - Runtime::LoaderSingleton::getExisting()->mergeValues( - {{"envoy.reloadable_features.enable_type_url_downgrade_and_upgrade", "true"}}); - setup(); - - // Watch for v2 resource type_url. - const std::string& v2_type_url = Config::TypeUrl::get().ClusterLoadAssignment; - const std::string& v3_type_url = - Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3); - auto watch = grpc_mux_->addWatch(v2_type_url, {}, callbacks_, resource_decoder_, {}); - - EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_)); - // Cluster is not watched, v3 resource is rejected. - grpc_mux_->start(); - { - auto unexpected_response = - std::make_unique(); - envoy::config::cluster::v3::Cluster cluster; - unexpected_response->set_type_url(Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3)); - unexpected_response->set_system_version_info("0"); - unexpected_response->add_resources()->mutable_resource()->PackFrom(cluster); - EXPECT_CALL(callbacks_, onConfigUpdate(_, _, "0")).Times(0); - grpc_mux_->onDiscoveryResponse(std::move(unexpected_response), control_plane_stats_); - } - // Cluster is not watched, v2 resource is rejected. - { - auto unexpected_response = - std::make_unique(); - envoy::config::cluster::v3::Cluster cluster; - unexpected_response->set_type_url(Config::TypeUrl::get().Cluster); - unexpected_response->set_system_version_info("0"); - unexpected_response->add_resources()->mutable_resource()->PackFrom(cluster); - EXPECT_CALL(callbacks_, onConfigUpdate(_, _, "0")).Times(0); - grpc_mux_->onDiscoveryResponse(std::move(unexpected_response), control_plane_stats_); - } - // ClusterLoadAssignment v2 is watched, v3 resource will be accepted. - { - auto response = std::make_unique(); - response->set_system_version_info("1"); - envoy::config::endpoint::v3::ClusterLoadAssignment load_assignment; - load_assignment.set_cluster_name("x"); - response->add_resources()->mutable_resource()->PackFrom(load_assignment); - // Send response that contains resource with v3 type url. - response->set_type_url(v3_type_url); - EXPECT_CALL(callbacks_, onConfigUpdate(_, _, "1")) - .WillOnce(Invoke([&load_assignment](const std::vector& added_resources, - const Protobuf::RepeatedPtrField&, - const std::string&) { - EXPECT_EQ(1, added_resources.size()); - EXPECT_TRUE( - TestUtility::protoEqual(added_resources[0].get().resource(), load_assignment)); - })); - grpc_mux_->onDiscoveryResponse(std::move(response), control_plane_stats_); - } -} - -// Watch v3 resource type_url, receive discovery response with v2 resource type_url. -TEST_F(NewGrpcMuxImplTest, V2ResourceResponseV3ResourceWatch) { - TestScopedRuntime scoped_runtime; - Runtime::LoaderSingleton::getExisting()->mergeValues( - {{"envoy.reloadable_features.enable_type_url_downgrade_and_upgrade", "true"}}); - setup(); - - // Watch for v3 resource type_url. - const std::string& v3_type_url = - Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3); - const std::string& v2_type_url = Config::TypeUrl::get().ClusterLoadAssignment; - auto watch = grpc_mux_->addWatch(v3_type_url, {}, callbacks_, resource_decoder_, {}); - - EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_)); - - grpc_mux_->start(); - // ClusterLoadAssignment v3 is watched, v2 resource will be accepted. - { - auto response = std::make_unique(); - response->set_system_version_info("1"); - envoy::config::endpoint::v3::ClusterLoadAssignment load_assignment; - load_assignment.set_cluster_name("x"); - response->add_resources()->mutable_resource()->PackFrom(load_assignment); - // Send response that contains resource with v3 type url. - response->set_type_url(v2_type_url); - EXPECT_CALL(callbacks_, onConfigUpdate(_, _, "1")) - .WillOnce(Invoke([&load_assignment](const std::vector& added_resources, - const Protobuf::RepeatedPtrField&, - const std::string&) { - EXPECT_EQ(1, added_resources.size()); - EXPECT_TRUE( - TestUtility::protoEqual(added_resources[0].get().resource(), load_assignment)); - })); - grpc_mux_->onDiscoveryResponse(std::move(response), control_plane_stats_); - } -} - // Validate basic gRPC mux subscriptions to xdstp:// glob collections. TEST_F(NewGrpcMuxImplTest, XdsTpGlobCollection) { setup(); diff --git a/test/common/protobuf/BUILD b/test/common/protobuf/BUILD index e022b00f52b01..1118273fdbac0 100644 --- a/test/common/protobuf/BUILD +++ b/test/common/protobuf/BUILD @@ -49,14 +49,6 @@ envoy_cc_test( ], ) -envoy_cc_test( - name = "type_util_test", - srcs = ["type_util_test.cc"], - deps = [ - "//source/common/protobuf:type_util_lib", - ], -) - envoy_cc_fuzz_test( name = "value_util_fuzz_test", srcs = ["value_util_fuzz_test.cc"], diff --git a/test/common/protobuf/utility_test.cc b/test/common/protobuf/utility_test.cc index c183339fe5285..52071d16a7bf9 100644 --- a/test/common/protobuf/utility_test.cc +++ b/test/common/protobuf/utility_test.cc @@ -2009,4 +2009,13 @@ TEST(StatusCode, Strings) { ASSERT_EQ("OK", MessageUtil::CodeEnumToString(ProtobufUtil::error::OK)); } +TEST(TypeUtilTest, TypeUrlHelperFunction) { + EXPECT_EQ("envoy.config.filter.http.ip_tagging.v2.IPTagging", + TypeUtil::typeUrlToDescriptorFullName( + "type.googleapis.com/envoy.config.filter.http.ip_tagging.v2.IPTagging")); + EXPECT_EQ( + "type.googleapis.com/envoy.config.filter.http.ip_tagging.v2.IPTagging", + TypeUtil::descriptorFullNameToTypeUrl("envoy.config.filter.http.ip_tagging.v2.IPTagging")); +} + } // namespace Envoy diff --git a/test/integration/ads_integration_test.cc b/test/integration/ads_integration_test.cc index c577f065af332..08e6d8661a9b8 100644 --- a/test/integration/ads_integration_test.cc +++ b/test/integration/ads_integration_test.cc @@ -368,38 +368,6 @@ TEST_P(AdsIntegrationTest, ResourceNamesOnStreamReset) { compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {"cluster_0"}, {}, {}, true)); } -// Validate that xds can support a mix of v2 and v3 type url. -TEST_P(AdsIntegrationTest, MixV2V3TypeUrlInDiscoveryResponse) { - config_helper_.addRuntimeOverride( - "envoy.reloadable_features.enable_type_url_downgrade_and_upgrade", "true"); - initialize(); - - // Send initial configuration. - // Discovery response with v3 type url. - sendDiscoveryResponse( - Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3), - {buildCluster("cluster_0")}, {buildCluster("cluster_0")}, {}, "1", false); - // Discovery response with v2 type url. - sendDiscoveryResponse( - Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")}, - {buildClusterLoadAssignment("cluster_0")}, {}, "1"); - // Discovery response with v3 type url. - sendDiscoveryResponse( - Config::getTypeUrl( - envoy::config::core::v3::ApiVersion::V3), - {buildListener("listener_0", "route_config_0")}, - {buildListener("listener_0", "route_config_0")}, {}, "1", false); - // Discovery response with v2 type url. - sendDiscoveryResponse( - Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")}, - {buildRouteConfig("route_config_0", "cluster_0")}, {}, "1"); - test_server_->waitForCounterGe("listener_manager.listener_create_success", 1); - - // Validate that we can process a request. - makeSingleRequest(); -} - // Validate that the request with duplicate listeners is rejected. TEST_P(AdsIntegrationTest, DuplicateWarmingListeners) { initialize();