Skip to content

Commit

Permalink
internal: Refactor Envoy into v2 package
Browse files Browse the repository at this point in the history
Refactors the envoy package into a v2 package for Envoy API V2 types.
Common items are kept in the envoy package for use by other versions.

Updates: projectcontour#1898

Signed-off-by: Steve Sloka <slokas@vmware.com>
  • Loading branch information
stevesloka committed Sep 18, 2020
1 parent 1b57d24 commit e3f2faa
Show file tree
Hide file tree
Showing 72 changed files with 4,870 additions and 4,688 deletions.
4 changes: 2 additions & 2 deletions cmd/contour/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

resource "github.com/envoyproxy/go-control-plane/pkg/resource/v2"
"github.com/projectcontour/contour/internal/build"
"github.com/projectcontour/contour/internal/envoy"
v2 "github.com/projectcontour/contour/internal/envoy/v2"
"github.com/projectcontour/contour/internal/k8s"
"github.com/sirupsen/logrus"
kingpin "gopkg.in/alecthomas/kingpin.v2"
Expand Down Expand Up @@ -69,7 +69,7 @@ func main() {
case sdmShutdown.FullCommand():
sdmShutdownCtx.shutdownHandler()
case bootstrap.FullCommand():
if err := envoy.WriteBootstrap(bootstrapCtx); err != nil {
if err := v2.WriteBootstrap(bootstrapCtx); err != nil {
log.WithError(err).Fatal("failed to write bootstrap configuration")
}
case certgenApp.FullCommand():
Expand Down
5 changes: 2 additions & 3 deletions cmd/contour/servecontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ import (
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/projectcontour/contour/internal/envoy"
"github.com/projectcontour/contour/internal/fixture"
"k8s.io/apimachinery/pkg/types"

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/types"
)

func TestServeContextProxyRootNamespaces(t *testing.T) {
Expand Down
23 changes: 12 additions & 11 deletions internal/contour/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@ import (
"sort"
"sync"

v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2"
envoy_api_v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2"
resource "github.com/envoyproxy/go-control-plane/pkg/resource/v2"
"github.com/golang/protobuf/proto"
"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/envoy"
v2 "github.com/projectcontour/contour/internal/envoy/v2"
"github.com/projectcontour/contour/internal/protobuf"
"github.com/projectcontour/contour/internal/sorter"
)

// ClusterCache manages the contents of the gRPC CDS cache.
type ClusterCache struct {
mu sync.Mutex
values map[string]*v2.Cluster
values map[string]*envoy_api_v2.Cluster
Cond
}

// Update replaces the contents of the cache with the supplied map.
func (c *ClusterCache) Update(v map[string]*v2.Cluster) {
func (c *ClusterCache) Update(v map[string]*envoy_api_v2.Cluster) {
c.mu.Lock()
defer c.mu.Unlock()

Expand All @@ -46,7 +47,7 @@ func (c *ClusterCache) Update(v map[string]*v2.Cluster) {
func (c *ClusterCache) Contents() []proto.Message {
c.mu.Lock()
defer c.mu.Unlock()
var values []*v2.Cluster
var values []*envoy_api_v2.Cluster
for _, v := range c.values {
values = append(values, v)
}
Expand All @@ -57,7 +58,7 @@ func (c *ClusterCache) Contents() []proto.Message {
func (c *ClusterCache) Query(names []string) []proto.Message {
c.mu.Lock()
defer c.mu.Unlock()
var values []*v2.Cluster
var values []*envoy_api_v2.Cluster
for _, n := range names {
// if the cluster is not registered we cannot return
// a blank cluster because each cluster has a required
Expand All @@ -80,13 +81,13 @@ func (c *ClusterCache) OnChange(root *dag.DAG) {
}

type clusterVisitor struct {
clusters map[string]*v2.Cluster
clusters map[string]*envoy_api_v2.Cluster
}

// visitCluster produces a map of *v2.Clusters.
func visitClusters(root dag.Vertex) map[string]*v2.Cluster {
// visitCluster produces a map of *envoy_api_v2.Clusters.
func visitClusters(root dag.Vertex) map[string]*envoy_api_v2.Cluster {
cv := clusterVisitor{
clusters: make(map[string]*v2.Cluster),
clusters: make(map[string]*envoy_api_v2.Cluster),
}
cv.visit(root)
return cv.clusters
Expand All @@ -97,12 +98,12 @@ func (v *clusterVisitor) visit(vertex dag.Vertex) {
case *dag.Cluster:
name := envoy.Clustername(cluster)
if _, ok := v.clusters[name]; !ok {
v.clusters[name] = envoy.Cluster(cluster)
v.clusters[name] = v2.Cluster(cluster)
}
case *dag.ExtensionCluster:
name := cluster.Name
if _, ok := v.clusters[name]; !ok {
v.clusters[name] = envoy.ExtensionCluster(cluster)
v.clusters[name] = v2.ExtensionCluster(cluster)
}
}

Expand Down
Loading

0 comments on commit e3f2faa

Please sign in to comment.