• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.circleci/H13-Feb-2020-

.github/H13-Feb-2020-

build/H13-Feb-2020-

envoy/H13-Feb-2020-

pkg/H13-Feb-2020-

sample/H13-Feb-2020-

.codecov.ymlH A D13-Feb-202099

.gitignoreH A D13-Feb-2020184

Dockerfile.ciH A D13-Feb-2020728

LICENSEH A D13-Feb-202011.1 KiB

MakefileH A D13-Feb-20201 KiB

OWNERS.mdH A D13-Feb-2020283

README.mdH A D13-Feb-20204.1 KiB

go.modH A D13-Feb-2020471

go.sumH A D13-Feb-20205.4 KiB

README.md

1# control-plane
2
3[![CircleCI](https://circleci.com/gh/envoyproxy/go-control-plane.svg?style=svg)](https://circleci.com/gh/envoyproxy/go-control-plane)
4[![Go Report Card](https://goreportcard.com/badge/github.com/envoyproxy/go-control-plane)](https://goreportcard.com/report/github.com/envoyproxy/go-control-plane)
5[![GoDoc](https://godoc.org/github.com/envoyproxy/go-control-plane?status.svg)](https://godoc.org/github.com/envoyproxy/go-control-plane)
6
7This repository contains a Go-based implementation of an API server that
8implements the discovery service APIs defined in
9[data-plane-api](https://github.com/envoyproxy/data-plane-api).
10
11
12## Scope
13
14Due to the variety of platforms out there, there is no single
15control plane implementation that can satisfy everyone's needs. Hence this
16code base does not attempt to be a full scale control plane for a fleet of
17Envoy proxies. Instead, it provides infrastructure that is shared by
18multiple different control plane implementations. The components provided
19by this library are:
20
21* _API Server:_ A generic gRPC based API server that implements xDS APIs as defined
22  in the
23  [data-plane-api](https://github.com/envoyproxy/data-plane-api). The API
24  server is responsible for pushing configuration updates to
25  Envoys. Consumers should be able to import this go library and use the
26  API server as is, in production deployments.
27
28* _Configuration Cache:_ The library will cache Envoy configurations in
29memory in an attempt to provide fast response to consumer Envoys. It is the
30responsibility of the consumer of this library to populate the cache as
31well as invalidate it when necessary. The cache will be keyed based on a
32pre-defined hash function whose keys are based on the
33[Node information](https://github.com/envoyproxy/data-plane-api/blob/d4988844024d0bcff4bcd030552eabe3396203fa/api/base.proto#L26-L36).
34
35At this moment, this repository will not tackle translating platform
36specific representation of resources (e.g., services, instances of
37services, etc.) into Envoy-style configuration. Based on usage and
38feedback, we might decided to revisit this aspect at a later point in time.
39
40## Requirements
41
421. Go 1.12+
43
44## Quick start
45
46It's recommended to run the command with script `./build/run_docker.sh` as it executes the command
47in the same environment as the circle ci. This makes sure to produce a consistent set of generated files.
48
491. Setup existing build:
50
51    ```sh
52    ./build/run_docker.sh make build test
53    ```
54
551. Run [integration test](pkg/test/main/README.md) against the latest Envoy binary:
56
57    ```sh
58    ./build/run_docker.sh make integration
59    ```
60
61## Usage
62
63Register services on the gRPC server as follows.
64
65```go
66import (
67	"context"
68	"google.golang.org/grpc"
69	"net"
70
71	api "github.com/envoyproxy/go-control-plane/envoy/api/v2"
72	discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v2"
73	"github.com/envoyproxy/go-control-plane/pkg/cache"
74	xds "github.com/envoyproxy/go-control-plane/pkg/server"
75)
76
77func main() {
78	snapshotCache := cache.NewSnapshotCache(false, cache.IDHash{}, nil)
79	server := xds.NewServer(context.Background(), snapshotCache, nil)
80	grpcServer := grpc.NewServer()
81	lis, _ := net.Listen("tcp", ":8080")
82
83	discovery.RegisterAggregatedDiscoveryServiceServer(grpcServer, server)
84	api.RegisterEndpointDiscoveryServiceServer(grpcServer, server)
85	api.RegisterClusterDiscoveryServiceServer(grpcServer, server)
86	api.RegisterRouteDiscoveryServiceServer(grpcServer, server)
87	api.RegisterListenerDiscoveryServiceServer(grpcServer, server)
88	go func() {
89		if err := grpcServer.Serve(lis); err != nil {
90			// error handling
91		}
92	}()
93}
94```
95
96As mentioned in [Scope](https://github.com/envoyproxy/go-control-plane/blob/master/README.md#scope), you need to cache Envoy configurations.
97Generate the key based on the node information as follows and cache the configurations.
98
99```go
100import "github.com/envoyproxy/go-control-plane/pkg/cache"
101
102var clusters, endpoints, routes, listeners []cache.Resource
103
104snapshotCache := cache.NewSnapshotCache(false, cache.IDHash{}, nil)
105snapshot := cache.NewSnapshot("1.0", endpoints, clusters, routes, listeners)
106_ = snapshotCache.SetSnapshot("node1", snapshot)
107```
108