Skip to content

Commit c01f433

Browse files
committed
fix(api): use apiextensionsv1.JSON for Lua filterContext
Address review feedback on #8730: - Change FilterContext field type from map[string]string to *apiextensionsv1.JSON in both the API (lua_types.go) and IR (xds.go), matching the existing pattern used by Wasm.Config and DynamicModule.Config. - Drop json/yaml struct tags from ir.Lua.FilterContext, consistent with the other untagged fields on that struct. - Update the xDS translator to unmarshal FilterContext.Raw into structpb.Struct via protojson.Unmarshal, replacing the previous string-only map iteration. - Regenerate deepcopy, CRD manifests, and test fixtures. Users can now pass non-string JSON values (numbers, bools, nested objects) in filterContext without stringifying them. Signed-off-by: Norman Stetter <85173861+norman-zon@users.noreply.github.com>
1 parent ff6126e commit c01f433

16 files changed

Lines changed: 61 additions & 56 deletions

api/v1alpha1/lua_types.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
package v1alpha1
77

8-
import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
8+
import (
9+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
10+
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
11+
)
912

1013
// LuaValueType defines the types of values for Lua supported by Envoy Gateway.
1114
// +kubebuilder:validation:Enum=Inline;ValueRef
@@ -45,10 +48,11 @@ type Lua struct {
4548
// +optional
4649
// +unionMember
4750
ValueRef *gwapiv1.LocalObjectReference `json:"valueRef,omitempty"`
48-
// FilterContext is a set of key/value pairs that are made available to the Lua script
49-
// via request_handle:filterContext(). This allows a shared script to be
50-
// parameterized differently per EnvoyExtensionPolicy/route.
51+
// FilterContext is the filter context configuration for the Lua script.
52+
// This must be a JSON object (key/value pairs). The values are made available
53+
// to the Lua script via request_handle:filterContext(). This allows a shared
54+
// script to be parameterized differently per EnvoyExtensionPolicy/route.
5155
//
5256
// +optional
53-
FilterContext map[string]string `json:"filterContext,omitempty"`
57+
FilterContext *apiextensionsv1.JSON `json:"filterContext,omitempty"`
5458
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_envoyextensionpolicies.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,13 +1601,12 @@ spec:
16011601
Only one of Inline or ValueRef must be set
16021602
properties:
16031603
filterContext:
1604-
additionalProperties:
1605-
type: string
16061604
description: |-
1607-
FilterContext is a set of key/value pairs that are made available to the Lua script
1608-
via request_handle:filterContext(). This allows a shared script to be
1609-
parameterized differently per EnvoyExtensionPolicy/route.
1610-
type: object
1605+
FilterContext is the filter context configuration for the Lua script.
1606+
This must be a JSON object (key/value pairs). The values are made available
1607+
to the Lua script via request_handle:filterContext(). This allows a shared
1608+
script to be parameterized differently per EnvoyExtensionPolicy/route.
1609+
x-kubernetes-preserve-unknown-fields: true
16111610
inline:
16121611
description: Inline contains the source code as an inline string.
16131612
type: string

charts/gateway-helm/charts/crds/crds/generated/gateway.envoyproxy.io_envoyextensionpolicies.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,13 +1600,12 @@ spec:
16001600
Only one of Inline or ValueRef must be set
16011601
properties:
16021602
filterContext:
1603-
additionalProperties:
1604-
type: string
16051603
description: |-
1606-
FilterContext is a set of key/value pairs that are made available to the Lua script
1607-
via request_handle:filterContext(). This allows a shared script to be
1608-
parameterized differently per EnvoyExtensionPolicy/route.
1609-
type: object
1604+
FilterContext is the filter context configuration for the Lua script.
1605+
This must be a JSON object (key/value pairs). The values are made available
1606+
to the Lua script via request_handle:filterContext(). This allows a shared
1607+
script to be parameterized differently per EnvoyExtensionPolicy/route.
1608+
x-kubernetes-preserve-unknown-fields: true
16101609
inline:
16111610
description: Inline contains the source code as an inline string.
16121611
type: string

internal/gatewayapi/testdata/envoyextensionpolicy-with-invalid-lua-validation-disabled.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ xdsIR:
215215
print("Value is greater than 5")
216216
end
217217
end
218+
FilterContext: null
218219
Name: envoyextensionpolicy/default/policy-for-http-route/lua/0
219220
hostname: www.example.com
220221
isHTTP2: false

internal/gatewayapi/testdata/envoyextensionpolicy-with-invalid-lua-validation-syntax.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ xdsIR:
317317
end
318318
return envoy.lua.ResponseStatus.Continue
319319
end
320+
FilterContext: null
320321
Name: envoyextensionpolicy/default/policy-for-http-route/lua/0
321322
hostname: www.example.com
322323
isHTTP2: false

internal/gatewayapi/testdata/envoyextensionpolicy-with-invalid-lua.out.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ xdsIR:
292292
luas:
293293
- Code: function envoy_on_request(request_handle) request_handle:logInfo('Goodbye.')
294294
end
295+
FilterContext: null
295296
Name: envoyextensionpolicy/envoy-gateway/policy-for-gateway/lua/0
296297
hostname: www.example.com
297298
isHTTP2: false
@@ -327,6 +328,7 @@ xdsIR:
327328
luas:
328329
- Code: function envoy_on_request(request_handle) request_handle:logInfo('Goodbye.')
329330
end
331+
FilterContext: null
330332
Name: envoyextensionpolicy/envoy-gateway/policy-for-gateway/lua/0
331333
hostname: www.example.com
332334
isHTTP2: false

internal/gatewayapi/testdata/envoyextensionpolicy-with-lua-configmap.out.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ xdsIR:
466466
function envoy_on_request(request_handle)
467467
request_handle:logInfo('Goodbye.')
468468
end
469+
FilterContext: null
469470
Name: envoyextensionpolicy/envoy-gateway/policy-for-gateway/lua/0
470471
hostname: www.example.com
471472
isHTTP2: false
@@ -505,6 +506,7 @@ xdsIR:
505506
function envoy_on_request(request_handle)
506507
request_handle:logInfo('Goodbye.')
507508
end
509+
FilterContext: null
508510
Name: envoyextensionpolicy/envoy-gateway/policy-for-gateway/lua/0
509511
hostname: www.example.com
510512
isHTTP2: false
@@ -544,6 +546,7 @@ xdsIR:
544546
function envoy_on_request(request_handle)
545547
request_handle:logInfo('Goodbye.')
546548
end
549+
FilterContext: null
547550
Name: envoyextensionpolicy/envoy-gateway/policy-for-gateway/lua/0
548551
hostname: www.example.com
549552
isHTTP2: false
@@ -581,9 +584,9 @@ xdsIR:
581584
function envoy_on_response(response_handle)
582585
response_handle:logWarn('Goodbye.')
583586
end
584-
Name: envoyextensionpolicy/default/policy-for-http-route/lua/0
585-
filterContext:
587+
FilterContext:
586588
token_header: x-session-token
589+
Name: envoyextensionpolicy/default/policy-for-http-route/lua/0
587590
hostname: www.example.com
588591
isHTTP2: false
589592
metadata:
@@ -620,6 +623,7 @@ xdsIR:
620623
function envoy_on_request(request_handle)
621624
request_handle:logInfo('Goodbye.')
622625
end
626+
FilterContext: null
623627
Name: envoyextensionpolicy/envoy-gateway/policy-for-gateway/lua/0
624628
hostname: www.example.com
625629
isHTTP2: false

internal/gatewayapi/testdata/envoyextensionpolicy-with-lua.out.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ xdsIR:
281281
luas:
282282
- Code: function envoy_on_response(response_handle) response_handle:logWarn('Goodbye.')
283283
end
284-
Name: envoyextensionpolicy/default/policy-for-http-route/lua/0
285-
filterContext:
284+
FilterContext:
286285
mode: strict
287286
token_header: x-api-key
287+
Name: envoyextensionpolicy/default/policy-for-http-route/lua/0
288288
hostname: www.example.com
289289
isHTTP2: false
290290
metadata:
@@ -319,6 +319,7 @@ xdsIR:
319319
luas:
320320
- Code: function envoy_on_request(request_handle) request_handle:logInfo('Goodbye.')
321321
end
322+
FilterContext: null
322323
Name: envoyextensionpolicy/envoy-gateway/policy-for-gateway/lua/0
323324
hostname: www.example.com
324325
isHTTP2: false

internal/ir/xds.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,9 +3685,9 @@ type Lua struct {
36853685
Name string
36863686
// Code is the Lua source code
36873687
Code *string
3688-
// FilterContext is a set of key/value pairs passed to the Lua script
3689-
// via request_handle:filterContext().
3690-
FilterContext map[string]string `json:"filterContext,omitempty" yaml:"filterContext,omitempty"`
3688+
// FilterContext is the filter context configuration for the Lua script.
3689+
// This is a JSON object passed to the Lua script via request_handle:filterContext().
3690+
FilterContext *apiextensionsv1.JSON
36913691
}
36923692

36933693
// Wasm holds the information associated with the Wasm extensions.

0 commit comments

Comments
 (0)