Skip to content

Commit

Permalink
api: lua support in EnvoyExtensionPolicy and HTTPRouteFilter
Browse files Browse the repository at this point in the history
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
  • Loading branch information
rudrakhp committed Dec 15, 2024
1 parent 469de2f commit 70d648a
Show file tree
Hide file tree
Showing 11 changed files with 560 additions and 4 deletions.
10 changes: 9 additions & 1 deletion api/v1alpha1/envoyextensionypolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ type EnvoyExtensionPolicySpec struct {
Wasm []Wasm `json:"wasm,omitempty"`

// ExtProc is an ordered list of external processing filters
// that should added to the envoy filter chain
// that should be added to the envoy filter chain
//
// +kubebuilder:validation:MaxItems=16
// +optional
ExtProc []ExtProc `json:"extProc,omitempty"`

// LuaFilters is an ordered list of Lua filters
// that should be added to the envoy filter chain
//
// +kubebuilder:validation:MaxItems=16
// +optional
// +notImplementedHide
LuaFilters []LuaFilter `json:"lua,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/httproutefilter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type HTTPRouteFilterSpec struct {
URLRewrite *HTTPURLRewriteFilter `json:"urlRewrite,omitempty"`
// +optional
DirectResponse *HTTPDirectResponseFilter `json:"directResponse,omitempty"`
// +kubebuilder:validation:MaxItems=16
// +optional
// +notImplementedHide
LuaFilters []LuaPerRouteFilter `json:"lua,omitempty"`
}

// HTTPURLRewriteFilter define rewrites of HTTP URL components such as path and host
Expand Down
67 changes: 67 additions & 0 deletions api/v1alpha1/lua_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package v1alpha1

// LuaFilter defines a Lua extension that applies globally
// to all requests passing through the filter chain.
type LuaFilter struct {
// SourceCodes is a map of named LuaSource codes that can be referenced in LuaPerRouteFilter
//
// +kubebuilder:validation:MaxProperties=16
// +optional
SourceCodes map[string]*LuaSource `json:"sourceCodes"`
// DefaultSourceCode is the default LuaSource that will be executed
// unless overridden by LuaPerRouteFilter configured for the selected route
DefaultSourceCode *LuaSource `json:"defaultSourceCode"`
// StatPrefix is the additional prefix to use when emitting statistics.
// By default, metrics are emitted in .lua. namespace.
// If multiple lua filters are configured in a filter chain, the stats from each filter instance can be emitted
// using custom stat prefix to distinguish emitted statistics.
//
// +optional
StatPrefix *string `json:"statPrefix,omitempty"`
}

// LuaPerRouteFilter defines a Lua extension that applies to specific routes based on route match.
// Only one of Disabled, Name or OverrideSource must be set.
// +kubebuilder:validation:XValidation:rule="has(self.disabled) ? (!has(self.name) && !has(self.overrideSource)) : (has(self.name) ? !has(self.overrideSource) : has(self.overrideSource))",message="Exactly one of disabled, name, or overrideSource must be set."
type LuaPerRouteFilter struct {
// Disabled is the status of the Lua filter for this particular vhost or route.
// If disabled is specified in multiple per-filter-configs, the most specific one will be used.
//
// +optional
Disabled *bool `json:"disabled,omitempty"`
// Name of a LuaSource code stored in LuaFilter.SourceCodes
//
// +optional
Name *string `json:"name,omitempty"`
// OverrideSource is a LuaSource defined for this specific route
//
// +optional
OverrideSource *LuaSource `json:"overrideSource,omitempty"`
}

// LuaSource contains source code information for a user defined Lua script
// Only one of FileName, InlineBytes, InlineString or EnvironmentVariable must be set
// +kubebuilder:validation:XValidation:rule="has(self.fileName) ? (!has(self.inlineBytes) && !has(self.inlineString) && !has(self.environmentVariable)) : (has(self.inlineBytes) ? (!has(self.inlineString) && !has(self.environmentVariable)) : has(self.inlineString) ? !has(self.environmentVariable) : has(self.environmentVariable))",message="Exactly one of fileName, inlineBytes, inlineString, or environmentVariable must be set."
type LuaSource struct {
// FileName represents a local filesystem data source.
//
// +optional
FileName *string `json:"fileName,omitempty"`
// InlineBytes represents bytes inlined in the configuration.
//
// +optional
InlineBytes []byte `json:"inlineBytes,omitempty"`
// InlineString represents a string inlined in the configuration.
//
// +optional
InlineString *string `json:"inlineString,omitempty"`
// EnvironmentVariable represents an environment variable data source.
//
// +optional
EnvironmentVariable *string `json:"environmentVariable,omitempty"`
}
120 changes: 120 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ spec:
extProc:
description: |-
ExtProc is an ordered list of external processing filters
that should added to the envoy filter chain
that should be added to the envoy filter chain
items:
description: ExtProc defines the configuration for External Processing
filter.
Expand Down Expand Up @@ -973,6 +973,94 @@ spec:
== "" || f.group == ''gateway.envoyproxy.io'')) : true'
maxItems: 16
type: array
lua:
description: |-
LuaFilters is an ordered list of Lua filters
that should be added to the envoy filter chain
items:
description: |-
LuaFilter defines a Lua extension that applies globally
to all requests passing through the filter chain.
properties:
defaultSourceCode:
description: |-
DefaultSourceCode is the default LuaSource that will be executed
unless overridden by LuaPerRouteFilter configured for the selected route
properties:
environmentVariable:
description: EnvironmentVariable represents an environment
variable data source.
type: string
fileName:
description: FileName represents a local filesystem data
source.
type: string
inlineBytes:
description: InlineBytes represents bytes inlined in the
configuration.
format: byte
type: string
inlineString:
description: InlineString represents a string inlined in
the configuration.
type: string
type: object
x-kubernetes-validations:
- message: Exactly one of fileName, inlineBytes, inlineString,
or environmentVariable must be set.
rule: 'has(self.fileName) ? (!has(self.inlineBytes) && !has(self.inlineString)
&& !has(self.environmentVariable)) : (has(self.inlineBytes)
? (!has(self.inlineString) && !has(self.environmentVariable))
: has(self.inlineString) ? !has(self.environmentVariable)
: has(self.environmentVariable))'
sourceCodes:
additionalProperties:
description: |-
LuaSource contains source code information for a user defined Lua script
Only one of FileName, InlineBytes, InlineString or EnvironmentVariable must be set
properties:
environmentVariable:
description: EnvironmentVariable represents an environment
variable data source.
type: string
fileName:
description: FileName represents a local filesystem data
source.
type: string
inlineBytes:
description: InlineBytes represents bytes inlined in the
configuration.
format: byte
type: string
inlineString:
description: InlineString represents a string inlined
in the configuration.
type: string
type: object
x-kubernetes-validations:
- message: Exactly one of fileName, inlineBytes, inlineString,
or environmentVariable must be set.
rule: 'has(self.fileName) ? (!has(self.inlineBytes) && !has(self.inlineString)
&& !has(self.environmentVariable)) : (has(self.inlineBytes)
? (!has(self.inlineString) && !has(self.environmentVariable))
: has(self.inlineString) ? !has(self.environmentVariable)
: has(self.environmentVariable))'
description: SourceCodes is a map of named LuaSource codes that
can be referenced in LuaPerRouteFilter
maxProperties: 16
type: object
statPrefix:
description: |-
StatPrefix is the additional prefix to use when emitting statistics.
By default, metrics are emitted in .lua. namespace.
If multiple lua filters are configured in a filter chain, the stats from each filter instance can be emitted
using custom stat prefix to distinguish emitted statistics.
type: string
required:
- defaultSourceCode
type: object
maxItems: 16
type: array
targetRef:
description: |-
TargetRef is the name of the resource this policy is being attached to.
Expand Down
Loading

0 comments on commit 70d648a

Please sign in to comment.