Skip to content

feat(api): Add filterContext field to Lua type in EnvoyExtensionPolicy#8730

Open
norman-zon wants to merge 3 commits intoenvoyproxy:mainfrom
norman-zon:8765-envoyextensionpolicy-filtercontext
Open

feat(api): Add filterContext field to Lua type in EnvoyExtensionPolicy#8730
norman-zon wants to merge 3 commits intoenvoyproxy:mainfrom
norman-zon:8765-envoyextensionpolicy-filtercontext

Conversation

@norman-zon
Copy link
Copy Markdown

What type of PR is this?

feat/api

What this PR does / why we need it:

Adds an optional filterContext field (map[string]string) to the Lua type in EnvoyExtensionPolicySpec, exposing Envoy's existing LuaPerRoute.filter_context field.

This allows a shared Lua script (stored in a ConfigMap via ValueRef) to be parameterized differently per route using request_handle:filterContext(). Without this, users must either duplicate the entire script inline with hardcoded values for each route or use EnvoyPatchPolicy to manually patch the generated xDS — both of which are fragile and defeat the purpose of script reuse.

Example usage:

lua:
  - type: ValueRef
    valueRef:
      name: shared-auth-lua
      kind: ConfigMap
    filterContext:
      token_header: x-api-key

The Lua script accesses the values via:

local ctx = request_handle:filterContext()
local header_name = ctx["token_header"]

Changes:

  • api/v1alpha1/lua_types.go — add FilterContext map[string]string to Lua struct
  • internal/ir/xds.go — add FilterContext to IR Lua struct
  • internal/gatewayapi/envoyextensionpolicy.go — pass FilterContext from API → IR
  • internal/xds/translator/lua.go — set FilterContext on LuaPerRoute, converting map[string]stringstructpb.Struct
  • GatewayAPI and xDS translator testdata updated
  • E2E test added: Lua script reads filterContext() and sets value as response header
  • Documentation updated with FilterContext section in Lua task guide
  • Release note added

No new Envoy features required — this only exposes an existing LuaPerRoute field.

Which issue(s) this PR fixes:

Fixes #8715

Release Notes: Yes

@norman-zon norman-zon requested a review from a team as a code owner April 13, 2026 08:59
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 13, 2026

Deploy Preview for cerulean-figolla-1f9435 ready!

Name Link
🔨 Latest commit 070ba24
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/69df89d25009d600081a2bf6
😎 Deploy Preview https://deploy-preview-8730--cerulean-figolla-1f9435.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.28%. Comparing base (faf7a99) to head (070ba24).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8730      +/-   ##
==========================================
- Coverage   74.32%   74.28%   -0.04%     
==========================================
  Files         245      245              
  Lines       38801    38807       +6     
==========================================
- Hits        28837    28829       -8     
- Misses       7962     7973      +11     
- Partials     2002     2005       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zirain
Copy link
Copy Markdown
Member

zirain commented Apr 14, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

…#8715)

Add an optional `filterContext` field (map[string]string) to the Lua type
in EnvoyExtensionPolicySpec. This exposes Envoy's existing
LuaPerRoute.filter_context so that a shared Lua script can be
parameterized differently per route via request_handle:filterContext().

Without this, users must either duplicate the entire script inline with
hardcoded values or resort to EnvoyPatchPolicy to manually patch xDS.

Changes:
- api: add FilterContext to Lua struct
- ir: add FilterContext to IR Lua struct
- gatewayapi: pass FilterContext from API to IR in buildLua()
- xds: set FilterContext on LuaPerRoute in patchRoute(), converting
  map[string]string to structpb.Struct
- tests: update gatewayapi/xds translator testdata, add e2e test
- docs: add FilterContext section to Lua extension task guide

Signed-off-by: Norman Stetter <85173861+norman-zon@users.noreply.github.com>
Signed-off-by: Norman Stetter <85173861+norman-zon@users.noreply.github.com>
@norman-zon norman-zon force-pushed the 8765-envoyextensionpolicy-filtercontext branch from a55e539 to 4bc5e02 Compare April 15, 2026 12:50
Signed-off-by: Norman Stetter <85173861+norman-zon@users.noreply.github.com>
@norman-zon norman-zon force-pushed the 8765-envoyextensionpolicy-filtercontext branch from 4bc5e02 to 070ba24 Compare April 15, 2026 12:51
@zirain
Copy link
Copy Markdown
Member

zirain commented Apr 16, 2026

FAIL: TestE2E/LuaHTTP/http_route_with_lua_filter_context (60.01s) e2e failed.

Copy link
Copy Markdown
Member

@rudrakhp rudrakhp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to add mocks for the filterContext() api in the validator mocks which is failing your E2E. Please refer how other APIs are mocked for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add filterContext field to Lua type in EnvoyExtensionPolicy

3 participants