Skip to content

Commit f96d5f9

Browse files
add tests for agentgateway extproc
Signed-off-by: Sibasish Behera <[email protected]>
1 parent dc6c874 commit f96d5f9

File tree

16 files changed

+545
-37
lines changed

16 files changed

+545
-37
lines changed

api/v1alpha1/ext_proc_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,32 @@ type ExtProcProvider struct {
1717
FailOpen bool `json:"failOpen,omitempty"`
1818

1919
// ProcessingMode defines how the filter should interact with the request/response streams.
20+
// Envoy: Supported
21+
// Agentgateway: Not Supported (ignored)
2022
// +optional
2123
ProcessingMode *ProcessingMode `json:"processingMode,omitempty"`
2224

2325
// MessageTimeout is the timeout for each message sent to the external processing server.
26+
// Envoy: Supported
27+
// Agentgateway: Not Supported (ignored)
2428
// +optional
2529
// +kubebuilder:validation:XValidation:rule="matches(self, '^([0-9]{1,5}(h|m|s|ms)){1,4}$')",message="invalid timeout value"
2630
// +kubebuilder:validation:XValidation:rule="duration(self) >= duration('1ms')",message="timeout must be at least 1ms."
2731
MessageTimeout *metav1.Duration `json:"messageTimeout,omitempty"`
2832

2933
// MaxMessageTimeout specifies the upper bound of override_message_timeout that may be sent from the external processing server.
3034
// The default value 0, which effectively disables the override_message_timeout API.
35+
// Envoy: Supported
36+
// Agentgateway: Not Supported (ignored)
3137
// +optional
3238
// +kubebuilder:validation:XValidation:rule="matches(self, '^([0-9]{1,5}(h|m|s|ms)){1,4}$')",message="invalid timeout value"
3339
// +kubebuilder:validation:XValidation:rule="duration(self) >= duration('1ms')",message="timeout must be at least 1ms."
3440
MaxMessageTimeout *metav1.Duration `json:"maxMessageTimeout,omitempty"`
3541

3642
// StatPrefix is an optional prefix to include when emitting stats from the extproc filter,
3743
// enabling different instances of the filter to have unique stats.
44+
// Envoy: Supported
45+
// Agentgateway: Not Supported (ignored)
3846
// +optional
3947
// +kubebuilder:validation:MinLength=1
4048
StatPrefix *string `json:"statPrefix,omitempty"`
@@ -43,13 +51,17 @@ type ExtProcProvider struct {
4351
// external processor response is received in response to request headers.
4452
// The default behavior is "FromResponse" which will only clear the route cache when
4553
// an external processing response has the clear_route_cache field set.
54+
// Envoy: Supported
55+
// Agentgateway: Not Supported (ignored)
4656
// +optional
4757
// +kubebuilder:validation:Enum=FromResponse;Clear;Retain
4858
// +kubebuilder:default=FromResponse
4959
RouteCacheAction ExtProcRouteCacheAction `json:"routeCacheAction,omitempty"`
5060

5161
// MetadataOptions allows configuring metadata namespaces to forwarded or received from the external
5262
// processing server.
63+
// Envoy: Supported
64+
// Agentgateway: Not Supported (ignored)
5365
// +optional
5466
MetadataOptions *MetadataOptions `json:"metadataOptions,omitempty"`
5567
}
@@ -77,11 +89,15 @@ type ExtProcPolicy struct {
7789
ExtensionRef *NamespacedObjectReference `json:"extensionRef,omitempty"`
7890

7991
// ProcessingMode defines how the filter should interact with the request/response streams
92+
// Envoy: Supported
93+
// Agentgateway: Not Supported (ignored)
8094
// +optional
8195
ProcessingMode *ProcessingMode `json:"processingMode,omitempty"`
8296

8397
// Disable all external processing filters.
8498
// Can be used to disable external processing policies applied at a higher level in the config hierarchy.
99+
// Envoy: Supported
100+
// Agentgateway: Not Supported (ignored)
85101
// +optional
86102
Disable *PolicyDisable `json:"disable,omitempty"`
87103
}

go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,12 @@ require (
646646
)
647647

648648
// Remove once https://github.com/kubernetes-sigs/controller-tools/pull/1224 merges
649-
replace sigs.k8s.io/controller-tools => github.com/shashankram/controller-tools v0.0.0-20250626172831-f7be064a9132
649+
replace (
650+
// TODO: remove local replace path on merge of PR https://github.com/agentgateway/agentgateway/pull/535
651+
// and new release based on that
652+
github.com/agentgateway/agentgateway => /home/void/programming/agentgateway
653+
sigs.k8s.io/controller-tools => github.com/shashankram/controller-tools v0.0.0-20250626172831-f7be064a9132
654+
)
650655

651656
tool (
652657
github.com/golang/mock/mockgen

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ github.com/a8m/envsubst v1.4.3 h1:kDF7paGK8QACWYaQo6KtyYBozY2jhQrTuNNuUxQkhJY=
208208
github.com/a8m/envsubst v1.4.3/go.mod h1:4jjHWQlZoaXPoLQUb7H2qT4iLkZDdmEQiOUogdUmqVU=
209209
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
210210
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
211-
github.com/agentgateway/agentgateway v0.10.3 h1:z5HcuNuiz+NTZR87sU91xsjxvBD9bRP2xOhJwGbgW8Y=
212-
github.com/agentgateway/agentgateway v0.10.3/go.mod h1:geHd31xH5d8OrCRuRyvnDxBeqSZ9+O9VhL8VJAfcA+E=
213211
github.com/agnivade/levenshtein v1.2.1 h1:EHBY3UOn1gwdy/VbFwgo4cxecRznFk7fKWN1KOX7eoM=
214212
github.com/agnivade/levenshtein v1.2.1/go.mod h1:QVVI16kDrtSuwcpd0p1+xMC6Z/VfhtCyDIjcwga4/DU=
215213
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=

install/helm/kgateway-crds/templates/gateway.kgateway.dev_gatewayextensions.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,19 @@ spec:
439439
description: |-
440440
MaxMessageTimeout specifies the upper bound of override_message_timeout that may be sent from the external processing server.
441441
The default value 0, which effectively disables the override_message_timeout API.
442+
Envoy: Supported
443+
Agentgateway: Not Supported (ignored)
442444
type: string
443445
x-kubernetes-validations:
444446
- message: invalid timeout value
445447
rule: matches(self, '^([0-9]{1,5}(h|m|s|ms)){1,4}$')
446448
- message: timeout must be at least 1ms.
447449
rule: duration(self) >= duration('1ms')
448450
messageTimeout:
449-
description: MessageTimeout is the timeout for each message sent
450-
to the external processing server.
451+
description: |-
452+
MessageTimeout is the timeout for each message sent to the external processing server.
453+
Envoy: Supported
454+
Agentgateway: Not Supported (ignored)
451455
type: string
452456
x-kubernetes-validations:
453457
- message: invalid timeout value
@@ -458,6 +462,8 @@ spec:
458462
description: |-
459463
MetadataOptions allows configuring metadata namespaces to forwarded or received from the external
460464
processing server.
465+
Envoy: Supported
466+
Agentgateway: Not Supported (ignored)
461467
properties:
462468
forwarding:
463469
description: Forwarding defines the typed or untyped dynamic
@@ -477,8 +483,10 @@ spec:
477483
type: object
478484
type: object
479485
processingMode:
480-
description: ProcessingMode defines how the filter should interact
481-
with the request/response streams.
486+
description: |-
487+
ProcessingMode defines how the filter should interact with the request/response streams.
488+
Envoy: Supported
489+
Agentgateway: Not Supported (ignored)
482490
properties:
483491
requestBodyMode:
484492
default: NONE
@@ -546,6 +554,8 @@ spec:
546554
external processor response is received in response to request headers.
547555
The default behavior is "FromResponse" which will only clear the route cache when
548556
an external processing response has the clear_route_cache field set.
557+
Envoy: Supported
558+
Agentgateway: Not Supported (ignored)
549559
enum:
550560
- FromResponse
551561
- Clear
@@ -555,6 +565,8 @@ spec:
555565
description: |-
556566
StatPrefix is an optional prefix to include when emitting stats from the extproc filter,
557567
enabling different instances of the filter to have unique stats.
568+
Envoy: Supported
569+
Agentgateway: Not Supported (ignored)
558570
minLength: 1
559571
type: string
560572
required:

install/helm/kgateway-crds/templates/gateway.kgateway.dev_trafficpolicies.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,8 @@ spec:
10421042
description: |-
10431043
Disable all external processing filters.
10441044
Can be used to disable external processing policies applied at a higher level in the config hierarchy.
1045+
Envoy: Supported
1046+
Agentgateway: Not Supported (ignored)
10451047
type: object
10461048
extensionRef:
10471049
description: ExtensionRef references the GatewayExtension that
@@ -1064,8 +1066,10 @@ spec:
10641066
- name
10651067
type: object
10661068
processingMode:
1067-
description: ProcessingMode defines how the filter should interact
1068-
with the request/response streams
1069+
description: |-
1070+
ProcessingMode defines how the filter should interact with the request/response streams
1071+
Envoy: Supported
1072+
Agentgateway: Not Supported (ignored)
10691073
properties:
10701074
requestBodyMode:
10711075
default: NONE

internal/kgateway/query/mocks/mock_queries.go

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

pkg/agentgateway/plugins/traffic_plugin.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -833,17 +833,16 @@ func processRateLimitPolicy(ctx krt.HandlerContext, gatewayExtensions krt.Collec
833833
}
834834

835835
func processExtProcPolicy(ctx krt.HandlerContext, gatewayExtensions krt.Collection[*v1alpha1.GatewayExtension], trafficPolicy *v1alpha1.TrafficPolicy, policyName string, policyTarget *api.PolicyTarget) ([]AgwPolicy, error) {
836-
if trafficPolicy.Spec.ExtProc.ExtensionRef == nil {
837-
logger.Debug("skipping extproc policy with no extensionRef (likely disable policy)",
838-
"policy", trafficPolicy.Name)
839-
return nil, nil
840-
}
841-
836+
// TODO: warn if unsupported policy parameters are used?
842837
gwExt, err := lookupGatewayExtension(ctx, gatewayExtensions, *trafficPolicy.Spec.ExtProc.ExtensionRef, trafficPolicy.Namespace, v1alpha1.GatewayExtensionTypeExtProc)
843838
if err != nil {
844839
return nil, err
845840
}
841+
846842
extProc := (*gwExt).Spec.ExtProc
843+
if extProc == nil {
844+
return nil, fmt.Errorf("extproc provider is missing from gateway extension %s/%s", gwExt.Namespace, gwExt.Namespace)
845+
}
847846

848847
var extProcSvcTarget *api.BackendReference
849848
if extProc.GrpcService != nil && extProc.GrpcService.BackendRef != nil {
@@ -867,33 +866,34 @@ func processExtProcPolicy(ctx krt.HandlerContext, gatewayExtensions krt.Collecti
867866
}
868867

869868
if extProcSvcTarget == nil {
870-
return nil, fmt.Errorf("extproc policy %s/%s missing grpcService.backendRef in GatewayExtension <place_holder>",
871-
trafficPolicy.Namespace, trafficPolicy.Name)
869+
return nil, fmt.Errorf("extproc policy %s/%s missing backendRef in gateway extension %s/%s",
870+
trafficPolicy.Namespace, trafficPolicy.Name, (*gwExt).Namespace, (*gwExt).Name)
872871
}
873872

874-
extProcPolicySpec := &api.PolicySpec_ExtProc{
875-
Target: extProcSvcTarget,
876-
FailureModeAllow: extProc.FailOpen,
873+
failureMode := api.PolicySpec_ExtProc_FAIL_CLOSED
874+
if extProc.FailOpen {
875+
failureMode = api.PolicySpec_ExtProc_FAIL_OPEN
877876
}
878877

879878
extProcPolicy := &api.Policy{
880879
Name: policyName + extprocPolicySuffix + attachmentName(policyTarget),
881880
Target: policyTarget,
882881
Spec: &api.PolicySpec{
883882
Kind: &api.PolicySpec_ExtProc_{
884-
ExtProc: extProcPolicySpec,
883+
ExtProc: &api.PolicySpec_ExtProc{
884+
Target: extProcSvcTarget,
885+
FailureMode: failureMode,
886+
},
885887
},
886888
},
887889
}
890+
888891
logger.Debug("generated ExtProc policy",
889892
"policy", trafficPolicy.Name,
890893
"agentgateway_policy", extProcPolicy.Name,
891894
"target", extProcSvcTarget)
892-
return []AgwPolicy{
893-
{
894-
Policy: extProcPolicy,
895-
},
896-
}, nil
895+
896+
return []AgwPolicy{{Policy: extProcPolicy}}, nil
897897
}
898898

899899
// processLocalRateLimitPolicy processes local rate limiting configuration

pkg/generated/openapi/zz_generated.openapi.go

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

0 commit comments

Comments
 (0)