github.com/imran-kn/cilium-fork@v1.6.9/pkg/envoy/xds/doc.go (about) 1 // Copyright 2018 Authors of Cilium 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package xds is an implementation of Envoy's xDS (Discovery Service) 16 // protocol. 17 // 18 // Server is the base implementation of any gRPC server which supports the xDS 19 // protocol. All xDS bi-directional gRPC streams from Stream* calls must be 20 // handled by calling Server.HandleRequestStream. 21 // For example, to implement the ADS protocol: 22 // 23 // func (s *myGRPCServer) StreamAggregatedResources(stream api.AggregatedDiscoveryService_StreamAggregatedResourcesServer) error { 24 // return s.xdsServer.HandleRequestStream(stream.Context(), stream, xds.AnyTypeURL) 25 // } 26 // 27 // Server is parameterized by a map of supported resource type URLs to resource 28 // sets, e.g. to support the LDS and RDS protocols: 29 // 30 // ldsCache := xds.NewCache() 31 // lds := xds.NewAckingResourceMutatorWrapper(ldsCache) 32 // rdsCache := xds.NewCache() 33 // rds := xds.NewAckingResourceMutatorWrapper(rdsCache) 34 // 35 // resTypes := map[string]xds.ResourceTypeConfiguration{ 36 // "type.googleapis.com/envoy.api.v2.Listener": {ldsCache, lds}, 37 // "type.googleapis.com/envoy.api.v2.RouteConfiguration": {rdsCache, rds}, 38 // } 39 // 40 // server := xds.NewServer(resTypes, 5*time.Seconds) 41 // 42 // It is recommended to use a distinct resource set for each resource type to 43 // minimize the volume of messages sent and received by xDS clients. 44 // 45 // Resource sets must implement the ResourceSource interface to provide read 46 // access to resources of one or multiple resource types: 47 // 48 // type ResourceSource interface { 49 // GetResources(ctx context.Context, typeURL string, lastVersion *uint64, 50 // nodeIP string, resourceNames []string) (*VersionedResources, error) 51 // } 52 // 53 // Resource sets should implement the ResourceSet interface to provide 54 // read-write access. It provides an API to atomically update the resources in 55 // the set: Upsert inserts or updates a single resource in the set, and 56 // Delete deletes a single resource from the set. 57 // 58 // Cache is an efficient, ready-to-use implementation of ResourceSet: 59 // 60 // typeURL := "type.googleapis.com/envoy.api.v2.Listener" 61 // ldsCache := xds.NewCache() 62 // ldsCache.Upsert(typeURL, "listener123", listenerA, false) 63 // ldsCache.Delete(typeURL, "listener456", false) 64 // 65 // In order to wait for acknowledgements of updates by Envoy nodes, 66 // each resource set should be wrapped into an AckingResourceMutatorWrapper, 67 // which should then be passed to NewServer(). 68 // AckingResourceMutatorWrapper provides an extended API which accepts 69 // Completions to notify of ACKs. 70 // 71 // typeURL := "type.googleapis.com/envoy.api.v2.Listener" 72 // ldsCache := xds.NewCache() 73 // lds := xds.NewAckingResourceMutatorWrapper(ldsCache) 74 // 75 // ctx, cancel := context.WithTimeout(..., 5*time.Second) 76 // wg := completion.NewWaitGroup(ctx) 77 // nodes := []string{"10.0.0.1"} // Nodes to wait an ACK from. 78 // lds.Upsert(typeURL, "listener123", listenerA, nodes, wg.AddCompletion()) 79 // lds.Delete(typeURL, "listener456", nodes, wg.AddCompletion()) 80 // wg.Wait() 81 // cancel() 82 package xds