New creates a new DependencyManager. - listenerName is the name of the Listener resource to request from the management server. - dataplaneAuthority is used to select the best matching virtual host from the route configuration received from the management server. - xdsClient is the xDS client to us
(listenerName, dataplaneAuthority string, xdsClient xdsclient.XDSClient, watcher ConfigWatcher)
| 135 | // - watcher is the ConfigWatcher interface that will receive the aggregated |
| 136 | // XDSConfig updates and errors. |
| 137 | func New(listenerName, dataplaneAuthority string, xdsClient xdsclient.XDSClient, watcher ConfigWatcher) *DependencyManager { |
| 138 | ctx, cancel := context.WithCancel(context.Background()) |
| 139 | dm := &DependencyManager{ |
| 140 | ldsResourceName: listenerName, |
| 141 | dataplaneAuthority: dataplaneAuthority, |
| 142 | xdsClient: xdsClient, |
| 143 | watcher: watcher, |
| 144 | nodeID: xdsClient.BootstrapConfig().Node().GetId(), |
| 145 | dnsSerializer: grpcsync.NewCallbackSerializer(ctx), |
| 146 | dnsSerializerCancel: cancel, |
| 147 | clustersFromLastRouteConfig: make(map[string]bool), |
| 148 | endpointWatchers: make(map[string]*xdsResourceState[xdsresource.EndpointsUpdate, struct{}]), |
| 149 | dnsResolvers: make(map[string]*xdsResourceState[xdsresource.DNSUpdate, dnsExtras]), |
| 150 | clusterWatchers: make(map[string]*xdsResourceState[xdsresource.ClusterUpdate, struct{}]), |
| 151 | clusterSubscriptions: make(map[string]*clusterRef), |
| 152 | } |
| 153 | dm.logger = prefixLogger(dm) |
| 154 | |
| 155 | // The dependency manager starts by watching the listener resource and |
| 156 | // discovers other resources as required. For example, the listener resource |
| 157 | // will contain the name of the route configuration resource, which will be |
| 158 | // subsequently watched.œ |
| 159 | dm.listenerWatcher = &xdsResourceState[xdsresource.ListenerUpdate, struct{}]{} |
| 160 | lw := &xdsResourceWatcher[xdsresource.ListenerUpdate]{ |
| 161 | onUpdate: func(update *xdsresource.ListenerUpdate, onDone func()) { |
| 162 | dm.onListenerResourceUpdate(update, onDone) |
| 163 | }, |
| 164 | onError: func(err error, onDone func()) { |
| 165 | dm.onListenerResourceError(err, onDone) |
| 166 | }, |
| 167 | onAmbientError: func(err error, onDone func()) { |
| 168 | dm.onListenerResourceAmbientError(err, onDone) |
| 169 | }, |
| 170 | } |
| 171 | dm.listenerWatcher.stop = xdsresource.WatchListener(dm.xdsClient, listenerName, lw) |
| 172 | return dm |
| 173 | } |
| 174 | |
| 175 | // Close cancels all registered resource watches. |
| 176 | func (m *DependencyManager) Close() { |