From f4cecd8db482da09a8b9b11c78301807b6ce0289 Mon Sep 17 00:00:00 2001 From: Steve Sloka Date: Sun, 20 Sep 2020 17:35:58 -0400 Subject: [PATCH] internal/contour: Refactor v2 contour files into v2 package 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: #1898 Signed-off-by: Steve Sloka --- cmd/contour/serve.go | 13 +- cmd/contour/servecontext.go | 6 +- cmd/contour/shutdownmanager.go | 7 +- internal/contour/cond_test.go | 4 +- internal/contour/example_test.go | 6 +- internal/contour/snapshot.go | 3 +- internal/contour/{ => v2}/cluster.go | 6 +- internal/contour/{ => v2}/cluster_test.go | 2 +- internal/contour/{ => v2}/contour_test.go | 2 +- .../contour/{ => v2}/endpointstranslator.go | 10 +- .../{ => v2}/endpointstranslator_test.go | 2 +- internal/contour/{ => v2}/listener.go | 5 +- internal/contour/{ => v2}/listener_test.go | 2 +- internal/contour/{ => v2}/route.go | 5 +- internal/contour/{ => v2}/route_test.go | 2 +- internal/contour/{ => v2}/secret.go | 5 +- internal/contour/{ => v2}/secret_test.go | 2 +- internal/contour/{ => v2}/server_test.go | 14 +- internal/contour/{ => v2}/visitor_test.go | 2 +- internal/featuretests/envoy.go | 10 +- internal/featuretests/featuretests.go | 39 +-- internal/featuretests/headercondition_test.go | 47 ++-- internal/featuretests/headerpolicy_test.go | 41 ++- internal/featuretests/listeners_test.go | 240 +++++++++--------- internal/featuretests/timeouts_test.go | 24 +- 25 files changed, 252 insertions(+), 247 deletions(-) rename internal/contour/{ => v2}/cluster.go (97%) rename internal/contour/{ => v2}/cluster_test.go (99%) rename internal/contour/{ => v2}/contour_test.go (98%) rename internal/contour/{ => v2}/endpointstranslator.go (98%) rename internal/contour/{ => v2}/endpointstranslator_test.go (99%) rename internal/contour/{ => v2}/listener.go (99%) rename internal/contour/{ => v2}/listener_test.go (99%) rename internal/contour/{ => v2}/route.go (99%) rename internal/contour/{ => v2}/route_test.go (99%) rename internal/contour/{ => v2}/secret.go (97%) rename internal/contour/{ => v2}/secret_test.go (99%) rename internal/contour/{ => v2}/server_test.go (95%) rename internal/contour/{ => v2}/visitor_test.go (99%) diff --git a/cmd/contour/serve.go b/cmd/contour/serve.go index a428f5f0dd5..4cb87954486 100644 --- a/cmd/contour/serve.go +++ b/cmd/contour/serve.go @@ -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" "github.com/projectcontour/contour/internal/dag" "github.com/projectcontour/contour/internal/debug" "github.com/projectcontour/contour/internal/health" @@ -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, @@ -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, } diff --git a/cmd/contour/servecontext.go b/cmd/contour/servecontext.go index e2b376439c2..b9589b4629e 100644 --- a/cmd/contour/servecontext.go +++ b/cmd/contour/servecontext.go @@ -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" @@ -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, diff --git a/cmd/contour/shutdownmanager.go b/cmd/contour/shutdownmanager.go index 6837d033bae..69519747f0e 100644 --- a/cmd/contour/shutdownmanager.go +++ b/cmd/contour/shutdownmanager.go @@ -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" ) @@ -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 { diff --git a/internal/contour/cond_test.go b/internal/contour/cond_test.go index 22a61269422..8ff9d6d74f9 100644 --- a/internal/contour/cond_test.go +++ b/internal/contour/cond_test.go @@ -13,7 +13,9 @@ package contour -import "testing" +import ( + "testing" +) func TestCondRegisterBeforeNotifyShouldNotBroadcast(t *testing.T) { var c Cond diff --git a/internal/contour/example_test.go b/internal/contour/example_test.go index 34ca20c40d9..5d0a5f94916 100644 --- a/internal/contour/example_test.go +++ b/internal/contour/example_test.go @@ -11,14 +11,12 @@ // 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() { @@ -26,7 +24,7 @@ func ExampleCond() { defer cancel() ch := make(chan int, 1) last := 0 - var c contour.Cond + var c Cond go func() { for { time.Sleep(100 * time.Millisecond) diff --git a/internal/contour/snapshot.go b/internal/contour/snapshot.go index b25bdfaee8d..b215662f6f6 100644 --- a/internal/contour/snapshot.go +++ b/internal/contour/snapshot.go @@ -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" ) diff --git a/internal/contour/cluster.go b/internal/contour/v2/cluster.go similarity index 97% rename from internal/contour/cluster.go rename to internal/contour/v2/cluster.go index 1da40e7b565..2871b9d54d5 100644 --- a/internal/contour/cluster.go +++ b/internal/contour/v2/cluster.go @@ -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" @@ -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. diff --git a/internal/contour/cluster_test.go b/internal/contour/v2/cluster_test.go similarity index 99% rename from internal/contour/cluster_test.go rename to internal/contour/v2/cluster_test.go index 2916b9bb8fe..073533f540f 100644 --- a/internal/contour/cluster_test.go +++ b/internal/contour/v2/cluster_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contour +package v2 import ( "testing" diff --git a/internal/contour/contour_test.go b/internal/contour/v2/contour_test.go similarity index 98% rename from internal/contour/contour_test.go rename to internal/contour/v2/contour_test.go index 6ba4398d420..131dc236974 100644 --- a/internal/contour/contour_test.go +++ b/internal/contour/v2/contour_test.go @@ -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" diff --git a/internal/contour/endpointstranslator.go b/internal/contour/v2/endpointstranslator.go similarity index 98% rename from internal/contour/endpointstranslator.go rename to internal/contour/v2/endpointstranslator.go index 1476dda7b42..44a69042a27 100644 --- a/internal/contour/endpointstranslator.go +++ b/internal/contour/v2/endpointstranslator.go @@ -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" @@ -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{ @@ -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 diff --git a/internal/contour/endpointstranslator_test.go b/internal/contour/v2/endpointstranslator_test.go similarity index 99% rename from internal/contour/endpointstranslator_test.go rename to internal/contour/v2/endpointstranslator_test.go index 8add26c69ab..a4fa15d31f6 100644 --- a/internal/contour/endpointstranslator_test.go +++ b/internal/contour/v2/endpointstranslator_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contour +package v2 import ( "testing" diff --git a/internal/contour/listener.go b/internal/contour/v2/listener.go similarity index 99% rename from internal/contour/listener.go rename to internal/contour/v2/listener.go index a9221d1d7c6..dedcd194fcb 100644 --- a/internal/contour/listener.go +++ b/internal/contour/v2/listener.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contour +package v2 import ( "path" @@ -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" @@ -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 diff --git a/internal/contour/listener_test.go b/internal/contour/v2/listener_test.go similarity index 99% rename from internal/contour/listener_test.go rename to internal/contour/v2/listener_test.go index e5e26fa5ef3..a2bc798226d 100644 --- a/internal/contour/listener_test.go +++ b/internal/contour/v2/listener_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contour +package v2 import ( "path" diff --git a/internal/contour/route.go b/internal/contour/v2/route.go similarity index 99% rename from internal/contour/route.go rename to internal/contour/v2/route.go index d5d91f867ff..fc35d45c6bb 100644 --- a/internal/contour/route.go +++ b/internal/contour/v2/route.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contour +package v2 import ( "path" @@ -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" @@ -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. diff --git a/internal/contour/route_test.go b/internal/contour/v2/route_test.go similarity index 99% rename from internal/contour/route_test.go rename to internal/contour/v2/route_test.go index 3a5be179c91..29b3e5140cf 100644 --- a/internal/contour/route_test.go +++ b/internal/contour/v2/route_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contour +package v2 import ( "testing" diff --git a/internal/contour/secret.go b/internal/contour/v2/secret.go similarity index 97% rename from internal/contour/secret.go rename to internal/contour/v2/secret.go index aca0257dde6..0fd57a0e4ea 100644 --- a/internal/contour/secret.go +++ b/internal/contour/v2/secret.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contour +package v2 import ( "sort" @@ -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" @@ -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. diff --git a/internal/contour/secret_test.go b/internal/contour/v2/secret_test.go similarity index 99% rename from internal/contour/secret_test.go rename to internal/contour/v2/secret_test.go index 3459d415616..505ebd78935 100644 --- a/internal/contour/secret_test.go +++ b/internal/contour/v2/secret_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contour +package v2 import ( "testing" diff --git a/internal/contour/server_test.go b/internal/contour/v2/server_test.go similarity index 95% rename from internal/contour/server_test.go rename to internal/contour/v2/server_test.go index b11c7a1d6d9..a7716e4629f 100644 --- a/internal/contour/server_test.go +++ b/internal/contour/v2/server_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contour +package v2 import ( "context" @@ -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" @@ -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) { @@ -191,7 +193,7 @@ 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{}, @@ -199,12 +201,12 @@ func TestGRPC(t *testing.T) { 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) diff --git a/internal/contour/visitor_test.go b/internal/contour/v2/visitor_test.go similarity index 99% rename from internal/contour/visitor_test.go rename to internal/contour/v2/visitor_test.go index 79e2cf31b6d..ae6490cb4d2 100644 --- a/internal/contour/visitor_test.go +++ b/internal/contour/v2/visitor_test.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package contour +package v2 import ( "testing" diff --git a/internal/featuretests/envoy.go b/internal/featuretests/envoy.go index 30347be1c88..3c3613b3505 100644 --- a/internal/featuretests/envoy.go +++ b/internal/featuretests/envoy.go @@ -30,7 +30,7 @@ import ( "github.com/envoyproxy/go-control-plane/pkg/wellknown" "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes/any" - "github.com/projectcontour/contour/internal/contour" + contourv2 "github.com/projectcontour/contour/internal/contour/v2" "github.com/projectcontour/contour/internal/dag" envoyv2 "github.com/projectcontour/contour/internal/envoy/v2" "github.com/projectcontour/contour/internal/protobuf" @@ -291,8 +291,8 @@ func filterchaintlsfallback(fallbackSecret *v1.Secret, peerValidationContext *da envoyv2.Filters( envoyv2.HTTPConnectionManagerBuilder(). DefaultFilters(). - RouteConfigName(contour.ENVOY_FALLBACK_ROUTECONFIG). - MetricsPrefix(contour.ENVOY_HTTPS_LISTENER). + RouteConfigName(contourv2.ENVOY_FALLBACK_ROUTECONFIG). + MetricsPrefix(contourv2.ENVOY_HTTPS_LISTENER). AccessLoggers(envoyv2.FileAccessLogEnvoy("/dev/stdout")). Get(), ), @@ -304,7 +304,7 @@ func httpsFilterFor(vhost string) *envoy_api_v2_listener.Filter { AddFilter(envoyv2.FilterMisdirectedRequests(vhost)). DefaultFilters(). RouteConfigName(path.Join("https", vhost)). - MetricsPrefix(contour.ENVOY_HTTPS_LISTENER). + MetricsPrefix(contourv2.ENVOY_HTTPS_LISTENER). AccessLoggers(envoyv2.FileAccessLogEnvoy("/dev/stdout")). Get() } @@ -326,7 +326,7 @@ func authzFilterFor( }, }). RouteConfigName(path.Join("https", vhost)). - MetricsPrefix(contour.ENVOY_HTTPS_LISTENER). + MetricsPrefix(contourv2.ENVOY_HTTPS_LISTENER). AccessLoggers(envoyv2.FileAccessLogEnvoy("/dev/stdout")). Get() } diff --git a/internal/featuretests/featuretests.go b/internal/featuretests/featuretests.go index 1c029d842d2..b7ef8290f59 100644 --- a/internal/featuretests/featuretests.go +++ b/internal/featuretests/featuretests.go @@ -22,13 +22,14 @@ import ( "testing" "time" - v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2" + envoy_api_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" "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes/any" projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" "github.com/projectcontour/contour/internal/contour" + contourv2 "github.com/projectcontour/contour/internal/contour/v2" "github.com/projectcontour/contour/internal/dag" "github.com/projectcontour/contour/internal/fixture" "github.com/projectcontour/contour/internal/k8s" @@ -62,20 +63,20 @@ func setup(t *testing.T, opts ...interface{}) (cache.ResourceEventHandler, *Cont log := fixture.NewTestLogger(t) log.SetLevel(logrus.DebugLevel) - et := contour.NewEndpointsTranslator(log) + et := contourv2.NewEndpointsTranslator(log) - conf := contour.ListenerConfig{} + conf := contourv2.ListenerConfig{} for _, opt := range opts { - if opt, ok := opt.(func(*contour.ListenerConfig)); ok { + if opt, ok := opt.(func(*contourv2.ListenerConfig)); ok { opt(&conf) } } resources := []contour.ResourceCache{ - contour.NewListenerCache(conf, statsAddress, statsPort), - &contour.SecretCache{}, - &contour.RouteCache{}, - &contour.ClusterCache{}, + contourv2.NewListenerCache(conf, statsAddress, statsPort), + &contourv2.SecretCache{}, + &contourv2.RouteCache{}, + &contourv2.ClusterCache{}, et, } @@ -231,7 +232,7 @@ func (r *resourceEventHandler) OnDelete(obj interface{}) { // routeResources returns the given routes as a slice of any.Any // resources, appropriately sorted. -func routeResources(t *testing.T, routes ...*v2.RouteConfiguration) []*any.Any { +func routeResources(t *testing.T, routes ...*envoy_api_v2.RouteConfiguration) []*any.Any { sort.Stable(sorter.For(routes)) return resources(t, protobuf.AsMessages(routes)...) } @@ -246,8 +247,8 @@ func resources(t *testing.T, protos ...proto.Message) []*any.Any { } type grpcStream interface { - Send(*v2.DiscoveryRequest) error - Recv() (*v2.DiscoveryResponse, error) + Send(*envoy_api_v2.DiscoveryRequest) error + Recv() (*envoy_api_v2.DiscoveryResponse, error) } type statusResult struct { @@ -340,29 +341,29 @@ func (c *Contour) Request(typeurl string, names ...string) *Response { require.NoError(c, err) st = sts case routeType: - rds := v2.NewRouteDiscoveryServiceClient(c.ClientConn) + rds := envoy_api_v2.NewRouteDiscoveryServiceClient(c.ClientConn) str, err := rds.StreamRoutes(ctx) require.NoError(c, err) st = str case clusterType: - cds := v2.NewClusterDiscoveryServiceClient(c.ClientConn) + cds := envoy_api_v2.NewClusterDiscoveryServiceClient(c.ClientConn) stc, err := cds.StreamClusters(ctx) require.NoError(c, err) st = stc case listenerType: - lds := v2.NewListenerDiscoveryServiceClient(c.ClientConn) + lds := envoy_api_v2.NewListenerDiscoveryServiceClient(c.ClientConn) stl, err := lds.StreamListeners(ctx) require.NoError(c, err) st = stl case endpointType: - eds := v2.NewEndpointDiscoveryServiceClient(c.ClientConn) + eds := envoy_api_v2.NewEndpointDiscoveryServiceClient(c.ClientConn) ste, err := eds.StreamEndpoints(ctx) require.NoError(c, err) st = ste default: c.Fatal("unknown typeURL:", typeurl) } - resp := c.sendRequest(st, &v2.DiscoveryRequest{ + resp := c.sendRequest(st, &envoy_api_v2.DiscoveryRequest{ TypeUrl: typeurl, ResourceNames: names, }) @@ -372,7 +373,7 @@ func (c *Contour) Request(typeurl string, names ...string) *Response { } } -func (c *Contour) sendRequest(stream grpcStream, req *v2.DiscoveryRequest) *v2.DiscoveryResponse { +func (c *Contour) sendRequest(stream grpcStream, req *envoy_api_v2.DiscoveryRequest) *envoy_api_v2.DiscoveryResponse { err := stream.Send(req) require.NoError(c, err) resp, err := stream.Recv() @@ -382,12 +383,12 @@ func (c *Contour) sendRequest(stream grpcStream, req *v2.DiscoveryRequest) *v2.D type Response struct { *Contour - *v2.DiscoveryResponse + *envoy_api_v2.DiscoveryResponse } // Equals tests that the response retrieved from Contour is equal to the supplied value. // TODO(youngnick) This function really should be copied to an `EqualResources` function. -func (r *Response) Equals(want *v2.DiscoveryResponse) *Contour { +func (r *Response) Equals(want *envoy_api_v2.DiscoveryResponse) *Contour { r.Helper() protobuf.RequireEqual(r.T, want.Resources, r.DiscoveryResponse.Resources) diff --git a/internal/featuretests/headercondition_test.go b/internal/featuretests/headercondition_test.go index 99f8f6d0474..2a30cbde680 100644 --- a/internal/featuretests/headercondition_test.go +++ b/internal/featuretests/headercondition_test.go @@ -16,12 +16,11 @@ package featuretests import ( "testing" - v22 "github.com/projectcontour/contour/internal/envoy/v2" - - v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2" + envoy_api_v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2" envoy_api_v2_route "github.com/envoyproxy/go-control-plane/envoy/api/v2/route" projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" "github.com/projectcontour/contour/internal/dag" + v2 "github.com/projectcontour/contour/internal/envoy/v2" "github.com/projectcontour/contour/internal/fixture" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -79,10 +78,10 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) { } rh.OnAdd(proxy1) - c.Request(routeType).Equals(&v2.DiscoveryResponse{ + c.Request(routeType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, - v22.RouteConfiguration("ingress_http", - v22.VirtualHost("hello.world", + v2.RouteConfiguration("ingress_http", + v2.VirtualHost("hello.world", &envoy_api_v2_route.Route{ Match: routePrefix("/blog", dag.HeaderMatchCondition{ Name: "x-header", @@ -142,10 +141,10 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) { rh.OnUpdate(proxy1, proxy2) - c.Request(routeType).Equals(&v2.DiscoveryResponse{ + c.Request(routeType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, - v22.RouteConfiguration("ingress_http", - v22.VirtualHost("hello.world", + v2.RouteConfiguration("ingress_http", + v2.VirtualHost("hello.world", &envoy_api_v2_route.Route{ Match: routePrefix("/blog", dag.HeaderMatchCondition{ Name: "x-header", @@ -205,10 +204,10 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) { rh.OnUpdate(proxy2, proxy3) - c.Request(routeType).Equals(&v2.DiscoveryResponse{ + c.Request(routeType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, - v22.RouteConfiguration("ingress_http", - v22.VirtualHost("hello.world", + v2.RouteConfiguration("ingress_http", + v2.VirtualHost("hello.world", &envoy_api_v2_route.Route{ Match: routePrefix("/blog", dag.HeaderMatchCondition{ Name: "x-header", @@ -268,10 +267,10 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) { rh.OnUpdate(proxy3, proxy4) - c.Request(routeType).Equals(&v2.DiscoveryResponse{ + c.Request(routeType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, - v22.RouteConfiguration("ingress_http", - v22.VirtualHost("hello.world", + v2.RouteConfiguration("ingress_http", + v2.VirtualHost("hello.world", &envoy_api_v2_route.Route{ Match: routePrefix("/blog", dag.HeaderMatchCondition{ Name: "x-header", @@ -331,10 +330,10 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) { rh.OnUpdate(proxy4, proxy5) - c.Request(routeType).Equals(&v2.DiscoveryResponse{ + c.Request(routeType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, - v22.RouteConfiguration("ingress_http", - v22.VirtualHost("hello.world", + v2.RouteConfiguration("ingress_http", + v2.VirtualHost("hello.world", &envoy_api_v2_route.Route{ Match: routePrefix("/blog", dag.HeaderMatchCondition{ Name: "x-header", @@ -392,10 +391,10 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) { rh.OnUpdate(proxy5, proxy6) - c.Request(routeType).Equals(&v2.DiscoveryResponse{ + c.Request(routeType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, - v22.RouteConfiguration("ingress_http", - v22.VirtualHost("hello.world", + v2.RouteConfiguration("ingress_http", + v2.VirtualHost("hello.world", &envoy_api_v2_route.Route{ Match: routePrefix("/", dag.HeaderMatchCondition{ Name: "x-header", @@ -451,10 +450,10 @@ func TestConditions_ContainsHeader_HTTProxy(t *testing.T) { rh.OnUpdate(proxy6, proxy7) - c.Request(routeType).Equals(&v2.DiscoveryResponse{ + c.Request(routeType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, - v22.RouteConfiguration("ingress_http", - v22.VirtualHost("hello.world", + v2.RouteConfiguration("ingress_http", + v2.VirtualHost("hello.world", &envoy_api_v2_route.Route{ Match: routePrefix("/", dag.HeaderMatchCondition{ Name: "x-header", diff --git a/internal/featuretests/headerpolicy_test.go b/internal/featuretests/headerpolicy_test.go index 68ffda21028..57d4fafe766 100644 --- a/internal/featuretests/headerpolicy_test.go +++ b/internal/featuretests/headerpolicy_test.go @@ -14,17 +14,16 @@ package featuretests import ( + "testing" + + envoy_api_v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2" envoy_api_v2_core "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" envoy_api_v2_route "github.com/envoyproxy/go-control-plane/envoy/api/v2/route" "github.com/golang/protobuf/ptypes/wrappers" - v22 "github.com/projectcontour/contour/internal/envoy/v2" + projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" + v2 "github.com/projectcontour/contour/internal/envoy/v2" "github.com/projectcontour/contour/internal/fixture" v1 "k8s.io/api/core/v1" - - "testing" - - v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2" - projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -55,10 +54,10 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) { }), ) - c.Request(routeType).Equals(&v2.DiscoveryResponse{ + c.Request(routeType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, - v22.RouteConfiguration("ingress_http", - v22.VirtualHost("hello.world", + v2.RouteConfiguration("ingress_http", + v2.VirtualHost("hello.world", &envoy_api_v2_route.Route{ Match: routePrefix("/"), Action: routeHostRewrite("default/svc1/80/da39a3ee5e", "goodbye.planet"), @@ -88,10 +87,10 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) { }), ) - c.Request(routeType).Equals(&v2.DiscoveryResponse{ + c.Request(routeType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, - v22.RouteConfiguration("ingress_http", - v22.VirtualHost("hello.world", + v2.RouteConfiguration("ingress_http", + v2.VirtualHost("hello.world", &envoy_api_v2_route.Route{ Match: routePrefix("/"), Action: routeCluster("default/svc1/80/da39a3ee5e"), @@ -129,10 +128,10 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) { }), ) - c.Request(routeType).Equals(&v2.DiscoveryResponse{ + c.Request(routeType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, - v22.RouteConfiguration("ingress_http", - v22.VirtualHost("hello.world", + v2.RouteConfiguration("ingress_http", + v2.VirtualHost("hello.world", &envoy_api_v2_route.Route{ Match: routePrefix("/"), Action: routeCluster("default/svc1/80/da39a3ee5e"), @@ -186,10 +185,10 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) { }), ) - c.Request(routeType).Equals(&v2.DiscoveryResponse{ + c.Request(routeType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: routeResources(t, - v22.RouteConfiguration("ingress_http", - v22.VirtualHost("hello.world", + v2.RouteConfiguration("ingress_http", + v2.VirtualHost("hello.world", &envoy_api_v2_route.Route{ Match: routePrefix("/"), Action: &envoy_api_v2_route.Route_Redirect{ @@ -201,8 +200,8 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) { }, }), ), - v22.RouteConfiguration("https/hello.world", - v22.VirtualHost("hello.world", + v2.RouteConfiguration("https/hello.world", + v2.VirtualHost("hello.world", &envoy_api_v2_route.Route{ Match: routePrefix("/"), Action: routeHostRewrite("default/externalname/443/da39a3ee5e", "goodbye.planet"), @@ -212,7 +211,7 @@ func TestHeaderPolicy_ReplaceHeader_HTTProxy(t *testing.T) { TypeUrl: routeType, }) - c.Request(clusterType).Equals(&v2.DiscoveryResponse{ + c.Request(clusterType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, tlsCluster(externalNameCluster("default/externalname/443/da39a3ee5e", "default/externalname/https", "default_externalname_443", "goodbye.planet", 443), nil, "goodbye.planet", "goodbye.planet"), ), diff --git a/internal/featuretests/listeners_test.go b/internal/featuretests/listeners_test.go index e75c7884cd1..31a2096eb42 100644 --- a/internal/featuretests/listeners_test.go +++ b/internal/featuretests/listeners_test.go @@ -20,9 +20,9 @@ import ( envoy_api_v2_auth "github.com/envoyproxy/go-control-plane/envoy/api/v2/auth" envoy_api_v2_listener "github.com/envoyproxy/go-control-plane/envoy/api/v2/listener" projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" - "github.com/projectcontour/contour/internal/contour" + contourv2 "github.com/projectcontour/contour/internal/contour/v2" "github.com/projectcontour/contour/internal/dag" - v2 "github.com/projectcontour/contour/internal/envoy/v2" + envoyv2 "github.com/projectcontour/contour/internal/envoy/v2" "github.com/projectcontour/contour/internal/fixture" v1 "k8s.io/api/core/v1" "k8s.io/api/networking/v1beta1" @@ -68,9 +68,9 @@ func TestNonTLSListener(t *testing.T) { Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - FilterChains: v2.FilterChains(v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0)), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + FilterChains: envoyv2.FilterChains(envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0)), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, staticListener(), ), @@ -127,9 +127,9 @@ func TestNonTLSListener(t *testing.T) { Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - FilterChains: v2.FilterChains(v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0)), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + FilterChains: envoyv2.FilterChains(envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0)), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, staticListener(), ), @@ -198,22 +198,22 @@ func TestTLSListener(t *testing.T) { Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - FilterChains: v2.FilterChains(v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0)), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + FilterChains: envoyv2.FilterChains(envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0)), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, &envoy_api_v2.Listener{ Name: "ingress_https", - Address: v2.SocketAddress("0.0.0.0", 8443), - ListenerFilters: v2.ListenerFilters( - v2.TLSInspector(), + Address: envoyv2.SocketAddress("0.0.0.0", 8443), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.TLSInspector(), ), FilterChains: []*envoy_api_v2_listener.FilterChain{ filterchaintls("kuard.example.com", s1, httpsFilterFor("kuard.example.com"), nil, "h2", "http/1.1"), }, - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, staticListener(), ), @@ -256,16 +256,16 @@ func TestTLSListener(t *testing.T) { Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_https", - Address: v2.SocketAddress("0.0.0.0", 8443), - ListenerFilters: v2.ListenerFilters( - v2.TLSInspector(), + Address: envoyv2.SocketAddress("0.0.0.0", 8443), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.TLSInspector(), ), FilterChains: []*envoy_api_v2_listener.FilterChain{ filterchaintls("kuard.example.com", s1, httpsFilterFor("kuard.example.com"), nil, "h2", "http/1.1"), }, - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, staticListener(), ), @@ -364,16 +364,16 @@ func TestHTTPProxyTLSListener(t *testing.T) { l1 := &envoy_api_v2.Listener{ Name: "ingress_https", - Address: v2.SocketAddress("0.0.0.0", 8443), - ListenerFilters: v2.ListenerFilters( - v2.TLSInspector(), + Address: envoyv2.SocketAddress("0.0.0.0", 8443), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.TLSInspector(), ), FilterChains: []*envoy_api_v2_listener.FilterChain{ filterchaintls("kuard.example.com", secret1, httpsFilterFor("kuard.example.com"), nil, "h2", "http/1.1"), }, - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), } // add service @@ -386,11 +386,11 @@ func TestHTTPProxyTLSListener(t *testing.T) { Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - FilterChains: v2.FilterChains( - v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + FilterChains: envoyv2.FilterChains( + envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0), ), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, l1, staticListener(), @@ -413,22 +413,22 @@ func TestHTTPProxyTLSListener(t *testing.T) { rh.OnAdd(secret1) l2 := &envoy_api_v2.Listener{ Name: "ingress_https", - Address: v2.SocketAddress("0.0.0.0", 8443), - ListenerFilters: v2.ListenerFilters( - v2.TLSInspector(), + Address: envoyv2.SocketAddress("0.0.0.0", 8443), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.TLSInspector(), ), FilterChains: []*envoy_api_v2_listener.FilterChain{ - v2.FilterChainTLS( + envoyv2.FilterChainTLS( "kuard.example.com", - v2.DownstreamTLSContext( + envoyv2.DownstreamTLSContext( &dag.Secret{Object: secret1}, envoy_api_v2_auth.TlsParameters_TLSv1_3, nil, "h2", "http/1.1"), - v2.Filters(httpsFilterFor("kuard.example.com")), + envoyv2.Filters(httpsFilterFor("kuard.example.com")), ), }, - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), } // add ingress and assert the existence of ingress_http and ingres_https @@ -437,11 +437,11 @@ func TestHTTPProxyTLSListener(t *testing.T) { Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - FilterChains: v2.FilterChains( - v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + FilterChains: envoyv2.FilterChains( + envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0), ), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, l2, staticListener(), @@ -503,16 +503,16 @@ func TestLDSFilter(t *testing.T) { Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_https", - Address: v2.SocketAddress("0.0.0.0", 8443), - ListenerFilters: v2.ListenerFilters( - v2.TLSInspector(), + Address: envoyv2.SocketAddress("0.0.0.0", 8443), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.TLSInspector(), ), FilterChains: []*envoy_api_v2_listener.FilterChain{ filterchaintls("kuard.example.com", s1, httpsFilterFor("kuard.example.com"), nil, "h2", "http/1.1"), }, - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, ), TypeUrl: listenerType, @@ -523,11 +523,11 @@ func TestLDSFilter(t *testing.T) { Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - FilterChains: v2.FilterChains( - v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + FilterChains: envoyv2.FilterChains( + envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0), ), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, ), TypeUrl: listenerType, @@ -552,7 +552,7 @@ func TestLDSStreamEmpty(t *testing.T) { } func TestLDSIngressHTTPUseProxyProtocol(t *testing.T) { - rh, c, done := setup(t, func(conf *contour.ListenerConfig) { + rh, c, done := setup(t, func(conf *contourv2.ListenerConfig) { conf.UseProxyProto = true }) defer done() @@ -593,12 +593,12 @@ func TestLDSIngressHTTPUseProxyProtocol(t *testing.T) { Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - ListenerFilters: v2.ListenerFilters( - v2.ProxyProtocol(), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.ProxyProtocol(), ), - FilterChains: v2.FilterChains(v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0)), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + FilterChains: envoyv2.FilterChains(envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0)), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, staticListener(), ), @@ -608,7 +608,7 @@ func TestLDSIngressHTTPUseProxyProtocol(t *testing.T) { } func TestLDSIngressHTTPSUseProxyProtocol(t *testing.T) { - rh, c, done := setup(t, func(conf *contour.ListenerConfig) { + rh, c, done := setup(t, func(conf *contourv2.ListenerConfig) { conf.UseProxyProto = true }) defer done() @@ -670,28 +670,28 @@ func TestLDSIngressHTTPSUseProxyProtocol(t *testing.T) { ingress_https := &envoy_api_v2.Listener{ Name: "ingress_https", - Address: v2.SocketAddress("0.0.0.0", 8443), - ListenerFilters: v2.ListenerFilters( - v2.ProxyProtocol(), - v2.TLSInspector(), + Address: envoyv2.SocketAddress("0.0.0.0", 8443), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.ProxyProtocol(), + envoyv2.TLSInspector(), ), FilterChains: []*envoy_api_v2_listener.FilterChain{ filterchaintls("kuard.example.com", s1, httpsFilterFor("kuard.example.com"), nil, "h2", "http/1.1"), }, - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), } c.Request(listenerType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - ListenerFilters: v2.ListenerFilters( - v2.ProxyProtocol(), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.ProxyProtocol(), ), - FilterChains: v2.FilterChains(v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0)), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + FilterChains: envoyv2.FilterChains(envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0)), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, ingress_https, staticListener(), @@ -701,7 +701,7 @@ func TestLDSIngressHTTPSUseProxyProtocol(t *testing.T) { } func TestLDSCustomAddressAndPort(t *testing.T) { - rh, c, done := setup(t, func(conf *contour.ListenerConfig) { + rh, c, done := setup(t, func(conf *contourv2.ListenerConfig) { conf.HTTPAddress = "127.0.0.100" conf.HTTPPort = 9100 conf.HTTPSAddress = "127.0.0.200" @@ -768,24 +768,24 @@ func TestLDSCustomAddressAndPort(t *testing.T) { ingress_http := &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("127.0.0.100", 9100), - FilterChains: v2.FilterChains( - v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0), + Address: envoyv2.SocketAddress("127.0.0.100", 9100), + FilterChains: envoyv2.FilterChains( + envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0), ), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), } ingress_https := &envoy_api_v2.Listener{ Name: "ingress_https", - Address: v2.SocketAddress("127.0.0.200", 9200), - ListenerFilters: v2.ListenerFilters( - v2.TLSInspector(), + Address: envoyv2.SocketAddress("127.0.0.200", 9200), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.TLSInspector(), ), FilterChains: []*envoy_api_v2_listener.FilterChain{ filterchaintls("kuard.example.com", s1, httpsFilterFor("kuard.example.com"), nil, "h2", "http/1.1"), }, - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), } c.Request(listenerType).Equals(&envoy_api_v2.DiscoveryResponse{ Resources: resources(t, @@ -798,7 +798,7 @@ func TestLDSCustomAddressAndPort(t *testing.T) { } func TestLDSCustomAccessLogPaths(t *testing.T) { - rh, c, done := setup(t, func(conf *contour.ListenerConfig) { + rh, c, done := setup(t, func(conf *contourv2.ListenerConfig) { conf.HTTPAccessLog = "/tmp/http_access.log" conf.HTTPSAccessLog = "/tmp/https_access.log" }) @@ -861,30 +861,30 @@ func TestLDSCustomAccessLogPaths(t *testing.T) { ingress_http := &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - FilterChains: v2.FilterChains( - v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/tmp/http_access.log"), 0), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + FilterChains: envoyv2.FilterChains( + envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/tmp/http_access.log"), 0), ), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), } ingress_https := &envoy_api_v2.Listener{ Name: "ingress_https", - Address: v2.SocketAddress("0.0.0.0", 8443), - ListenerFilters: v2.ListenerFilters( - v2.TLSInspector(), + Address: envoyv2.SocketAddress("0.0.0.0", 8443), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.TLSInspector(), ), FilterChains: []*envoy_api_v2_listener.FilterChain{ filterchaintls("kuard.example.com", s1, - v2.HTTPConnectionManagerBuilder(). - AddFilter(v2.FilterMisdirectedRequests("kuard.example.com")). + envoyv2.HTTPConnectionManagerBuilder(). + AddFilter(envoyv2.FilterMisdirectedRequests("kuard.example.com")). DefaultFilters(). RouteConfigName("https/kuard.example.com"). - MetricsPrefix(contour.ENVOY_HTTPS_LISTENER). - AccessLoggers(v2.FileAccessLogEnvoy("/tmp/https_access.log")). + MetricsPrefix(contourv2.ENVOY_HTTPS_LISTENER). + AccessLoggers(envoyv2.FileAccessLogEnvoy("/tmp/https_access.log")). Get(), nil, "h2", "http/1.1"), }, - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), } c.Request(listenerType).Equals(&envoy_api_v2.DiscoveryResponse{ VersionInfo: "1", @@ -961,25 +961,25 @@ func TestHTTPProxyHTTPS(t *testing.T) { ingressHTTP := &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - FilterChains: v2.FilterChains( - v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + FilterChains: envoyv2.FilterChains( + envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0), ), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), } ingressHTTPS := &envoy_api_v2.Listener{ Name: "ingress_https", - Address: v2.SocketAddress("0.0.0.0", 8443), - ListenerFilters: v2.ListenerFilters( - v2.TLSInspector(), + Address: envoyv2.SocketAddress("0.0.0.0", 8443), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.TLSInspector(), ), FilterChains: []*envoy_api_v2_listener.FilterChain{ filterchaintls("example.com", s1, httpsFilterFor("example.com"), nil, "h2", "http/1.1"), }, - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), } c.Request(listenerType).Equals(&envoy_api_v2.DiscoveryResponse{ VersionInfo: "1", @@ -994,7 +994,7 @@ func TestHTTPProxyHTTPS(t *testing.T) { } func TestHTTPProxyMinimumTLSVersion(t *testing.T) { - rh, c, done := setup(t, func(conf *contour.ListenerConfig) { + rh, c, done := setup(t, func(conf *contourv2.ListenerConfig) { conf.MinimumTLSVersion = envoy_api_v2_auth.TlsParameters_TLSv1_2 }) @@ -1043,22 +1043,22 @@ func TestHTTPProxyMinimumTLSVersion(t *testing.T) { l1 := &envoy_api_v2.Listener{ Name: "ingress_https", - Address: v2.SocketAddress("0.0.0.0", 8443), - ListenerFilters: v2.ListenerFilters( - v2.TLSInspector(), + Address: envoyv2.SocketAddress("0.0.0.0", 8443), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.TLSInspector(), ), FilterChains: []*envoy_api_v2_listener.FilterChain{ - v2.FilterChainTLS( + envoyv2.FilterChainTLS( "kuard.example.com", - v2.DownstreamTLSContext( + envoyv2.DownstreamTLSContext( &dag.Secret{Object: secret1}, envoy_api_v2_auth.TlsParameters_TLSv1_2, nil, "h2", "http/1.1"), - v2.Filters(httpsFilterFor("kuard.example.com")), + envoyv2.Filters(httpsFilterFor("kuard.example.com")), ), }, - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), } // verify that p1's TLS 1.1 minimum has been upgraded to 1.2 @@ -1066,11 +1066,11 @@ func TestHTTPProxyMinimumTLSVersion(t *testing.T) { Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - FilterChains: v2.FilterChains( - v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + FilterChains: envoyv2.FilterChains( + envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0), ), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, l1, staticListener(), @@ -1108,22 +1108,22 @@ func TestHTTPProxyMinimumTLSVersion(t *testing.T) { l2 := &envoy_api_v2.Listener{ Name: "ingress_https", - Address: v2.SocketAddress("0.0.0.0", 8443), - ListenerFilters: v2.ListenerFilters( - v2.TLSInspector(), + Address: envoyv2.SocketAddress("0.0.0.0", 8443), + ListenerFilters: envoyv2.ListenerFilters( + envoyv2.TLSInspector(), ), FilterChains: []*envoy_api_v2_listener.FilterChain{ - v2.FilterChainTLS( + envoyv2.FilterChainTLS( "kuard.example.com", - v2.DownstreamTLSContext( + envoyv2.DownstreamTLSContext( &dag.Secret{Object: secret1}, envoy_api_v2_auth.TlsParameters_TLSv1_3, nil, "h2", "http/1.1"), - v2.Filters(httpsFilterFor("kuard.example.com")), + envoyv2.Filters(httpsFilterFor("kuard.example.com")), ), }, - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), } // verify that p2's TLS 1.3 minimum has NOT been downgraded to 1.2 @@ -1131,11 +1131,11 @@ func TestHTTPProxyMinimumTLSVersion(t *testing.T) { Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - FilterChains: v2.FilterChains( - v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + FilterChains: envoyv2.FilterChains( + envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0), ), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, l2, staticListener(), @@ -1199,11 +1199,11 @@ func TestLDSHTTPProxyRootCannotDelegateToAnotherRoot(t *testing.T) { Resources: resources(t, &envoy_api_v2.Listener{ Name: "ingress_http", - Address: v2.SocketAddress("0.0.0.0", 8080), - FilterChains: v2.FilterChains( - v2.HTTPConnectionManager("ingress_http", v2.FileAccessLogEnvoy("/dev/stdout"), 0), + Address: envoyv2.SocketAddress("0.0.0.0", 8080), + FilterChains: envoyv2.FilterChains( + envoyv2.HTTPConnectionManager("ingress_http", envoyv2.FileAccessLogEnvoy("/dev/stdout"), 0), ), - SocketOptions: v2.TCPKeepaliveSocketOptions(), + SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), }, staticListener(), ), diff --git a/internal/featuretests/timeouts_test.go b/internal/featuretests/timeouts_test.go index 87db6848f92..0184ab6391a 100644 --- a/internal/featuretests/timeouts_test.go +++ b/internal/featuretests/timeouts_test.go @@ -19,7 +19,7 @@ import ( envoy_api_v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2" projcontour "github.com/projectcontour/contour/apis/projectcontour/v1" - "github.com/projectcontour/contour/internal/contour" + contourv2 "github.com/projectcontour/contour/internal/contour/v2" envoyv2 "github.com/projectcontour/contour/internal/envoy/v2" "github.com/projectcontour/contour/internal/fixture" "github.com/projectcontour/contour/internal/timeout" @@ -56,17 +56,17 @@ func TestTimeoutsNotSpecified(t *testing.T) { } rh.OnAdd(hp1) - c.Request(listenerType, contour.ENVOY_HTTP_LISTENER).Equals(&envoy_api_v2.DiscoveryResponse{ + c.Request(listenerType, contourv2.ENVOY_HTTP_LISTENER).Equals(&envoy_api_v2.DiscoveryResponse{ TypeUrl: listenerType, Resources: resources(t, &envoy_api_v2.Listener{ - Name: contour.ENVOY_HTTP_LISTENER, + Name: contourv2.ENVOY_HTTP_LISTENER, Address: envoyv2.SocketAddress("0.0.0.0", 8080), SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), FilterChains: envoyv2.FilterChains(envoyv2.HTTPConnectionManagerBuilder(). - RouteConfigName(contour.ENVOY_HTTP_LISTENER). - MetricsPrefix(contour.ENVOY_HTTP_LISTENER). - AccessLoggers(envoyv2.FileAccessLogEnvoy(contour.DEFAULT_HTTP_ACCESS_LOG)). + RouteConfigName(contourv2.ENVOY_HTTP_LISTENER). + MetricsPrefix(contourv2.ENVOY_HTTP_LISTENER). + AccessLoggers(envoyv2.FileAccessLogEnvoy(contourv2.DEFAULT_HTTP_ACCESS_LOG)). DefaultFilters(). Get(), ), @@ -75,7 +75,7 @@ func TestTimeoutsNotSpecified(t *testing.T) { } func TestNonZeroTimeoutsSpecified(t *testing.T) { - withTimeouts := func(conf *contour.ListenerConfig) { + withTimeouts := func(conf *contourv2.ListenerConfig) { conf.ConnectionIdleTimeout = timeout.DurationSetting(7 * time.Second) conf.StreamIdleTimeout = timeout.DurationSetting(70 * time.Second) conf.MaxConnectionDuration = timeout.DurationSetting(700 * time.Second) @@ -109,17 +109,17 @@ func TestNonZeroTimeoutsSpecified(t *testing.T) { } rh.OnAdd(hp1) - c.Request(listenerType, contour.ENVOY_HTTP_LISTENER).Equals(&envoy_api_v2.DiscoveryResponse{ + c.Request(listenerType, contourv2.ENVOY_HTTP_LISTENER).Equals(&envoy_api_v2.DiscoveryResponse{ TypeUrl: listenerType, Resources: resources(t, &envoy_api_v2.Listener{ - Name: contour.ENVOY_HTTP_LISTENER, + Name: contourv2.ENVOY_HTTP_LISTENER, Address: envoyv2.SocketAddress("0.0.0.0", 8080), SocketOptions: envoyv2.TCPKeepaliveSocketOptions(), FilterChains: envoyv2.FilterChains(envoyv2.HTTPConnectionManagerBuilder(). - RouteConfigName(contour.ENVOY_HTTP_LISTENER). - MetricsPrefix(contour.ENVOY_HTTP_LISTENER). - AccessLoggers(envoyv2.FileAccessLogEnvoy(contour.DEFAULT_HTTP_ACCESS_LOG)). + RouteConfigName(contourv2.ENVOY_HTTP_LISTENER). + MetricsPrefix(contourv2.ENVOY_HTTP_LISTENER). + AccessLoggers(envoyv2.FileAccessLogEnvoy(contourv2.DEFAULT_HTTP_ACCESS_LOG)). DefaultFilters(). ConnectionIdleTimeout(timeout.DurationSetting(7 * time.Second)). StreamIdleTimeout(timeout.DurationSetting(70 * time.Second)).