Skip to content

Commit

Permalink
add processing mode
Browse files Browse the repository at this point in the history
Signed-off-by: Guy Daich <guy.daich@sap.com>
  • Loading branch information
guydc committed Apr 10, 2024
1 parent cc91a51 commit 844558b
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 3 deletions.
41 changes: 40 additions & 1 deletion api/v1alpha1/ext_proc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,52 @@ import (
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// +kubebuilder:validation:Enum=Streamed;Buffered;BufferedPartial
type ExtProcBodyProcessingMode string

const (
StreamedExtProcBodyProcessingMode ExtProcBodyProcessingMode = "Streamed"
BufferedExtProcBodyProcessingMode ExtProcBodyProcessingMode = "Buffered"
BufferedPartialExtBodyHeaderProcessingMode ExtProcBodyProcessingMode = "BufferedPartial"
)

// ProcessingModeOptions defines if headers or body should be processed by the external service
type ProcessingModeOptions struct {
// Defines body processing mode
//
// +optional
Body *ExtProcBodyProcessingMode `json:"body,omitempty"`
}

// ExtProcProcessingMode defines if and how headers and bodies are sent to the service.
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/http/ext_proc/v3/processing_mode.proto#envoy-v3-api-msg-extensions-filters-http-ext-proc-v3-processingmode
type ExtProcProcessingMode struct {
// Defines processing mode for requests. If present, request headers are sent. Request body is processed according
// to the specified mode.
//
// +optional
Request *ProcessingModeOptions `json:"request,omitempty"`

// Defines processing mode for responses. If present, response headers are sent. Response body is processed according
// to the specified mode.
//
// +optional
Response *ProcessingModeOptions `json:"response,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="has(self.backendRef) ? (!has(self.backendRef.group) || self.backendRef.group == \"\") : true", message="group is invalid, only the core API group (specified by omitting the group field or setting it to an empty string) is supported"
// +kubebuilder:validation:XValidation:rule="has(self.backendRef) ? (!has(self.backendRef.kind) || self.backendRef.kind == 'Service') : true", message="kind is invalid, only Service (specified by omitting the kind field or setting it to 'Service') is supported"
//
// ExtProc defines the configuration for External Processing filter.
type ExtProc struct {
// Service defines the configuration of the external processing service
// BackendRef defines the configuration of the external processing service
BackendRef ExtProcBackendRef `json:"backendRef"`

// ProcessingMode defines how request and response body is processed
// Default: header and body are not sent to the external processor
//
// +optional
ProcessingMode *ExtProcProcessingMode `json:"processingMode,omitempty"`
}

// ExtProcService defines the gRPC External Processing service using the envoy grpc client
Expand Down
50 changes: 50 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 @@ -58,7 +58,7 @@ spec:
filter.
properties:
backendRef:
description: Service defines the configuration of the external
description: BackendRef defines the configuration of the external
processing service
properties:
group:
Expand Down Expand Up @@ -134,6 +134,38 @@ spec:
- message: Must have port for Service reference
rule: '(size(self.group) == 0 && self.kind == ''Service'')
? has(self.port) : true'
processingMode:
description: |-
ProcessingMode defines how request and response body is processed
Default: header and body are not sent to the external processor
properties:
request:
description: |-
Defines processing mode for requests. If present, request headers are sent. Request body is processed according
to the specified mode.
properties:
body:
description: Defines body processing mode
enum:
- Streamed
- Buffered
- BufferedPartial
type: string
type: object
response:
description: |-
Defines processing mode for responses. If present, response headers are sent. Response body is processed according
to the specified mode.
properties:
body:
description: Defines body processing mode
enum:
- Streamed
- Buffered
- BufferedPartial
type: string
type: object
type: object
required:
- backendRef
type: object
Expand Down
44 changes: 43 additions & 1 deletion site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,8 @@ _Appears in:_

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `backendRef` | _[ExtProcBackendRef](#extprocbackendref)_ | true | Service defines the configuration of the external processing service |
| `backendRef` | _[ExtProcBackendRef](#extprocbackendref)_ | true | BackendRef defines the configuration of the external processing service |
| `processingMode` | _[ExtProcProcessingMode](#extprocprocessingmode)_ | false | ProcessingMode defines how request and response body is processed<br />Default: header and body are not sent to the external processor |


#### ExtProcBackendRef
Expand All @@ -1041,6 +1042,33 @@ _Appears in:_
| `port` | _[PortNumber](#portnumber)_ | false | Port specifies the destination port number to use for this resource.<br />Port is required when the referent is a Kubernetes Service. In this<br />case, the port number is the service port number, not the target port.<br />For other resources, destination port might be derived from the referent<br />resource or this field. |


#### ExtProcBodyProcessingMode

_Underlying type:_ _string_



_Appears in:_
- [ProcessingModeOptions](#processingmodeoptions)



#### ExtProcProcessingMode



ExtProcProcessingMode defines if and how headers and bodies are sent to the service.
https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/http/ext_proc/v3/processing_mode.proto#envoy-v3-api-msg-extensions-filters-http-ext-proc-v3-processingmode

_Appears in:_
- [ExtProc](#extproc)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `request` | _[ProcessingModeOptions](#processingmodeoptions)_ | false | Defines processing mode for requests. If present, request headers are sent. Request body is processed according<br />to the specified mode. |
| `response` | _[ProcessingModeOptions](#processingmodeoptions)_ | false | Defines processing mode for responses. If present, response headers are sent. Response body is processed according<br />to the specified mode. |


#### ExtensionAPISettings


Expand Down Expand Up @@ -1944,6 +1972,20 @@ _Appears in:_
| `backOff` | _[BackOffPolicy](#backoffpolicy)_ | false | Backoff is the backoff policy to be applied per retry attempt. gateway uses a fully jittered exponential<br />back-off algorithm for retries. For additional details,<br />see https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter#config-http-filters-router-x-envoy-max-retries |


#### ProcessingModeOptions



ProcessingModeOptions defines if headers or body should be processed by the external service

_Appears in:_
- [ExtProcProcessingMode](#extprocprocessingmode)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `body` | _[ExtProcBodyProcessingMode](#extprocbodyprocessingmode)_ | false | Defines body processing mode |


#### ProviderType

_Underlying type:_ _string_
Expand Down
38 changes: 38 additions & 0 deletions test/cel-validation/envoyextensionpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ package celvalidation
import (
"context"
"fmt"
"k8s.io/utils/ptr"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -151,6 +153,42 @@ func TestEnvoyExtensionPolicyTarget(t *testing.T) {
"spec.targetRef: Invalid value: \"object\": this policy does not yet support the sectionName field",
},
},
{
desc: "ExtProc with invalid fields",
mutate: func(sp *egv1a1.EnvoyExtensionPolicy) {
sp.Spec = egv1a1.EnvoyExtensionPolicySpec{
ExtProc: []egv1a1.ExtProc{
{
BackendRef: egv1a1.ExtProcBackendRef{
BackendObjectReference: gwapiv1.BackendObjectReference{
Name: "grpc-proc-service",
Port: ptr.To(gwapiv1.PortNumber(80)),
},
},
ProcessingMode: &egv1a1.ExtProcProcessingMode{
Request: &egv1a1.ProcessingModeOptions{
Body: ptr.To(egv1a1.ExtProcBodyProcessingMode("not-a-body-mode")),
},
Response: &egv1a1.ProcessingModeOptions{
Body: ptr.To(egv1a1.ExtProcBodyProcessingMode("not-a-body-mode")),
},
},
},
},
TargetRef: gwapiv1a2.PolicyTargetReferenceWithSectionName{
PolicyTargetReference: gwapiv1a2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Kind: "Gateway",
Name: "eg",
},
},
}
},
wantErrors: []string{
"spec.extProc[0].processingMode.response.body: Unsupported value: \"not-a-body-mode\": supported values: \"Streamed\", \"Buffered\", \"BufferedPartial\"",
"spec.extProc[0].processingMode.request.body: Unsupported value: \"not-a-body-mode\": supported values: \"Streamed\", \"Buffered\", \"BufferedPartial\"",
},
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 844558b

Please sign in to comment.