1
#pragma once
2

            
3
#include "envoy/common/pure.h"
4
#include "envoy/config/core/v3/config_source.pb.h"
5
#include "envoy/config/subscription_factory.h"
6
#include "envoy/config/xds_config_tracker.h"
7
#include "envoy/config/xds_resources_delegate.h"
8
#include "envoy/upstream/cluster_manager.h"
9

            
10
#include "absl/status/status.h"
11

            
12
namespace Envoy {
13
namespace Config {
14

            
15
/**
16
 * An xDS-Manager interface for all operations related to xDS connections and
17
 * resources in Envoy.
18
 *
19
 * This class is WIP. Currently supported functionality:
20
 * - Dynamically set the ADS configuration to be used.
21
 *
22
 * In general, this is intended to be used only on the main thread, as part of the Server instance
23
 * interface and config subsystem.
24
 */
25
class XdsManager {
26
public:
27
50738
  virtual ~XdsManager() = default;
28

            
29
  /**
30
   * Initializes the xDS-Manager.
31
   * This should be called after the cluster-manager is created.
32
   * @param bootstrap - the bootstrap config of Envoy.
33
   * @param cm - a pointer to a valid cluster manager.
34
   * @return Ok if the initialization was successful, or an error otherwise.
35
   */
36
  virtual absl::Status initialize(const envoy::config::bootstrap::v3::Bootstrap& bootstrap,
37
                                  Upstream::ClusterManager* cm) PURE;
38

            
39
  /**
40
   * Initializes the ADS connections.
41
   * This should be called after the cluster-manager was created, and the
42
   * primiary clusters were initialized.
43
   * @param bootstrap - the bootstrap config of Envoy.
44
   * @return Ok if the initialization was successful, or an error otherwise.
45
   */
46
  virtual absl::Status
47
  initializeAdsConnections(const envoy::config::bootstrap::v3::Bootstrap& bootstrap) PURE;
48

            
49
  /**
50
   * Start all xDS-TP config-based gRPC muxes (if any).
51
   * This includes both the servers defined in the `config_sources`, and
52
   * `default_config_source` in the bootstrap.
53
   */
54
  virtual void startXdstpAdsMuxes() PURE;
55

            
56
  /**
57
   * Subscription to a singleton resource.
58
   * This will create a subscription to a singleton resource, based on the resource_name and the
59
   * config source. If an xDS-TP based resource name is given, then the config sources defined in
60
   * the Bootstrap config_sources/default_config_source may be used.
61
   *
62
   * @param resource_name absl::string_view the resource to subscribe to.
63
   * @param config OptRef<const envoy::config::core::v3::ConfigSource> an optional config source to
64
   * use.
65
   * @param type_url type URL for the resource being subscribed to.
66
   * @param scope stats scope for any stats tracked by the subscription.
67
   * @param callbacks the callbacks needed by all Subscription objects, to deliver config updates.
68
   *                  The callbacks must not result in the deletion of the Subscription object.
69
   * @param resource_decoder how incoming opaque resource objects are to be decoded.
70
   * @param options subscription options.
71
   *
72
   * @return SubscriptionPtr subscription object corresponding for config and type_url or error
73
   * status.
74
   */
75
  virtual absl::StatusOr<SubscriptionPtr> subscribeToSingletonResource(
76
      absl::string_view resource_name, OptRef<const envoy::config::core::v3::ConfigSource> config,
77
      absl::string_view type_url, Stats::Scope& scope, SubscriptionCallbacks& callbacks,
78
      OpaqueResourceDecoderSharedPtr resource_decoder, const SubscriptionOptions& options) PURE;
79

            
80
  /**
81
   * Pause discovery requests for a given API type on all ADS types (both xdstp-based and "old"
82
   * ADS). This is useful, for example, when we're processing an update for LDS or CDS and don't
83
   * want a flood of updates for RDS or EDS respectively. Discovery requests may later be resumed
84
   * with after the returned ScopedResume object is destroyed.
85
   * @param type_url type URL corresponding to xDS API, e.g.
86
   * type.googleapis.com/envoy.config.cluster.v3.Cluster.
87
   *
88
   * @return a ScopedResume object, which when destructed, resumes the paused discovery requests.
89
   * A discovery request will be sent if one would have been sent during the pause.
90
   */
91
  ABSL_MUST_USE_RESULT virtual ScopedResume pause(const std::string& type_url) PURE;
92

            
93
  /**
94
   * Pause discovery requests for given API types on all ADS types (both xdstp-based and "old" ADS).
95
   * This is useful, for example, when we're processing an update for LDS or CDS and don't want a
96
   * flood of updates for RDS or EDS respectively. Discovery requests may later be resumed with
97
   * after the returned ScopedResume object is destroyed.
98
   * @param type_urls type URLs corresponding to xDS API, e.g.
99
   * type.googleapis.com/envoy.config.cluster.v3.Cluster.
100
   *
101
   * @return a ScopedResume object, which when destructed, resumes the paused discovery requests.
102
   * A discovery request will be sent if one would have been sent during the pause.
103
   */
104
  ABSL_MUST_USE_RESULT virtual ScopedResume pause(const std::vector<std::string>& type_urls) PURE;
105

            
106
  /**
107
   * Shuts down the xDS-Manager and all the configured connections to the config
108
   * servers.
109
   */
110
  virtual void shutdown() PURE;
111

            
112
  /**
113
   * Set the ADS ConfigSource Envoy should use that will replace the current ADS
114
   * server.
115
   * @param ads_config the ADS config of the new server.
116
   * @return Ok if the ADS config is valid (points to a valid static server),
117
   *         or an error otherwise.
118
   */
119
  virtual absl::Status
120
  setAdsConfigSource(const envoy::config::core::v3::ApiConfigSource& config_source) PURE;
121

            
122
  /**
123
   * Returns a shared_ptr to the singleton xDS-over-gRPC provider for upstream control plane muxing
124
   * of xDS. This is treated somewhat as a special case in ClusterManager, since it does not relate
125
   * logically to the management of clusters but instead is required early in ClusterManager/server
126
   * initialization and in various sites that need ClusterManager for xDS API interfacing.
127
   *
128
   * @return GrpcMux& ADS API provider referencee.
129
   */
130
  virtual Config::GrpcMuxSharedPtr adsMux() PURE;
131

            
132
  /**
133
   * Obtain the subscription factory for the cluster manager. Since subscriptions may have an
134
   * upstream component, the factory is a facet of the cluster manager.
135
   *
136
   * @return Config::SubscriptionFactory& the subscription factory.
137
   */
138
  virtual SubscriptionFactory& subscriptionFactory() PURE;
139
};
140

            
141
using XdsManagerPtr = std::unique_ptr<XdsManager>;
142
} // namespace Config
143
} // namespace Envoy