Skip to content

Commit

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

This doesn't change anything functionally, just refactors contour into a v2 package.

Updates: projectcontour#1898

Signed-off-by: Steve Sloka <slokas@vmware.com>
  • Loading branch information
stevesloka committed Sep 21, 2020
1 parent aae453f commit bd45169
Show file tree
Hide file tree
Showing 25 changed files with 291 additions and 282 deletions.
13 changes: 7 additions & 6 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/envoyproxy/go-control-plane/pkg/server/v2"
"github.com/projectcontour/contour/internal/annotation"
"github.com/projectcontour/contour/internal/contour"
v2 "github.com/projectcontour/contour/internal/contour/v2"
"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/debug"
"github.com/projectcontour/contour/internal/health"
Expand Down Expand Up @@ -201,7 +202,7 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error {
return fmt.Errorf("error parsing request timeout: %w", err)
}

listenerConfig := contour.ListenerConfig{
listenerConfig := v2.ListenerConfig{
UseProxyProto: ctx.useProxyProto,
HTTPAddress: ctx.httpAddr,
HTTPPort: ctx.httpPort,
Expand Down Expand Up @@ -230,13 +231,13 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error {

// Endpoints updates are handled directly by the EndpointsTranslator
// due to their high update rate and their orthogonal nature.
endpointHandler := contour.NewEndpointsTranslator(log.WithField("context", "endpointstranslator"))
endpointHandler := v2.NewEndpointsTranslator(log.WithField("context", "endpointstranslator"))

resources := []contour.ResourceCache{
contour.NewListenerCache(listenerConfig, ctx.statsAddr, ctx.statsPort),
&contour.SecretCache{},
&contour.RouteCache{},
&contour.ClusterCache{},
v2.NewListenerCache(listenerConfig, ctx.statsAddr, ctx.statsPort),
&v2.SecretCache{},
&v2.RouteCache{},
&v2.ClusterCache{},
endpointHandler,
}

Expand Down
7 changes: 4 additions & 3 deletions cmd/contour/servecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
"strings"
"time"

"github.com/projectcontour/contour/internal/contour"
v2 "github.com/projectcontour/contour/internal/contour/v2"

"github.com/projectcontour/contour/internal/envoy"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
Expand Down Expand Up @@ -162,8 +163,8 @@ func newServeContext() *serveContext {
healthPort: 8000,
metricsAddr: "0.0.0.0",
metricsPort: 8000,
httpAccessLog: contour.DEFAULT_HTTP_ACCESS_LOG,
httpsAccessLog: contour.DEFAULT_HTTPS_ACCESS_LOG,
httpAccessLog: v2.DEFAULT_HTTP_ACCESS_LOG,
httpsAccessLog: v2.DEFAULT_HTTPS_ACCESS_LOG,
httpAddr: "0.0.0.0",
httpsAddr: "0.0.0.0",
httpPort: 8080,
Expand Down
4 changes: 2 additions & 2 deletions cmd/contour/shutdownmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"os"
"time"

"github.com/projectcontour/contour/internal/contour"
v2 "github.com/projectcontour/contour/internal/contour/v2"

"github.com/prometheus/common/expfmt"

Expand All @@ -43,7 +43,7 @@ const shutdownReadyFile = "/ok"
const shutdownReadyCheckInterval = time.Second * 1

func prometheusLabels() []string {
return []string{contour.ENVOY_HTTP_LISTENER, contour.ENVOY_HTTPS_LISTENER}
return []string{v2.ENVOY_HTTP_LISTENER, v2.ENVOY_HTTPS_LISTENER}
}

type shutdownmanagerContext struct {
Expand Down
4 changes: 3 additions & 1 deletion internal/contour/cond_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

package contour

import "testing"
import (
"testing"
)

func TestCondRegisterBeforeNotifyShouldNotBroadcast(t *testing.T) {
var c Cond
Expand Down
6 changes: 2 additions & 4 deletions internal/contour/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour_test
package contour

import (
"context"
"fmt"
"time"

"github.com/projectcontour/contour/internal/contour"
)

func ExampleCond() {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
ch := make(chan int, 1)
last := 0
var c contour.Cond
var c Cond
go func() {
for {
time.Sleep(100 * time.Millisecond)
Expand Down
3 changes: 1 addition & 2 deletions internal/contour/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import (
"reflect"
"strconv"

"github.com/projectcontour/contour/internal/xds"

envoy_xds "github.com/envoyproxy/go-control-plane/pkg/cache/types"
"github.com/envoyproxy/go-control-plane/pkg/cache/v2"
resource "github.com/envoyproxy/go-control-plane/pkg/resource/v2"
"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/xds"
"github.com/sirupsen/logrus"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
"sort"
"sync"

"github.com/projectcontour/contour/internal/contour"

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"
Expand All @@ -31,7 +33,7 @@ import (
type ClusterCache struct {
mu sync.Mutex
values map[string]*envoy_api_v2.Cluster
Cond
contour.Cond
}

// Update replaces the contents of the cache with the supplied map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
v1 "k8s.io/api/core/v1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
"fmt"
"sort"
"sync"

"github.com/projectcontour/contour/internal/contour"

envoy_api_v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2"
envoy_api_v2_endpoint "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint"
resource "github.com/envoyproxy/go-control-plane/pkg/resource/v2"
Expand Down Expand Up @@ -222,7 +224,7 @@ func (c *EndpointsCache) DeleteEndpoint(ep *v1.Endpoints) {
// NewEndpointsTranslator allocates a new endpoints translator.
func NewEndpointsTranslator(log logrus.FieldLogger) *EndpointsTranslator {
return &EndpointsTranslator{
Cond: Cond{},
Cond: contour.Cond{},
FieldLogger: log,
entries: map[string]*envoy_api_v2.ClusterLoadAssignment{},
cache: EndpointsCache{
Expand All @@ -237,9 +239,9 @@ func NewEndpointsTranslator(log logrus.FieldLogger) *EndpointsTranslator {
// ClusterLoadAssignment resources.
type EndpointsTranslator struct {
// Observer notifies when the endpoints cache has been updated.
Observer Observer
Observer contour.Observer

Cond
contour.Cond
logrus.FieldLogger

cache EndpointsCache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
"path"
Expand All @@ -25,6 +25,7 @@ import (
http "github.com/envoyproxy/go-control-plane/envoy/config/filter/network/http_connection_manager/v2"
resource "github.com/envoyproxy/go-control-plane/pkg/resource/v2"
"github.com/golang/protobuf/proto"
"github.com/projectcontour/contour/internal/contour"
"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/envoy"
v2 "github.com/projectcontour/contour/internal/envoy/v2"
Expand Down Expand Up @@ -222,7 +223,7 @@ type ListenerCache struct {
staticValues map[string]*envoy_api_v2.Listener

Config ListenerConfig
Cond
contour.Cond
}

// NewListenerCache returns an instance of a ListenerCache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
"path"
Expand Down
5 changes: 3 additions & 2 deletions internal/contour/route.go → internal/contour/v2/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
"path"
Expand All @@ -23,6 +23,7 @@ import (
resource "github.com/envoyproxy/go-control-plane/pkg/resource/v2"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/any"
"github.com/projectcontour/contour/internal/contour"
"github.com/projectcontour/contour/internal/dag"
v2 "github.com/projectcontour/contour/internal/envoy/v2"
"github.com/projectcontour/contour/internal/protobuf"
Expand All @@ -33,7 +34,7 @@ import (
type RouteCache struct {
mu sync.Mutex
values map[string]*envoy_api_v2.RouteConfiguration
Cond
contour.Cond
}

// Update replaces the contents of the cache with the supplied map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
"testing"
Expand Down
5 changes: 3 additions & 2 deletions internal/contour/secret.go → internal/contour/v2/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
"sort"
Expand All @@ -20,6 +20,7 @@ import (
envoy_api_v2_auth "github.com/envoyproxy/go-control-plane/envoy/api/v2/auth"
resource "github.com/envoyproxy/go-control-plane/pkg/resource/v2"
"github.com/golang/protobuf/proto"
"github.com/projectcontour/contour/internal/contour"
"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/envoy"
v2 "github.com/projectcontour/contour/internal/envoy/v2"
Expand All @@ -31,7 +32,7 @@ import (
type SecretCache struct {
mu sync.Mutex
values map[string]*envoy_api_v2_auth.Secret
Cond
contour.Cond
}

// Update replaces the contents of the cache with the supplied map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
"context"
Expand All @@ -20,6 +20,8 @@ import (
"testing"
"time"

"github.com/projectcontour/contour/internal/contour"

v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2"
discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v2"
resource "github.com/envoyproxy/go-control-plane/pkg/resource/v2"
Expand All @@ -40,7 +42,7 @@ import (
func TestGRPC(t *testing.T) {
// tr and et is recreated before the start of each test.
var et *EndpointsTranslator
var eh *EventHandler
var eh *contour.EventHandler

tests := map[string]func(*testing.T, *grpc.ClientConn){
"StreamClusters": func(t *testing.T, cc *grpc.ClientConn) {
Expand Down Expand Up @@ -191,20 +193,20 @@ func TestGRPC(t *testing.T) {
t.Run(name, func(t *testing.T) {
et = NewEndpointsTranslator(fixture.NewTestLogger(t))

resources := []ResourceCache{
resources := []contour.ResourceCache{
NewListenerCache(ListenerConfig{}, "", 0),
&SecretCache{},
&RouteCache{},
&ClusterCache{},
et,
}

eh = &EventHandler{
Observer: dag.ComposeObservers(ObserversOf(resources)...),
eh = &contour.EventHandler{
Observer: dag.ComposeObservers(contour.ObserversOf(resources)...),
FieldLogger: log,
}

srv := xds.RegisterServer(xds.NewContourServer(log, ResourcesOf(resources)...), nil)
srv := xds.RegisterServer(xds.NewContourServer(log, contour.ResourcesOf(resources)...), nil)
l, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
done := make(chan error, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package contour
package v2

import (
"testing"
Expand Down
Loading

0 comments on commit bd45169

Please sign in to comment.