Skip to content

Commit a1cdaed

Browse files
authored
xds: refactor ADS related data to xDS-Manager part 2
This PR moves the xDS-Config-Tracker from the cluster-manager to the xds-manager. Note that in this PR we add a getter for the xDS-Config-Tracker, but that will be removed in the future when the rest of the xDS-related components are moved from the cluster-manager to the xds-manager. Signed-off-by: Adi Suissa-Peleg <[email protected]>
1 parent 2b65c22 commit a1cdaed

File tree

13 files changed

+69
-32
lines changed

13 files changed

+69
-32
lines changed

envoy/config/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ envoy_cc_library(
160160
name = "xds_manager_interface",
161161
hdrs = ["xds_manager.h"],
162162
deps = [
163+
":xds_config_tracker_interface",
163164
"//envoy/upstream:cluster_manager_interface",
164165
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
165166
],

envoy/config/xds_manager.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "envoy/common/pure.h"
44
#include "envoy/config/core/v3/config_source.pb.h"
5+
#include "envoy/config/xds_config_tracker.h"
56
#include "envoy/upstream/cluster_manager.h"
67

78
#include "absl/status/status.h"
@@ -26,10 +27,12 @@ class XdsManager {
2627
/**
2728
* Initializes the xDS-Manager.
2829
* This should be called after the cluster-manager is created.
30+
* @param boostrap - the bootstrap config of Envoy.
2931
* @param cm - a pointer to a valid cluster manager.
3032
* @return Ok if the initialization was successful, or an error otherwise.
3133
*/
32-
virtual absl::Status initialize(Upstream::ClusterManager* cm) PURE;
34+
virtual absl::Status initialize(const envoy::config::bootstrap::v3::Bootstrap& bootstrap,
35+
Upstream::ClusterManager* cm) PURE;
3336

3437
/**
3538
* Shuts down the xDS-Manager and all the configured connections to the config
@@ -46,6 +49,15 @@ class XdsManager {
4649
*/
4750
virtual absl::Status
4851
setAdsConfigSource(const envoy::config::core::v3::ApiConfigSource& config_source) PURE;
52+
53+
/**
54+
* Returns the XdsConfigTracker if defined by the bootstrap.
55+
* The object will be initialized (if configured) after the call to initialize().
56+
* TODO(adisuissa): this method will be removed once all the ADS-related objects
57+
* are moved out of the cluster-manager to the xds-manager.
58+
* @return the XdsConfigTracker if defined, or nullopt if not.
59+
*/
60+
virtual OptRef<Config::XdsConfigTracker> xdsConfigTracker() PURE;
4961
};
5062

5163
using XdsManagerPtr = std::unique_ptr<XdsManager>;

source/common/config/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ envoy_cc_library(
305305
srcs = ["xds_manager_impl.cc"],
306306
hdrs = ["xds_manager_impl.h"],
307307
deps = [
308+
":utility_lib",
308309
"//envoy/config:xds_manager_interface",
309310
"//envoy/upstream:cluster_manager_interface",
310311
"//source/common/common:thread_lib",

source/common/config/xds_manager_impl.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@
33
#include "envoy/config/core/v3/config_source.pb.validate.h"
44

55
#include "source/common/common/thread.h"
6+
#include "source/common/config/utility.h"
67

78
namespace Envoy {
89
namespace Config {
910

10-
absl::Status XdsManagerImpl::initialize(Upstream::ClusterManager* cm) {
11+
absl::Status XdsManagerImpl::initialize(const envoy::config::bootstrap::v3::Bootstrap& bootstrap,
12+
Upstream::ClusterManager* cm) {
1113
ASSERT(cm != nullptr);
1214
cm_ = cm;
15+
16+
if (bootstrap.has_xds_config_tracker_extension()) {
17+
auto& tracker_factory = Config::Utility::getAndCheckFactory<Config::XdsConfigTrackerFactory>(
18+
bootstrap.xds_config_tracker_extension());
19+
xds_config_tracker_ = tracker_factory.createXdsConfigTracker(
20+
bootstrap.xds_config_tracker_extension().typed_config(),
21+
validation_context_.dynamicValidationVisitor(), api_, main_thread_dispatcher_);
22+
}
23+
1324
return absl::OkStatus();
1425
}
1526

source/common/config/xds_manager_impl.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,29 @@ namespace Config {
99

1010
class XdsManagerImpl : public XdsManager {
1111
public:
12-
XdsManagerImpl(ProtobufMessage::ValidationContext& validation_context)
13-
: validation_context_(validation_context) {}
12+
XdsManagerImpl(Event::Dispatcher& main_thread_dispatcher, Api::Api& api,
13+
ProtobufMessage::ValidationContext& validation_context)
14+
: main_thread_dispatcher_(main_thread_dispatcher), api_(api),
15+
validation_context_(validation_context) {}
1416

1517
// Config::ConfigSourceProvider
16-
absl::Status initialize(Upstream::ClusterManager* cm) override;
18+
absl::Status initialize(const envoy::config::bootstrap::v3::Bootstrap& bootstrap,
19+
Upstream::ClusterManager* cm) override;
1720
void shutdown() override {}
1821
absl::Status
1922
setAdsConfigSource(const envoy::config::core::v3::ApiConfigSource& config_source) override;
23+
OptRef<Config::XdsConfigTracker> xdsConfigTracker() override {
24+
return makeOptRefFromPtr<Config::XdsConfigTracker>(xds_config_tracker_.get());
25+
}
2026

2127
private:
2228
// Validates (syntactically) the config_source by doing the PGV validation.
2329
absl::Status validateAdsConfig(const envoy::config::core::v3::ApiConfigSource& config_source);
2430

31+
Event::Dispatcher& main_thread_dispatcher_;
32+
Api::Api& api_;
2533
ProtobufMessage::ValidationContext& validation_context_;
34+
Config::XdsConfigTrackerPtr xds_config_tracker_;
2635
// The cm_ will only be valid after the cluster-manager is initialized.
2736
// Note that this implies that the xDS-manager must be shut down properly
2837
// prior to the cluster-manager deletion.

source/common/upstream/cluster_manager_impl.cc

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ ClusterManagerImpl::ClusterManagerImpl(
377377
}
378378

379379
// Now that the async-client manager is set, the xDS-Manager can be initialized.
380-
absl::Status status = xds_manager_.initialize(this);
380+
absl::Status status = xds_manager_.initialize(bootstrap, this);
381381
SET_AND_RETURN_IF_NOT_OK(status, creation_status);
382382

383383
// TODO(adisuissa): refactor and move the following data members to the
@@ -391,18 +391,9 @@ ClusterManagerImpl::ClusterManagerImpl(
391391
validation_context.dynamicValidationVisitor(), api, main_thread_dispatcher);
392392
}
393393

394-
if (bootstrap.has_xds_config_tracker_extension()) {
395-
auto& tracer_factory = Config::Utility::getAndCheckFactory<Config::XdsConfigTrackerFactory>(
396-
bootstrap.xds_config_tracker_extension());
397-
xds_config_tracker_ = tracer_factory.createXdsConfigTracker(
398-
bootstrap.xds_config_tracker_extension().typed_config(),
399-
validation_context.dynamicValidationVisitor(), api, main_thread_dispatcher);
400-
}
401-
402394
subscription_factory_ = std::make_unique<Config::SubscriptionFactoryImpl>(
403395
local_info, main_thread_dispatcher, *this, validation_context.dynamicValidationVisitor(), api,
404-
server, makeOptRefFromPtr(xds_resources_delegate_.get()),
405-
makeOptRefFromPtr(xds_config_tracker_.get()));
396+
server, makeOptRefFromPtr(xds_resources_delegate_.get()), xds_manager_.xdsConfigTracker());
406397
}
407398

408399
absl::Status
@@ -501,7 +492,7 @@ ClusterManagerImpl::initialize(const envoy::config::bootstrap::v3::Bootstrap& bo
501492
factory->create(std::move(primary_client), std::move(failover_client), dispatcher_,
502493
random_, *stats_.rootScope(), dyn_resources.ads_config(), local_info_,
503494
std::move(custom_config_validators), std::move(backoff_strategy),
504-
makeOptRefFromPtr(xds_config_tracker_.get()), {}, use_eds_cache);
495+
xds_manager_.xdsConfigTracker(), {}, use_eds_cache);
505496
} else {
506497
absl::Status status = Config::Utility::checkTransportVersion(dyn_resources.ads_config());
507498
RETURN_IF_NOT_OK(status);
@@ -531,11 +522,11 @@ ClusterManagerImpl::initialize(const envoy::config::bootstrap::v3::Bootstrap& bo
531522
Grpc::RawAsyncClientPtr failover_client;
532523
RETURN_IF_NOT_OK(createClients(factory_primary_or_error.value(), factory_failover,
533524
primary_client, failover_client));
534-
ads_mux_ = factory->create(
535-
std::move(primary_client), std::move(failover_client), dispatcher_, random_,
536-
*stats_.rootScope(), dyn_resources.ads_config(), local_info_,
537-
std::move(custom_config_validators), std::move(backoff_strategy),
538-
makeOptRefFromPtr(xds_config_tracker_.get()), xds_delegate_opt_ref, use_eds_cache);
525+
ads_mux_ =
526+
factory->create(std::move(primary_client), std::move(failover_client), dispatcher_,
527+
random_, *stats_.rootScope(), dyn_resources.ads_config(), local_info_,
528+
std::move(custom_config_validators), std::move(backoff_strategy),
529+
xds_manager_.xdsConfigTracker(), xds_delegate_opt_ref, use_eds_cache);
539530
}
540531
} else {
541532
ads_mux_ = std::make_unique<Config::NullGrpcMuxImpl>();

source/common/upstream/cluster_manager_impl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,6 @@ class ClusterManagerImpl : public ClusterManager,
955955
ClusterSet primary_clusters_;
956956

957957
std::unique_ptr<Config::XdsResourcesDelegate> xds_resources_delegate_;
958-
std::unique_ptr<Config::XdsConfigTracker> xds_config_tracker_;
959958

960959
bool initialized_{};
961960
bool ads_mux_initialized_{};

source/server/config_validation/server.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void ValidationInstance::initialize(const Options& options,
145145
serverFactoryContext(), messageValidationContext().staticValidationVisitor(),
146146
thread_local_);
147147

148-
xds_manager_ = std::make_unique<Config::XdsManagerImpl>(validation_context_);
148+
xds_manager_ = std::make_unique<Config::XdsManagerImpl>(*dispatcher_, *api_, validation_context_);
149149

150150
cluster_manager_factory_ = std::make_unique<Upstream::ValidationClusterManagerFactory>(
151151
server_contexts_, stats(), threadLocal(), http_context_,

source/server/server.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ absl::Status InstanceBase::initializeOrThrow(Network::Address::InstanceConstShar
753753

754754
// Create the xDS-Manager that will be passed to the cluster manager when it
755755
// is initialized below.
756-
xds_manager_ = std::make_unique<Config::XdsManagerImpl>(validation_context_);
756+
xds_manager_ = std::make_unique<Config::XdsManagerImpl>(*dispatcher_, *api_, validation_context_);
757757

758758
cluster_manager_factory_ = std::make_unique<Upstream::ProdClusterManagerFactory>(
759759
serverFactoryContext(), stats_store_, thread_local_, http_context_,

test/common/config/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ envoy_cc_test(
277277
rbe_pool = "2core",
278278
deps = [
279279
"//source/common/config:xds_manager_lib",
280+
"//test/mocks/api:api_mocks",
281+
"//test/mocks/event:event_mocks",
280282
"//test/mocks/protobuf:protobuf_mocks",
281283
"//test/mocks/upstream:cluster_manager_mocks",
282284
"//test/test_common:status_utility_lib",

0 commit comments

Comments
 (0)