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

chore: set default filter orders #5095

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion api/v1alpha1/envoyproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ type FilterPosition struct {
}

// EnvoyFilter defines the type of Envoy HTTP filter.
// +kubebuilder:validation:Enum=envoy.filters.http.health_check;envoy.filters.http.fault;envoy.filters.http.cors;envoy.filters.http.ext_authz;envoy.filters.http.basic_auth;envoy.filters.http.oauth2;envoy.filters.http.jwt_authn;envoy.filters.http.stateful_session;envoy.filters.http.ext_proc;envoy.filters.http.wasm;envoy.filters.http.rbac;envoy.filters.http.local_ratelimit;envoy.filters.http.ratelimit;envoy.filters.http.custom_response
// +kubebuilder:validation:Enum=envoy.filters.http.health_check;envoy.filters.http.fault;envoy.filters.http.cors;envoy.filters.http.ext_authz;envoy.filters.http.api_key_auth;envoy.filters.http.basic_auth;envoy.filters.http.oauth2;envoy.filters.http.jwt_authn;envoy.filters.http.stateful_session;envoy.filters.http.ext_proc;envoy.filters.http.wasm;envoy.filters.http.rbac;envoy.filters.http.local_ratelimit;envoy.filters.http.ratelimit;envoy.filters.http.custom_response;envoy.filters.http.compressor
type EnvoyFilter string

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ spec:
- envoy.filters.http.fault
- envoy.filters.http.cors
- envoy.filters.http.ext_authz
- envoy.filters.http.api_key_auth
- envoy.filters.http.basic_auth
- envoy.filters.http.oauth2
- envoy.filters.http.jwt_authn
Expand All @@ -338,6 +339,7 @@ spec:
- envoy.filters.http.local_ratelimit
- envoy.filters.http.ratelimit
- envoy.filters.http.custom_response
- envoy.filters.http.compressor
type: string
before:
description: |-
Expand All @@ -348,6 +350,7 @@ spec:
- envoy.filters.http.fault
- envoy.filters.http.cors
- envoy.filters.http.ext_authz
- envoy.filters.http.api_key_auth
- envoy.filters.http.basic_auth
- envoy.filters.http.oauth2
- envoy.filters.http.jwt_authn
Expand All @@ -358,6 +361,7 @@ spec:
- envoy.filters.http.local_ratelimit
- envoy.filters.http.ratelimit
- envoy.filters.http.custom_response
- envoy.filters.http.compressor
type: string
name:
description: Name of the filter.
Expand All @@ -366,6 +370,7 @@ spec:
- envoy.filters.http.fault
- envoy.filters.http.cors
- envoy.filters.http.ext_authz
- envoy.filters.http.api_key_auth
- envoy.filters.http.basic_auth
- envoy.filters.http.oauth2
- envoy.filters.http.jwt_authn
Expand All @@ -376,6 +381,7 @@ spec:
- envoy.filters.http.local_ratelimit
- envoy.filters.http.ratelimit
- envoy.filters.http.custom_response
- envoy.filters.http.compressor
type: string
required:
- name
Expand Down
12 changes: 7 additions & 5 deletions internal/xds/translator/httpfilters.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

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"
"k8s.io/utils/ptr"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
Expand Down Expand Up @@ -80,7 +79,7 @@ type OrderedHTTPFilters []*OrderedHTTPFilter
// For example, the health_check filter should be placed in the first position because external load
// balancer determines whether envoy should receive traffic based on the health check result which
// only depending on the current draining state of the envoy, result should not be affected by other
// filters, or else user traffic discruption may happen.
// filters, or else user traffic disruption may happen.
// the fault filter should be placed in the second position because
// it doesn't rely on the functionality of other filters, and rejecting early can save computation costs
// for the remaining filters, the cors filter should be put at the third to avoid unnecessary
Expand All @@ -98,7 +97,6 @@ func newOrderedHTTPFilter(filter *hcmv3.HttpFilter) *OrderedHTTPFilter {
// When the fault filter is configured to be at the first, the computation of
// the remaining filters is skipped when rejected early
// Important: After adding new filter types, don't forget to modify the validation rule of the EnvoyFilter type in the API
// TODO (zhaohuabing): remove duplicate filter type constants and replace them with the type constants in the api package
switch {
case isFilterType(filter, egv1a1.EnvoyFilterHealthCheck):
order = 0
Expand Down Expand Up @@ -128,8 +126,12 @@ func newOrderedHTTPFilter(filter *hcmv3.HttpFilter) *OrderedHTTPFilter {
order = 202
case isFilterType(filter, egv1a1.EnvoyFilterRateLimit):
order = 203
case isFilterType(filter, wellknown.Router):
case isFilterType(filter, egv1a1.EnvoyFilterCustomResponse):
order = 204
case isFilterType(filter, egv1a1.EnvoyFilterCompressor):
order = 205
case isFilterType(filter, egv1a1.EnvoyFilterRouter):
order = 206
}

return &OrderedHTTPFilter{
Expand Down Expand Up @@ -267,7 +269,7 @@ func (t *Translator) patchHCMWithFilters(
// Add the router filter if it doesn't exist.
hasRouter := false
for _, filter := range mgr.HttpFilters {
if filter.Name == wellknown.Router {
if filter.Name == string(egv1a1.EnvoyFilterRouter) {
hasRouter = true
break
}
Expand Down
Loading