google.golang.org/grpc@v1.74.2/xds/internal/xdsclient/client.go (about) 1 /* 2 * 3 * Copyright 2019 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 // Package xdsclient implements a full fledged gRPC client for the xDS API used 20 // by the xds resolver and balancer implementations. 21 package xdsclient 22 23 import ( 24 "context" 25 26 v3statuspb "github.com/envoyproxy/go-control-plane/envoy/service/status/v3" 27 "google.golang.org/grpc/internal/xds/bootstrap" 28 "google.golang.org/grpc/xds/internal/clients/lrsclient" 29 "google.golang.org/grpc/xds/internal/xdsclient/xdsresource" 30 ) 31 32 // XDSClient is a full fledged gRPC client which queries a set of discovery APIs 33 // (collectively termed as xDS) on a remote management server, to discover 34 // various dynamic resources. 35 type XDSClient interface { 36 // WatchResource uses xDS to discover the resource associated with the 37 // provided resource name. The resource type implementation determines how 38 // xDS responses are are deserialized and validated, as received from the 39 // xDS management server. Upon receipt of a response from the management 40 // server, an appropriate callback on the watcher is invoked. 41 // 42 // Most callers will not have a need to use this API directly. They will 43 // instead use a resource-type-specific wrapper API provided by the relevant 44 // resource type implementation. 45 // 46 // 47 // During a race (e.g. an xDS response is received while the user is calling 48 // cancel()), there's a small window where the callback can be called after 49 // the watcher is canceled. Callers need to handle this case. 50 WatchResource(rType xdsresource.Type, resourceName string, watcher xdsresource.ResourceWatcher) (cancel func()) 51 52 ReportLoad(*bootstrap.ServerConfig) (*lrsclient.LoadStore, func(context.Context)) 53 54 BootstrapConfig() *bootstrap.Config 55 } 56 57 // DumpResources returns the status and contents of all xDS resources. It uses 58 // xDS clients from the default pool. 59 func DumpResources() *v3statuspb.ClientStatusResponse { 60 return DefaultPool.DumpResources() 61 }