Skip to content

Commit

Permalink
internal/envoy: moved to typed configs for httpfilters
Browse files Browse the repository at this point in the history
Using some HTTP filter names from the go-control-plane wellknown package give warnings
due to being deprecated from Envoy.

This updates the names to use TypedConfigs which are matched differently in Envoy
and won't have the same issues with deprecation.

Fixes projectcontour#2479

Signed-off-by: Steve Sloka <[email protected]>
  • Loading branch information
stevesloka committed Nov 16, 2020
1 parent 4f893a6 commit 3409330
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 36 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/ahmetb/gen-crd-api-reference-docs v0.1.5
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect
github.com/client9/misspell v0.3.4
github.com/client9/misspell v0.3.4 // indirect
github.com/envoyproxy/go-control-plane v0.9.7
github.com/go-logr/logr v0.2.1 // indirect
github.com/golang/protobuf v1.4.2
Expand Down
55 changes: 48 additions & 7 deletions internal/envoy/v3/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ import (
accesslog "github.com/envoyproxy/go-control-plane/envoy/config/accesslog/v3"
envoy_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_listener_v3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
envoy_compressor_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/compressor/v3"
envoy_config_filter_http_ext_authz_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ext_authz/v3"
lua "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/lua/v3"
http "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
tcp "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/tcp_proxy/v3"
envoy_tls_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
envoy_type "github.com/envoyproxy/go-control-plane/envoy/type/v3"
"github.com/envoyproxy/go-control-plane/pkg/wellknown"
"github.com/golang/protobuf/ptypes/any"
"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/envoy"
"github.com/projectcontour/contour/internal/protobuf"
Expand All @@ -44,6 +46,11 @@ const (
HTTPVersion1 HTTPVersionType = http.HttpConnectionManager_HTTP1
HTTPVersion2 HTTPVersionType = http.HttpConnectionManager_HTTP2
HTTPVersion3 HTTPVersionType = http.HttpConnectionManager_HTTP3

HTTPFilterRouter = "type.googleapis.com/envoy.extensions.filters.http.router.v3.Router"
HTTPFilterCORS = "type.googleapis.com/envoy.extensions.filters.http.cors.v3.Cors"
HTTPFilterGrpcWeb = "type.googleapis.com/envoy.extensions.filters.http.grpc_web.v3.GrpcWeb"
HTTPFilterGzip = "type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip"
)

// ProtoNamesForVersions returns the slice of ALPN protocol names for the give HTTP versions.
Expand Down Expand Up @@ -202,18 +209,47 @@ func (b *httpConnectionManagerBuilder) ConnectionShutdownGracePeriod(timeout tim
}

func (b *httpConnectionManagerBuilder) DefaultFilters() *httpConnectionManagerBuilder {

// Add a default set of ordered http filters.
// The names are not required to match anything and are
// identified by the TypeURL of each filter.
b.filters = append(b.filters,
&http.HttpFilter{
Name: wellknown.Gzip,
Name: "compressor",
ConfigType: &http.HttpFilter_TypedConfig{
TypedConfig: protobuf.MustMarshalAny(&envoy_compressor_v3.Compressor{
CompressorLibrary: &envoy_core_v3.TypedExtensionConfig{
Name: "gzip",
TypedConfig: &any.Any{
TypeUrl: HTTPFilterGzip,
},
},
}),
},
},
&http.HttpFilter{
Name: wellknown.GRPCWeb,
Name: "grpcweb",
ConfigType: &http.HttpFilter_TypedConfig{
TypedConfig: &any.Any{
TypeUrl: HTTPFilterGrpcWeb,
},
},
},
&http.HttpFilter{
Name: wellknown.CORS,
Name: "cors",
ConfigType: &http.HttpFilter_TypedConfig{
TypedConfig: &any.Any{
TypeUrl: HTTPFilterCORS,
},
},
},
&http.HttpFilter{
Name: wellknown.Router,
Name: "router",
ConfigType: &http.HttpFilter_TypedConfig{
TypedConfig: &any.Any{
TypeUrl: HTTPFilterRouter,
},
},
},
)

Expand Down Expand Up @@ -247,12 +283,17 @@ func (b *httpConnectionManagerBuilder) Validate() error {
filterNames := map[string]struct{}{}

for _, f := range b.filters {
filterNames[f.Name] = struct{}{}
// Extract the TypeURL to compare against to identify
// the http filter.
switch config := f.ConfigType.(type) {
case *http.HttpFilter_TypedConfig:
filterNames[config.TypedConfig.TypeUrl] = struct{}{}
}
}

// If there's no router filter, requests won't be forwarded.
if _, ok := filterNames[wellknown.Router]; !ok {
return fmt.Errorf("missing required filter %q", wellknown.Router)
if _, ok := filterNames[HTTPFilterRouter]; !ok {
return fmt.Errorf("missing required filter %q", HTTPFilterRouter)
}

return nil
Expand Down
Loading

0 comments on commit 3409330

Please sign in to comment.