Skip to content

Commit

Permalink
refactor route filter config
Browse files Browse the repository at this point in the history
Signed-off-by: huabing zhao <[email protected]>
  • Loading branch information
zhaohuabing committed Oct 20, 2023
1 parent 7e09ffc commit 80fb42b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
28 changes: 27 additions & 1 deletion internal/xds/translator/httpfilters.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package translator
import (
"sort"

routev3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
hcmv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
"github.com/envoyproxy/go-control-plane/pkg/wellknown"

Expand Down Expand Up @@ -75,7 +76,9 @@ func sortHTTPFilters(filters []*hcmv3.HttpFilter) []*hcmv3.HttpFilter {

// patchHCMWithFilters builds and appends HTTP Filters to the HTTP connection
// manager.
func (t *Translator) patchHCMWithFilters(mgr *hcmv3.HttpConnectionManager, irListener *ir.HTTPListener) error {
func (t *Translator) patchHCMWithFilters(
mgr *hcmv3.HttpConnectionManager,
irListener *ir.HTTPListener) error {
// The order of filter patching is not relevant here.
// All the filters will be sorted in correct order after the patching is done.
// TODO: Make this a generic interface for all API Gateway features.
Expand All @@ -99,3 +102,26 @@ func (t *Translator) patchHCMWithFilters(mgr *hcmv3.HttpConnectionManager, irLis
mgr.HttpFilters = sortHTTPFilters(mgr.HttpFilters)
return nil
}

// patchRouteWithFilters appends per-route filter configurations to the route.
func patchRouteWithFilters(
route *routev3.Route,
irRoute *ir.HTTPRoute) error {
// TODO: Convert this into a generic interface for API Gateway features.
// https://github.com/envoyproxy/gateway/issues/882
if err :=
patchRouteWithRateLimit(route.GetRoute(), irRoute); err != nil {
return nil
}

Check warning on line 115 in internal/xds/translator/httpfilters.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/httpfilters.go#L114-L115

Added lines #L114 - L115 were not covered by tests

// Add the jwt per route config to the route, if needed.
if err := patchRouteWithJwtConfig(route, irRoute); err != nil {
return nil
}

Check warning on line 120 in internal/xds/translator/httpfilters.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/httpfilters.go#L119-L120

Added lines #L119 - L120 were not covered by tests

// Add the cors per route config to the route, if needed.
if err := patchRouteWithCorsConfig(route, irRoute); err != nil {
return err
}

Check warning on line 125 in internal/xds/translator/httpfilters.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/httpfilters.go#L124-L125

Added lines #L124 - L125 were not covered by tests
return nil
}
15 changes: 2 additions & 13 deletions internal/xds/translator/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,8 @@ func buildXdsRoute(httpRoute *ir.HTTPRoute) *routev3.Route {
router.GetRoute().Timeout = durationpb.New(httpRoute.Timeout.Duration)
}

// TODO: Convert this into a generic interface for API Gateway features.
// https://github.com/envoyproxy/gateway/issues/882
if err := patchRouteWithRateLimit(router.GetRoute(), httpRoute); err != nil {
return nil
}

// Add the jwt per route config to the route, if needed.
if err := patchRouteWithJwtConfig(router, httpRoute); err != nil {
return nil
}

// Add the cors per route config to the route, if needed.
if err := patchRouteWithCorsConfig(router, httpRoute); err != nil {
// Add per route filter configs to the route, if needed.
if err := patchRouteWithFilters(router, httpRoute); err != nil {
return nil
}

Expand Down

0 comments on commit 80fb42b

Please sign in to comment.