google.golang.org/grpc@v1.72.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  	v3statuspb "github.com/envoyproxy/go-control-plane/envoy/service/status/v3"
    25  	"google.golang.org/grpc/internal/xds/bootstrap"
    26  	"google.golang.org/grpc/xds/internal/xdsclient/load"
    27  	"google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
    28  )
    29  
    30  // XDSClient is a full fledged gRPC client which queries a set of discovery APIs
    31  // (collectively termed as xDS) on a remote management server, to discover
    32  // various dynamic resources.
    33  type XDSClient interface {
    34  	// WatchResource uses xDS to discover the resource associated with the
    35  	// provided resource name. The resource type implementation determines how
    36  	// xDS responses are are deserialized and validated, as received from the
    37  	// xDS management server. Upon receipt of a response from the management
    38  	// server, an appropriate callback on the watcher is invoked.
    39  	//
    40  	// Most callers will not have a need to use this API directly. They will
    41  	// instead use a resource-type-specific wrapper API provided by the relevant
    42  	// resource type implementation.
    43  	//
    44  	//
    45  	// During a race (e.g. an xDS response is received while the user is calling
    46  	// cancel()), there's a small window where the callback can be called after
    47  	// the watcher is canceled. Callers need to handle this case.
    48  	WatchResource(rType xdsresource.Type, resourceName string, watcher xdsresource.ResourceWatcher) (cancel func())
    49  
    50  	ReportLoad(*bootstrap.ServerConfig) (*load.Store, func())
    51  
    52  	BootstrapConfig() *bootstrap.Config
    53  }
    54  
    55  // DumpResources returns the status and contents of all xDS resources. It uses
    56  // xDS clients from the default pool.
    57  func DumpResources() *v3statuspb.ClientStatusResponse {
    58  	return DefaultPool.DumpResources()
    59  }