Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/contour: Refactor v2 contour files into v2 package #2928

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
contourv1 "github.com/projectcontour/contour/apis/projectcontour/v1"
"github.com/projectcontour/contour/internal/annotation"
"github.com/projectcontour/contour/internal/contour"
contourv2 "github.com/projectcontour/contour/internal/contour/v2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a little unfortunate that contourv1 refers to the API package, while contourv2 refers to the internal package. We could use contourv1api or similar for the former. Not blocking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup I agree. =)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #2938.

"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/debug"
"github.com/projectcontour/contour/internal/health"
Expand Down Expand Up @@ -246,7 +247,7 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error {
return fmt.Errorf("error parsing request timeout: %w", err)
}

listenerConfig := contour.ListenerConfig{
listenerConfig := contourv2.ListenerConfig{
UseProxyProto: ctx.useProxyProto,
HTTPAddress: ctx.httpAddr,
HTTPPort: ctx.httpPort,
Expand Down Expand Up @@ -275,13 +276,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 := contourv2.NewEndpointsTranslator(log.WithField("context", "endpointstranslator"))

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

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

"github.com/projectcontour/contour/internal/contour"
contourv2 "github.com/projectcontour/contour/internal/contour/v2"
envoyv2 "github.com/projectcontour/contour/internal/envoy/v2"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
Expand Down Expand Up @@ -166,8 +166,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: contourv2.DEFAULT_HTTP_ACCESS_LOG,
httpsAccessLog: contourv2.DEFAULT_HTTPS_ACCESS_LOG,
httpAddr: "0.0.0.0",
httpsAddr: "0.0.0.0",
httpPort: 8080,
Expand Down
7 changes: 2 additions & 5 deletions cmd/contour/shutdownmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ import (
"os"
"time"

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

contourv2 "github.com/projectcontour/contour/internal/contour/v2"
"github.com/prometheus/common/expfmt"

"github.com/sirupsen/logrus"

"gopkg.in/alecthomas/kingpin.v2"
)

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

func prometheusLabels() []string {
return []string{contour.ENVOY_HTTP_LISTENER, contour.ENVOY_HTTPS_LISTENER}
return []string{contourv2.ENVOY_HTTP_LISTENER, contourv2.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"
envoyv2 "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"
envoyv2 "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
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"
envoyv2 "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